From cd154e05f09a5bd40e258f50a71e89d263143e35 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 18 Oct 2010 20:34:25 +0000 Subject: Revert [2710] and [2717], remove TDB and replace with QDBM again, to fix build on Windows and make it easier to merge Charles' work. --- bin/bbackupd/BackupClientInodeToIDMap.cpp | 76 +- bin/bbackupd/BackupClientInodeToIDMap.h | 5 +- bootstrap | 3 - bundled/replace/.checker_innocent | 4 - bundled/replace/.revinfo.git | 6 - bundled/replace/Makefile.in | 70 - bundled/replace/README | 123 - bundled/replace/aclocal.m4 | 1 - bundled/replace/autoconf-2.60.m4 | 236 - bundled/replace/autogen-waf.sh | 1 - bundled/replace/autogen.sh | 13 - bundled/replace/build_macros.m4 | 14 - bundled/replace/config.guess | 1561 -- bundled/replace/config.h.in | 965 - bundled/replace/config.sub | 1686 -- bundled/replace/configure | 27830 ---------------------------- bundled/replace/configure.ac | 33 - bundled/replace/crypt.c | 770 - bundled/replace/crypt.m4 | 6 - bundled/replace/dlfcn.c | 76 - bundled/replace/dlfcn.m4 | 31 - bundled/replace/getaddrinfo.c | 497 - bundled/replace/getaddrinfo.h | 91 - bundled/replace/getifaddrs.c | 352 - bundled/replace/getpass.c | 218 - bundled/replace/getpass.m4 | 24 - bundled/replace/hdr_replace.h | 2 - bundled/replace/inet_aton.c | 33 - bundled/replace/inet_ntoa.c | 39 - bundled/replace/inet_ntop.c | 191 - bundled/replace/inet_pton.c | 213 - bundled/replace/install-sh | 238 - bundled/replace/libreplace.m4 | 319 - bundled/replace/libreplace_cc.m4 | 179 - bundled/replace/libreplace_ld.m4 | 337 - bundled/replace/libreplace_macros.m4 | 332 - bundled/replace/libreplace_network.m4 | 466 - bundled/replace/repdir.m4 | 81 - bundled/replace/repdir_getdents.c | 166 - bundled/replace/repdir_getdirentries.c | 183 - bundled/replace/replace.c | 762 - bundled/replace/replace.h | 774 - bundled/replace/samba.m4 | 34 - bundled/replace/snprintf.c | 1531 -- bundled/replace/socket.c | 35 - bundled/replace/socketpair.c | 46 - bundled/replace/strptime.c | 990 - bundled/replace/strptime.m4 | 13 - bundled/replace/system/README | 4 - bundled/replace/system/aio.h | 32 - bundled/replace/system/capability.h | 55 - bundled/replace/system/config.m4 | 131 - bundled/replace/system/dir.h | 67 - bundled/replace/system/filesys.h | 188 - bundled/replace/system/glob.h | 37 - bundled/replace/system/iconv.h | 57 - bundled/replace/system/kerberos.h | 141 - bundled/replace/system/locale.h | 42 - bundled/replace/system/network.h | 379 - bundled/replace/system/passwd.h | 112 - bundled/replace/system/readline.h | 58 - bundled/replace/system/select.h | 41 - bundled/replace/system/shmem.h | 59 - bundled/replace/system/syslog.h | 70 - bundled/replace/system/terminal.h | 46 - bundled/replace/system/time.h | 69 - bundled/replace/system/wait.h | 55 - bundled/replace/system/wscript_configure | 26 - bundled/replace/test/getifaddrs.c | 100 - bundled/replace/test/main.c | 37 - bundled/replace/test/os2_delete.c | 132 - bundled/replace/test/shared_mmap.c | 68 - bundled/replace/test/snprintf.c | 29 - bundled/replace/test/strptime.c | 172 - bundled/replace/test/testsuite.c | 1108 -- bundled/replace/timegm.c | 78 - bundled/replace/timegm.m4 | 1 - bundled/replace/win32.m4 | 20 - bundled/replace/win32_replace.h | 159 - bundled/replace/wscript | 391 - bundled/tdb/.revinfo.git | 8 - bundled/tdb/.tmp_waflock | 0 bundled/tdb/ABI/tdb-1.2.1.sigs | 95 - bundled/tdb/ABI/tdb-1.2.2.sigs | 60 - bundled/tdb/ABI/tdb-1.2.3.sigs | 60 - bundled/tdb/Makefile.in | 80 - bundled/tdb/aclocal.m4 | 1 - bundled/tdb/autogen-waf.sh | 1 - bundled/tdb/autogen.sh | 14 - bundled/tdb/build_macros.m4 | 14 - bundled/tdb/common/check.c | 423 - bundled/tdb/common/dump.c | 137 - bundled/tdb/common/error.c | 57 - bundled/tdb/common/freelist.c | 386 - bundled/tdb/common/freelistcheck.c | 109 - bundled/tdb/common/io.c | 472 - bundled/tdb/common/lock.c | 863 - bundled/tdb/common/open.c | 543 - bundled/tdb/common/tdb.c | 1157 -- bundled/tdb/common/tdb_private.h | 270 - bundled/tdb/common/transaction.c | 1236 -- bundled/tdb/common/traverse.c | 366 - bundled/tdb/config.guess | 1561 -- bundled/tdb/config.mk | 57 - bundled/tdb/config.sub | 1686 -- bundled/tdb/configure.ac | 51 - bundled/tdb/docs/README | 273 - bundled/tdb/docs/tdb.magic | 10 - bundled/tdb/docs/tracing.txt | 46 - bundled/tdb/include/tdb.h | 176 - bundled/tdb/install-sh | 238 - bundled/tdb/libtdb.m4 | 41 - bundled/tdb/manpages/tdbbackup.8.xml | 136 - bundled/tdb/manpages/tdbdump.8.xml | 61 - bundled/tdb/manpages/tdbtool.8.xml | 235 - bundled/tdb/pytdb.c | 506 - bundled/tdb/python.mk | 6 - bundled/tdb/python/tdbdump.py | 12 - bundled/tdb/python/tests/simple.py | 138 - bundled/tdb/rules.mk | 16 - bundled/tdb/script/abi_checks.sh | 91 - bundled/tdb/script/abi_checks_gcc.sh | 35 - bundled/tdb/script/mksigs.pl | 183 - bundled/tdb/script/mksyms.awk | 76 - bundled/tdb/script/mksyms.sh | 45 - bundled/tdb/script/release-script.sh | 67 - bundled/tdb/tdb.exports | 65 - bundled/tdb/tdb.mk | 106 - bundled/tdb/tdb.pc.in | 11 - bundled/tdb/tdb.signatures | 61 - bundled/tdb/tools/tdbbackup.c | 337 - bundled/tdb/tools/tdbdump.c | 116 - bundled/tdb/tools/tdbtest.c | 265 - bundled/tdb/tools/tdbtool.c | 779 - bundled/tdb/tools/tdbtorture.c | 431 - bundled/tdb/web/index.html | 48 - bundled/tdb/wscript | 113 - configure.ac | 2 +- infrastructure/makebuildenv.pl.in | 31 +- infrastructure/makeparcels.pl.in | 3 +- modules.txt | 6 +- parcels.txt | 3 +- qdbm/COPYING | 504 + qdbm/ChangeLog | 990 + qdbm/LTmakefile.in | 318 + qdbm/Makefile.in | 646 + qdbm/NEWS | 43 + qdbm/README | 50 + qdbm/RISCmakefile | 140 + qdbm/THANKS | 45 + qdbm/VCmakefile | 248 + qdbm/cabin.c | 3529 ++++ qdbm/cabin.h | 1544 ++ qdbm/cbcodec.c | 1079 ++ qdbm/cbtest.c | 924 + qdbm/configure | 3913 ++++ qdbm/configure.in | 312 + qdbm/crmgr.c | 956 + qdbm/crtest.c | 873 + qdbm/crtsv.c | 266 + qdbm/curia.c | 1192 ++ qdbm/curia.h | 474 + qdbm/depot.c | 2219 +++ qdbm/depot.h | 492 + qdbm/dpmgr.c | 916 + qdbm/dptest.c | 836 + qdbm/dptsv.c | 261 + qdbm/hovel.c | 568 + qdbm/hovel.h | 278 + qdbm/hvmgr.c | 582 + qdbm/hvtest.c | 272 + qdbm/misc/COPYING.txt | 504 + qdbm/misc/README-win32.txt | 101 + qdbm/misc/VCmakefile-old | 169 + qdbm/misc/benchmark.pdf | Bin 0 -> 52196 bytes qdbm/misc/icon16.png | Bin 0 -> 339 bytes qdbm/misc/icon20.png | Bin 0 -> 275 bytes qdbm/misc/index.html | 202 + qdbm/misc/index.ja.html | 209 + qdbm/misc/logo.png | Bin 0 -> 11430 bytes qdbm/misc/makevcdef | 48 + qdbm/misc/mymemo-ja.html | 34 + qdbm/misc/tutorial-ja.html | 622 + qdbm/misc/win32check.bat | 111 + qdbm/myconf.c | 1113 ++ qdbm/myconf.h | 593 + qdbm/odeum.c | 2090 +++ qdbm/odeum.h | 590 + qdbm/odidx.c | 890 + qdbm/odmgr.c | 1085 ++ qdbm/odtest.c | 694 + qdbm/qdbm.def | 424 + qdbm/qdbm.pc.in | 14 + qdbm/qdbm.spec.in | 218 + qdbm/qmttest.c | 300 + qdbm/relic.c | 266 + qdbm/relic.h | 170 + qdbm/rlmgr.c | 465 + qdbm/rltest.c | 241 + qdbm/spex-ja.html | 4348 +++++ qdbm/spex.html | 4343 +++++ qdbm/villa.c | 2666 +++ qdbm/villa.h | 758 + qdbm/vista.c | 171 + qdbm/vista.h | 138 + qdbm/vlmgr.c | 968 + qdbm/vltest.c | 1507 ++ qdbm/vltsv.c | 261 + 208 files changed, 50823 insertions(+), 60055 deletions(-) delete mode 100644 bundled/replace/.checker_innocent delete mode 100644 bundled/replace/.revinfo.git delete mode 100644 bundled/replace/Makefile.in delete mode 100644 bundled/replace/README delete mode 100644 bundled/replace/aclocal.m4 delete mode 100644 bundled/replace/autoconf-2.60.m4 delete mode 120000 bundled/replace/autogen-waf.sh delete mode 100755 bundled/replace/autogen.sh delete mode 100644 bundled/replace/build_macros.m4 delete mode 100755 bundled/replace/config.guess delete mode 100644 bundled/replace/config.h.in delete mode 100755 bundled/replace/config.sub delete mode 100755 bundled/replace/configure delete mode 100644 bundled/replace/configure.ac delete mode 100644 bundled/replace/crypt.c delete mode 100644 bundled/replace/crypt.m4 delete mode 100644 bundled/replace/dlfcn.c delete mode 100644 bundled/replace/dlfcn.m4 delete mode 100644 bundled/replace/getaddrinfo.c delete mode 100644 bundled/replace/getaddrinfo.h delete mode 100644 bundled/replace/getifaddrs.c delete mode 100644 bundled/replace/getpass.c delete mode 100644 bundled/replace/getpass.m4 delete mode 100644 bundled/replace/hdr_replace.h delete mode 100644 bundled/replace/inet_aton.c delete mode 100644 bundled/replace/inet_ntoa.c delete mode 100644 bundled/replace/inet_ntop.c delete mode 100644 bundled/replace/inet_pton.c delete mode 100755 bundled/replace/install-sh delete mode 100644 bundled/replace/libreplace.m4 delete mode 100644 bundled/replace/libreplace_cc.m4 delete mode 100644 bundled/replace/libreplace_ld.m4 delete mode 100644 bundled/replace/libreplace_macros.m4 delete mode 100644 bundled/replace/libreplace_network.m4 delete mode 100644 bundled/replace/repdir.m4 delete mode 100644 bundled/replace/repdir_getdents.c delete mode 100644 bundled/replace/repdir_getdirentries.c delete mode 100644 bundled/replace/replace.c delete mode 100644 bundled/replace/replace.h delete mode 100644 bundled/replace/samba.m4 delete mode 100644 bundled/replace/snprintf.c delete mode 100644 bundled/replace/socket.c delete mode 100644 bundled/replace/socketpair.c delete mode 100644 bundled/replace/strptime.c delete mode 100644 bundled/replace/strptime.m4 delete mode 100644 bundled/replace/system/README delete mode 100644 bundled/replace/system/aio.h delete mode 100644 bundled/replace/system/capability.h delete mode 100644 bundled/replace/system/config.m4 delete mode 100644 bundled/replace/system/dir.h delete mode 100644 bundled/replace/system/filesys.h delete mode 100644 bundled/replace/system/glob.h delete mode 100644 bundled/replace/system/iconv.h delete mode 100644 bundled/replace/system/kerberos.h delete mode 100644 bundled/replace/system/locale.h delete mode 100644 bundled/replace/system/network.h delete mode 100644 bundled/replace/system/passwd.h delete mode 100644 bundled/replace/system/readline.h delete mode 100644 bundled/replace/system/select.h delete mode 100644 bundled/replace/system/shmem.h delete mode 100644 bundled/replace/system/syslog.h delete mode 100644 bundled/replace/system/terminal.h delete mode 100644 bundled/replace/system/time.h delete mode 100644 bundled/replace/system/wait.h delete mode 100644 bundled/replace/system/wscript_configure delete mode 100644 bundled/replace/test/getifaddrs.c delete mode 100644 bundled/replace/test/main.c delete mode 100644 bundled/replace/test/os2_delete.c delete mode 100644 bundled/replace/test/shared_mmap.c delete mode 100644 bundled/replace/test/snprintf.c delete mode 100644 bundled/replace/test/strptime.c delete mode 100644 bundled/replace/test/testsuite.c delete mode 100644 bundled/replace/timegm.c delete mode 100644 bundled/replace/timegm.m4 delete mode 100644 bundled/replace/win32.m4 delete mode 100644 bundled/replace/win32_replace.h delete mode 100644 bundled/replace/wscript delete mode 100644 bundled/tdb/.revinfo.git delete mode 100644 bundled/tdb/.tmp_waflock delete mode 100644 bundled/tdb/ABI/tdb-1.2.1.sigs delete mode 100644 bundled/tdb/ABI/tdb-1.2.2.sigs delete mode 100644 bundled/tdb/ABI/tdb-1.2.3.sigs delete mode 100644 bundled/tdb/Makefile.in delete mode 100644 bundled/tdb/aclocal.m4 delete mode 120000 bundled/tdb/autogen-waf.sh delete mode 100755 bundled/tdb/autogen.sh delete mode 100644 bundled/tdb/build_macros.m4 delete mode 100644 bundled/tdb/common/check.c delete mode 100644 bundled/tdb/common/dump.c delete mode 100644 bundled/tdb/common/error.c delete mode 100644 bundled/tdb/common/freelist.c delete mode 100644 bundled/tdb/common/freelistcheck.c delete mode 100644 bundled/tdb/common/io.c delete mode 100644 bundled/tdb/common/lock.c delete mode 100644 bundled/tdb/common/open.c delete mode 100644 bundled/tdb/common/tdb.c delete mode 100644 bundled/tdb/common/tdb_private.h delete mode 100644 bundled/tdb/common/transaction.c delete mode 100644 bundled/tdb/common/traverse.c delete mode 100755 bundled/tdb/config.guess delete mode 100644 bundled/tdb/config.mk delete mode 100755 bundled/tdb/config.sub delete mode 100644 bundled/tdb/configure.ac delete mode 100644 bundled/tdb/docs/README delete mode 100644 bundled/tdb/docs/tdb.magic delete mode 100644 bundled/tdb/docs/tracing.txt delete mode 100644 bundled/tdb/include/tdb.h delete mode 100755 bundled/tdb/install-sh delete mode 100644 bundled/tdb/libtdb.m4 delete mode 100644 bundled/tdb/manpages/tdbbackup.8.xml delete mode 100644 bundled/tdb/manpages/tdbdump.8.xml delete mode 100644 bundled/tdb/manpages/tdbtool.8.xml delete mode 100644 bundled/tdb/pytdb.c delete mode 100644 bundled/tdb/python.mk delete mode 100644 bundled/tdb/python/tdbdump.py delete mode 100644 bundled/tdb/python/tests/simple.py delete mode 100644 bundled/tdb/rules.mk delete mode 100755 bundled/tdb/script/abi_checks.sh delete mode 100755 bundled/tdb/script/abi_checks_gcc.sh delete mode 100755 bundled/tdb/script/mksigs.pl delete mode 100644 bundled/tdb/script/mksyms.awk delete mode 100755 bundled/tdb/script/mksyms.sh delete mode 100755 bundled/tdb/script/release-script.sh delete mode 100644 bundled/tdb/tdb.exports delete mode 100644 bundled/tdb/tdb.mk delete mode 100644 bundled/tdb/tdb.pc.in delete mode 100644 bundled/tdb/tdb.signatures delete mode 100644 bundled/tdb/tools/tdbbackup.c delete mode 100644 bundled/tdb/tools/tdbdump.c delete mode 100644 bundled/tdb/tools/tdbtest.c delete mode 100644 bundled/tdb/tools/tdbtool.c delete mode 100644 bundled/tdb/tools/tdbtorture.c delete mode 100644 bundled/tdb/web/index.html delete mode 100644 bundled/tdb/wscript create mode 100644 qdbm/COPYING create mode 100644 qdbm/ChangeLog create mode 100644 qdbm/LTmakefile.in create mode 100644 qdbm/Makefile.in create mode 100644 qdbm/NEWS create mode 100644 qdbm/README create mode 100644 qdbm/RISCmakefile create mode 100644 qdbm/THANKS create mode 100644 qdbm/VCmakefile create mode 100644 qdbm/cabin.c create mode 100644 qdbm/cabin.h create mode 100644 qdbm/cbcodec.c create mode 100644 qdbm/cbtest.c create mode 100755 qdbm/configure create mode 100644 qdbm/configure.in create mode 100644 qdbm/crmgr.c create mode 100644 qdbm/crtest.c create mode 100644 qdbm/crtsv.c create mode 100644 qdbm/curia.c create mode 100644 qdbm/curia.h create mode 100644 qdbm/depot.c create mode 100644 qdbm/depot.h create mode 100644 qdbm/dpmgr.c create mode 100644 qdbm/dptest.c create mode 100644 qdbm/dptsv.c create mode 100644 qdbm/hovel.c create mode 100644 qdbm/hovel.h create mode 100644 qdbm/hvmgr.c create mode 100644 qdbm/hvtest.c create mode 100644 qdbm/misc/COPYING.txt create mode 100644 qdbm/misc/README-win32.txt create mode 100644 qdbm/misc/VCmakefile-old create mode 100644 qdbm/misc/benchmark.pdf create mode 100644 qdbm/misc/icon16.png create mode 100644 qdbm/misc/icon20.png create mode 100644 qdbm/misc/index.html create mode 100644 qdbm/misc/index.ja.html create mode 100644 qdbm/misc/logo.png create mode 100755 qdbm/misc/makevcdef create mode 100644 qdbm/misc/mymemo-ja.html create mode 100644 qdbm/misc/tutorial-ja.html create mode 100644 qdbm/misc/win32check.bat create mode 100644 qdbm/myconf.c create mode 100644 qdbm/myconf.h create mode 100644 qdbm/odeum.c create mode 100644 qdbm/odeum.h create mode 100644 qdbm/odidx.c create mode 100644 qdbm/odmgr.c create mode 100644 qdbm/odtest.c create mode 100644 qdbm/qdbm.def create mode 100644 qdbm/qdbm.pc.in create mode 100644 qdbm/qdbm.spec.in create mode 100644 qdbm/qmttest.c create mode 100644 qdbm/relic.c create mode 100644 qdbm/relic.h create mode 100644 qdbm/rlmgr.c create mode 100644 qdbm/rltest.c create mode 100644 qdbm/spex-ja.html create mode 100644 qdbm/spex.html create mode 100644 qdbm/villa.c create mode 100644 qdbm/villa.h create mode 100644 qdbm/vista.c create mode 100644 qdbm/vista.h create mode 100644 qdbm/vlmgr.c create mode 100644 qdbm/vltest.c create mode 100644 qdbm/vltsv.c diff --git a/bin/bbackupd/BackupClientInodeToIDMap.cpp b/bin/bbackupd/BackupClientInodeToIDMap.cpp index 262e5bc2..74d5f3cd 100644 --- a/bin/bbackupd/BackupClientInodeToIDMap.cpp +++ b/bin/bbackupd/BackupClientInodeToIDMap.cpp @@ -10,9 +10,7 @@ #include "Box.h" #include - -#define _PUBLIC_ -#include "tdb.h" +#include #define BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION #include "BackupClientInodeToIDMap.h" @@ -28,7 +26,7 @@ typedef struct int64_t mInDirectory; } IDBRecord; -#define BOX_DBM_MESSAGE(stuff) stuff << " (tdb): " << tdb_error(mpContext) +#define BOX_DBM_MESSAGE(stuff) stuff << " (qdbm): " << dperrmsg(dpecode) #define BOX_LOG_DBM_ERROR(stuff) \ BOX_ERROR(BOX_DBM_MESSAGE(stuff)) @@ -38,21 +36,21 @@ typedef struct THROW_EXCEPTION_MESSAGE(exception, subtype, \ BOX_DBM_MESSAGE(message << ": " << filename)); -#define ASSERT_DBM(success, message, exception, subtype) \ - if(!(success)) \ +#define ASSERT_DBM_OK(operation, message, filename, exception, subtype) \ + if(!(operation)) \ { \ - THROW_DBM_ERROR(message, mFilename, exception, subtype); \ + THROW_DBM_ERROR(message, filename, exception, subtype); \ } #define ASSERT_DBM_OPEN() \ - if(mpContext == 0) \ + if(mpDepot == 0) \ { \ THROW_EXCEPTION_MESSAGE(BackupStoreException, InodeMapNotOpen, \ "Inode database not open"); \ } #define ASSERT_DBM_CLOSED() \ - if(mpContext != 0) \ + if(mpDepot != 0) \ { \ THROW_EXCEPTION_MESSAGE(CommonException, Internal, \ "Inode database already open: " << mFilename); \ @@ -69,7 +67,7 @@ typedef struct BackupClientInodeToIDMap::BackupClientInodeToIDMap() : mReadOnly(true), mEmpty(false), - mpContext(NULL) + mpDepot(0) { } @@ -83,7 +81,7 @@ BackupClientInodeToIDMap::BackupClientInodeToIDMap() // -------------------------------------------------------------------------- BackupClientInodeToIDMap::~BackupClientInodeToIDMap() { - if(mpContext != NULL) + if(mpDepot != 0) { Close(); } @@ -110,15 +108,15 @@ void BackupClientInodeToIDMap::Open(const char *Filename, bool ReadOnly, ASSERT(!mEmpty); // Open the database file - int mode = ReadOnly ? O_RDONLY : O_RDWR; + int mode = ReadOnly ? DP_OREADER : DP_OWRITER; if(CreateNew) { - mode |= O_CREAT; + mode |= DP_OCREAT; } - mpContext = tdb_open(Filename, 0, 0, mode, 0700); + mpDepot = dpopen(Filename, mode, 0); - ASSERT_DBM(mpContext != NULL, "Failed to open inode database", + ASSERT_DBM_OK(mpDepot, "Failed to open inode database", mFilename, BackupStoreException, BerkelyDBFailure); // Read only flag @@ -139,7 +137,7 @@ void BackupClientInodeToIDMap::Open(const char *Filename, bool ReadOnly, void BackupClientInodeToIDMap::OpenEmpty() { ASSERT_DBM_CLOSED(); - ASSERT(mpContext == NULL); + ASSERT(mpDepot == 0); mEmpty = true; mReadOnly = true; } @@ -155,22 +153,11 @@ void BackupClientInodeToIDMap::OpenEmpty() void BackupClientInodeToIDMap::Close() { ASSERT_DBM_OPEN(); - ASSERT_DBM(tdb_close(mpContext) == 0, "Failed to close inode database", - BackupStoreException, BerkelyDBFailure); - mpContext = NULL; + ASSERT_DBM_OK(dpclose(mpDepot), "Failed to close inode database", + mFilename, BackupStoreException, BerkelyDBFailure); + mpDepot = 0; } -static TDB_DATA GetDatum(void* dptr, size_t dsize) -{ - TDB_DATA datum; - datum.dptr = (unsigned char *)dptr; - datum.dsize = dsize; - return datum; -} - -#define GET_STRUCT_DATUM(structure) \ - GetDatum(&structure, sizeof(structure)) - // -------------------------------------------------------------------------- // // Function @@ -189,7 +176,7 @@ void BackupClientInodeToIDMap::AddToMap(InodeRefType InodeRef, int64_t ObjectID, THROW_EXCEPTION(BackupStoreException, InodeMapIsReadOnly); } - if(mpContext == 0) + if(mpDepot == 0) { THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); } @@ -201,9 +188,9 @@ void BackupClientInodeToIDMap::AddToMap(InodeRefType InodeRef, int64_t ObjectID, rec.mObjectID = ObjectID; rec.mInDirectory = InDirectory; - ASSERT_DBM(tdb_store(mpContext, GET_STRUCT_DATUM(InodeRef), - GET_STRUCT_DATUM(rec), 0) == 0, - "Failed to add record to inode database", + ASSERT_DBM_OK(dpput(mpDepot, (const char *)&InodeRef, sizeof(InodeRef), + (const char *)&rec, sizeof(rec), DP_DOVER), + "Failed to add record to inode database", mFilename, BackupStoreException, BerkelyDBFailure); } @@ -227,33 +214,22 @@ bool BackupClientInodeToIDMap::Lookup(InodeRefType InodeRef, return false; } - if(mpContext == 0) + if(mpDepot == 0) { THROW_EXCEPTION(BackupStoreException, InodeMapNotOpen); } ASSERT_DBM_OPEN(); - TDB_DATA datum = tdb_fetch(mpContext, GET_STRUCT_DATUM(InodeRef)); - if(datum.dptr == NULL) + IDBRecord rec; + + if(dpgetwb(mpDepot, (const char *)&InodeRef, sizeof(InodeRef), + 0, sizeof(IDBRecord), (char *)&rec) == -1) { // key not in file return false; } - - IDBRecord rec; - if(datum.dsize != sizeof(rec)) - { - THROW_EXCEPTION_MESSAGE(CommonException, Internal, - "Failed to get inode database entry: " - "record has wrong size: expected " << - sizeof(rec) << " but was " << datum.dsize << - " in " << mFilename); - } - rec = *(IDBRecord *)datum.dptr; - free(datum.dptr); - // Return data rObjectIDOut = rec.mObjectID; rInDirectoryOut = rec.mInDirectory; diff --git a/bin/bbackupd/BackupClientInodeToIDMap.h b/bin/bbackupd/BackupClientInodeToIDMap.h index f47c7a54..fbe45114 100644 --- a/bin/bbackupd/BackupClientInodeToIDMap.h +++ b/bin/bbackupd/BackupClientInodeToIDMap.h @@ -17,8 +17,7 @@ // avoid having to include the DB files when not necessary #ifndef BACKIPCLIENTINODETOIDMAP_IMPLEMENTATION - struct TDB_CONTEXT; - struct TDB_DATUM; + class DEPOT; #endif // -------------------------------------------------------------------------- @@ -50,7 +49,7 @@ private: bool mReadOnly; bool mEmpty; std::string mFilename; - TDB_CONTEXT *mpContext; + DEPOT *mpDepot; }; #endif // BACKUPCLIENTINODETOIDMAP_H diff --git a/bootstrap b/bootstrap index eaf83d5d..14fc19e3 100755 --- a/bootstrap +++ b/bootstrap @@ -1,8 +1,5 @@ #!/bin/sh -set -e - aclocal -I infrastructure/m4 autoheader autoconf -( cd bundled/tdb; ./autogen.sh; ) diff --git a/bundled/replace/.checker_innocent b/bundled/replace/.checker_innocent deleted file mode 100644 index e6191765..00000000 --- a/bundled/replace/.checker_innocent +++ /dev/null @@ -1,4 +0,0 @@ ->>>MISTAKE21_create_files_6a9e68ada99a97cb ->>>MISTAKE21_os2_delete_9b2bfa7f38711d09 ->>>MISTAKE21_os2_delete_2fcc29aaa99a97cb ->>>SECURITY2_os2_delete_9b2bfa7f1c9396ca diff --git a/bundled/replace/.revinfo.git b/bundled/replace/.revinfo.git deleted file mode 100644 index 879f239a..00000000 --- a/bundled/replace/.revinfo.git +++ /dev/null @@ -1,6 +0,0 @@ -481044f -1282569007 -481044f8b303236bc9932b91ed689bb189382494 -Mon Aug 23 15:10:07 2010 +0200 - lib/replace/replace.h | 6 +++--- - 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bundled/replace/Makefile.in b/bundled/replace/Makefile.in deleted file mode 100644 index 65f8125e..00000000 --- a/bundled/replace/Makefile.in +++ /dev/null @@ -1,70 +0,0 @@ -#!gmake -# -CC = @CC@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ -bindir = @bindir@ -includedir = @includedir@ -libdir = @libdir@ -VPATH = @libreplacedir@ -srcdir = @srcdir@ -builddir = @builddir@ -sharedbuilddir = @sharedbuilddir@ -INSTALLCMD = @INSTALL@ -LIBS = @LIBS@ - -.PHONY: test all showflags install installcheck clean distclean realdistclean - -CFLAGS=-I. @CFLAGS@ -LDFLAGS=@LDFLAGS@ - -OBJS = @LIBREPLACEOBJ@ - -all: showflags libreplace.a testsuite - -showflags: - @echo 'libreplace will be compiled with flags:' - @echo ' CC = $(CC)' - @echo ' CFLAGS = $(CFLAGS)' - @echo ' LDFLAGS= $(LDFLAGS)' - @echo ' LIBS = $(LIBS)' - -install: all - ${INSTALLCMD} -d $(libdir) - ${INSTALLCMD} -m 644 libreplace.a $(libdir) - -shared-build: all - ${INSTALLCMD} -d $(sharedbuilddir)/include - ${INSTALLCMD} -m 644 replace.h $(sharedbuilddir)/include - ${INSTALLCMD} -d $(sharedbuilddir)/lib - ${INSTALLCMD} -m 644 libreplace.a $(sharedbuilddir)/lib - -libreplace.a: $(OBJS) - ar -rcsv $@ $(OBJS) - -test: all - ./testsuite - -installcheck: install test - -TEST_OBJS = test/main.o test/testsuite.o test/os2_delete.o test/strptime.o test/getifaddrs.o - -testsuite: libreplace.a $(TEST_OBJS) - $(CC) -o testsuite $(TEST_OBJS) -L. -lreplace $(LDFLAGS) $(LIBS) - -.c.o: - @echo Compiling $*.c - @mkdir -p `dirname $@` - @$(CC) $(CFLAGS) -c $< -o $@ - -clean: - rm -f *.o test/*.o *.a testsuite - rm -f testfile.dat - -distclean: clean - rm -f *~ */*~ - rm -f config.log config.status config.h config.cache - rm -f Makefile - -realdistclean: distclean - rm -f configure config.h.in diff --git a/bundled/replace/README b/bundled/replace/README deleted file mode 100644 index b2d2e4fe..00000000 --- a/bundled/replace/README +++ /dev/null @@ -1,123 +0,0 @@ -This subsystem ensures that we can always use a certain core set of -functions and types, that are either provided by the OS or by replacement -functions / definitions in this subsystem. The aim is to try to stick -to POSIX functions in here as much as possible. Convenience functions -that are available on no platform at all belong in other subsystems -(such as LIBUTIL). - -The following functions are guaranteed: - -ftruncate -strlcpy -strlcat -mktime -rename -initgroups -memmove -strdup -setlinebuf -vsyslog -timegm -setenv -unsetenv -strndup -strnlen -waitpid -seteuid -setegid -asprintf -snprintf -vasprintf -vsnprintf -opendir -readdir -telldir -seekdir -closedir -dlopen -dlclose -dlsym -dlerror -chroot -bzero -strerror -errno -mkdtemp -mkstemp (a secure one!) -pread -pwrite -chown -lchown -getpass -readline (the library) -inet_ntoa -inet_ntop -inet_pton -inet_aton -strtoll -strtoull -socketpair -strptime -getaddrinfo -freeaddrinfo -getnameinfo -gai_strerror -getifaddrs -freeifaddrs -utime -utimes -dup2 -link -readlink -symlink -realpath - -Types: -bool -socklen_t -uint{8,16,32,64}_t -int{8,16,32,64}_t -intptr_t -sig_atomic_t - -Constants: -PATH_NAME_MAX -UINT{16,32,64}_MAX -INT32_MAX -RTLD_LAZY -HOST_NAME_MAX -UINT16_MAX -UINT32_MAX -UINT64_MAX -CHAR_BIT - -Macros: -va_copy -__FUNCTION__ -__FILE__ -__LINE__ -__LINESTR__ -__location__ -__STRING -__STRINGSTRING -MIN -MAX -QSORT_CAST -ZERO_STRUCT -ZERO_STRUCTP -ZERO_STRUCTPN -ZERO_ARRAY -ARRAY_SIZE -PTR_DIFF - -Headers: -stdint.h -stdbool.h - -Optional C keywords: -volatile - -Prerequisites: -memset (for bzero) -syslog (for vsyslog) -mktemp (for mkstemp and mkdtemp) diff --git a/bundled/replace/aclocal.m4 b/bundled/replace/aclocal.m4 deleted file mode 100644 index 5605e476..00000000 --- a/bundled/replace/aclocal.m4 +++ /dev/null @@ -1 +0,0 @@ -m4_include(libreplace.m4) diff --git a/bundled/replace/autoconf-2.60.m4 b/bundled/replace/autoconf-2.60.m4 deleted file mode 100644 index b2694fde..00000000 --- a/bundled/replace/autoconf-2.60.m4 +++ /dev/null @@ -1,236 +0,0 @@ -# AC_GNU_SOURCE -# -------------- -AC_DEFUN([AC_GNU_SOURCE], -[AH_VERBATIM([_GNU_SOURCE], -[/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# undef _GNU_SOURCE -#endif])dnl -AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl -AC_BEFORE([$0], [AC_RUN_IFELSE])dnl -AC_DEFINE([_GNU_SOURCE]) -]) - -# _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST, -# ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE) -# -------------------------------------------------------------- -# Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99') -# by trying to compile a program of TEST-PROLOGUE and TEST-BODY. If this fails, -# try again with each compiler option in the space-separated OPTION-LIST; if one -# helps, append it to CC. If eventually successful, run ACTION-IF-AVAILABLE, -# else ACTION-IF-UNAVAILABLE. -AC_DEFUN([_AC_C_STD_TRY], -[AC_MSG_CHECKING([for $CC option to accept ISO ]m4_translit($1, [c], [C])) -AC_CACHE_VAL(ac_cv_prog_cc_$1, -[ac_cv_prog_cc_$1=no -ac_save_CC=$CC -AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])]) -for ac_arg in '' $4 -do - CC="$ac_save_CC $ac_arg" - _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg]) - test "x$ac_cv_prog_cc_$1" != "xno" && break -done -rm -f conftest.$ac_ext -CC=$ac_save_CC -])# AC_CACHE_VAL -case "x$ac_cv_prog_cc_$1" in - x) - AC_MSG_RESULT([none needed]) ;; - xno) - AC_MSG_RESULT([unsupported]) ;; - *) - CC="$CC $ac_cv_prog_cc_$1" - AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;; -esac -AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6]) -])# _AC_C_STD_TRY - -# _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE]) -# ---------------------------------------------------------------- -# If the C compiler is not in ISO C99 mode by default, try to add an -# option to output variable CC to make it so. This macro tries -# various options that select ISO C99 on some system or another. It -# considers the compiler to be in ISO C99 mode if it handles mixed -# code and declarations, _Bool, inline and restrict. -AC_DEFUN([_AC_PROG_CC_C99], -[_AC_C_STD_TRY([c99], -[[#include -#include -#include -#include -#include - -struct incomplete_array -{ - int datasize; - double data[]; -}; - -struct named_init { - int number; - const wchar_t *name; - double average; -}; - -typedef const char *ccp; - -static inline int -test_restrict(ccp restrict text) -{ - // See if C++-style comments work. - // Iterate through items via the restricted pointer. - // Also check for declarations in for loops. - for (unsigned int i = 0; *(text+i) != '\0'; ++i) - continue; - return 0; -} - -// Check varargs and va_copy work. -static void -test_varargs(const char *format, ...) -{ - va_list args; - va_start(args, format); - va_list args_copy; - va_copy(args_copy, args); - - const char *str; - int number; - float fnumber; - - while (*format) - { - switch (*format++) - { - case 's': // string - str = va_arg(args_copy, const char *); - break; - case 'd': // int - number = va_arg(args_copy, int); - break; - case 'f': // float - fnumber = (float) va_arg(args_copy, double); - break; - default: - break; - } - } - va_end(args_copy); - va_end(args); -} -]], -[[ - // Check bool and long long datatypes. - _Bool success = false; - long long int bignum = -1234567890LL; - unsigned long long int ubignum = 1234567890uLL; - - // Check restrict. - if (test_restrict("String literal") != 0) - success = true; - char *restrict newvar = "Another string"; - - // Check varargs. - test_varargs("s, d' f .", "string", 65, 34.234); - - // Check incomplete arrays work. - struct incomplete_array *ia = - malloc(sizeof(struct incomplete_array) + (sizeof(double) * 10)); - ia->datasize = 10; - for (int i = 0; i < ia->datasize; ++i) - ia->data[i] = (double) i * 1.234; - - // Check named initialisers. - struct named_init ni = { - .number = 34, - .name = L"Test wide string", - .average = 543.34343, - }; - - ni.number = 58; - - int dynamic_array[ni.number]; - dynamic_array[43] = 543; - - // work around unused variable warnings - return bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'; -]], -dnl Try -dnl GCC -std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999) -dnl AIX -qlanglvl=extc99 (unused restrictive mode: -qlanglvl=stdc99) -dnl Intel ICC -c99 -dnl IRIX -c99 -dnl Solaris (unused because it causes the compiler to assume C99 semantics for -dnl library functions, and this is invalid before Solaris 10: -xc99) -dnl Tru64 -c99 -dnl with extended modes being tried first. -[[-std=gnu99 -c99 -qlanglvl=extc99]], [$1], [$2])[]dnl -])# _AC_PROG_CC_C99 - -# AC_PROG_CC_C99 -# -------------- -AC_DEFUN([AC_PROG_CC_C99], -[ AC_REQUIRE([AC_PROG_CC])dnl - _AC_PROG_CC_C99 -]) - -# AC_USE_SYSTEM_EXTENSIONS -# ------------------------ -# Enable extensions on systems that normally disable them, -# typically due to standards-conformance issues. -m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[ -AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS], -[AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl -AC_BEFORE([$0], [AC_RUN_IFELSE])dnl - - AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=]) - if test "$MINIX" = yes; then - AC_DEFINE([_POSIX_SOURCE], [1], - [Define to 1 if you need to in order for `stat' and other - things to work.]) - AC_DEFINE([_POSIX_1_SOURCE], [2], - [Define to 2 if the system does not provide POSIX.1 features - except with this defined.]) - AC_DEFINE([_MINIX], [1], - [Define to 1 if on MINIX.]) - fi - - AH_VERBATIM([__EXTENSIONS__], -[/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# undef _ALL_SOURCE -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# undef _GNU_SOURCE -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# undef _POSIX_PTHREAD_SEMANTICS -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# undef _TANDEM_SOURCE -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# undef __EXTENSIONS__ -#endif -]) - AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], - [ac_cv_safe_to_define___extensions__], - [AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[ -# define __EXTENSIONS__ 1 - ]AC_INCLUDES_DEFAULT])], - [ac_cv_safe_to_define___extensions__=yes], - [ac_cv_safe_to_define___extensions__=no])]) - test $ac_cv_safe_to_define___extensions__ = yes && - AC_DEFINE([__EXTENSIONS__]) - AC_DEFINE([_ALL_SOURCE]) - AC_DEFINE([_GNU_SOURCE]) - AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) - AC_DEFINE([_TANDEM_SOURCE]) -])# AC_USE_SYSTEM_EXTENSIONS -]) diff --git a/bundled/replace/autogen-waf.sh b/bundled/replace/autogen-waf.sh deleted file mode 120000 index 99150f3a..00000000 --- a/bundled/replace/autogen-waf.sh +++ /dev/null @@ -1 +0,0 @@ -../../buildtools/scripts/autogen-waf.sh \ No newline at end of file diff --git a/bundled/replace/autogen.sh b/bundled/replace/autogen.sh deleted file mode 100755 index d46a4279..00000000 --- a/bundled/replace/autogen.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -rm -rf autom4te.cache -rm -f configure config.h.in - -autoheader || exit 1 -autoconf || exit 1 - -rm -rf autom4te.cache - -echo "Now run ./configure and then make." -exit 0 - diff --git a/bundled/replace/build_macros.m4 b/bundled/replace/build_macros.m4 deleted file mode 100644 index c036668c..00000000 --- a/bundled/replace/build_macros.m4 +++ /dev/null @@ -1,14 +0,0 @@ -AC_DEFUN(BUILD_WITH_SHARED_BUILD_DIR, - [ AC_ARG_WITH([shared-build-dir], - [AC_HELP_STRING([--with-shared-build-dir=DIR], - [temporary build directory where libraries are installed [$srcdir/sharedbuild]])]) - - sharedbuilddir="$srcdir/sharedbuild" - if test x"$with_shared_build_dir" != x; then - sharedbuilddir=$with_shared_build_dir - CFLAGS="$CFLAGS -I$with_shared_build_dir/include" - LDFLAGS="$LDFLAGS -L$with_shared_build_dir/lib" - fi - AC_SUBST(sharedbuilddir) - ]) - diff --git a/bundled/replace/config.guess b/bundled/replace/config.guess deleted file mode 100755 index da833146..00000000 --- a/bundled/replace/config.guess +++ /dev/null @@ -1,1561 +0,0 @@ -#! /bin/sh -# Attempt to guess a canonical system name. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 -# Free Software Foundation, Inc. - -timestamp='2009-04-27' - -# This file is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Originally written by Per Bothner . -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. -# -# This script attempts to guess a canonical system name similar to -# config.sub. If it succeeds, it prints the system name on stdout, and -# exits with 0. Otherwise, it exits with 1. -# -# The plan is that this can be called by configure scripts if you -# don't specify an explicit build system type. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] - -Output the configuration name of the system \`$me' is run on. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.guess ($timestamp) - -Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" >&2 - exit 1 ;; - * ) - break ;; - esac -done - -if test $# != 0; then - echo "$me: too many arguments$help" >&2 - exit 1 -fi - -trap 'exit 1' 1 2 15 - -# CC_FOR_BUILD -- compiler used by this script. Note that the use of a -# compiler to aid in system detection is discouraged as it requires -# temporary files to be created and, as you can see below, it is a -# headache to deal with in a portable fashion. - -# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still -# use `HOST_CC' if defined, but it is deprecated. - -# Portable tmp directory creation inspired by the Autoconf team. - -set_cc_for_build=' -trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; -trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; -: ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; -dummy=$tmp/dummy ; -tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; -case $CC_FOR_BUILD,$HOST_CC,$CC in - ,,) echo "int x;" > $dummy.c ; - for c in cc gcc c89 c99 ; do - if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then - CC_FOR_BUILD="$c"; break ; - fi ; - done ; - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found ; - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; set_cc_for_build= ;' - -# This is needed to find uname on a Pyramid OSx when run in the BSD universe. -# (ghazi@noc.rutgers.edu 1994-08-24) -if (test -f /.attbin/uname) >/dev/null 2>&1 ; then - PATH=$PATH:/.attbin ; export PATH -fi - -UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown -UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown -UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown - -# Note: order is significant - the case branches are not exclusive. - -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in - *:NetBSD:*:*) - # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, - # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently - # switched to ELF, *-*-netbsd* would select the old - # object file format. This provides both forward - # compatibility and a consistent mechanism for selecting the - # object file format. - # - # Note: NetBSD doesn't particularly care about the vendor - # portion of the name. We always set it to "unknown". - sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || echo unknown)` - case "${UNAME_MACHINE_ARCH}" in - armeb) machine=armeb-unknown ;; - arm*) machine=arm-unknown ;; - sh3el) machine=shl-unknown ;; - sh3eb) machine=sh-unknown ;; - sh5el) machine=sh5le-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-unknown ;; - esac - # The Operating System including object format, if it has switched - # to ELF recently, or will in the future. - case "${UNAME_MACHINE_ARCH}" in - arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build - if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep __ELF__ >/dev/null - then - # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). - # Return netbsd for either. FIX? - os=netbsd - else - os=netbsdelf - fi - ;; - *) - os=netbsd - ;; - esac - # The OS release - # Debian GNU/NetBSD machines have a different userland, and - # thus, need a distinct triplet. However, they do not need - # kernel version information, so it can be replaced with a - # suitable tag, in the style of linux-gnu. - case "${UNAME_VERSION}" in - Debian*) - release='-gnu' - ;; - *) - release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` - ;; - esac - # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: - # contains redundant information, the shorter form: - # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}" - exit ;; - *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} - exit ;; - *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} - exit ;; - *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} - exit ;; - macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd${UNAME_RELEASE} - exit ;; - *:MirBSD:*:*) - echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} - exit ;; - alpha:OSF1:*:*) - case $UNAME_RELEASE in - *4.0) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - ;; - *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` - ;; - esac - # According to Compaq, /usr/sbin/psrinfo has been available on - # OSF/1 and Tru64 systems produced since 1995. I hope that - # covers most systems running today. This code pipes the CPU - # types through head -n 1, so we only detect the type of CPU 0. - ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` - case "$ALPHA_CPU_TYPE" in - "EV4 (21064)") - UNAME_MACHINE="alpha" ;; - "EV4.5 (21064)") - UNAME_MACHINE="alpha" ;; - "LCA4 (21066/21068)") - UNAME_MACHINE="alpha" ;; - "EV5 (21164)") - UNAME_MACHINE="alphaev5" ;; - "EV5.6 (21164A)") - UNAME_MACHINE="alphaev56" ;; - "EV5.6 (21164PC)") - UNAME_MACHINE="alphapca56" ;; - "EV5.7 (21164PC)") - UNAME_MACHINE="alphapca57" ;; - "EV6 (21264)") - UNAME_MACHINE="alphaev6" ;; - "EV6.7 (21264A)") - UNAME_MACHINE="alphaev67" ;; - "EV6.8CB (21264C)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8AL (21264B)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8CX (21264D)") - UNAME_MACHINE="alphaev68" ;; - "EV6.9A (21264/EV69A)") - UNAME_MACHINE="alphaev69" ;; - "EV7 (21364)") - UNAME_MACHINE="alphaev7" ;; - "EV7.9 (21364A)") - UNAME_MACHINE="alphaev79" ;; - esac - # A Pn.n version is a patched version. - # A Vn.n version is a released version. - # A Tn.n version is a released field test version. - # A Xn.n version is an unreleased experimental baselevel. - # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit ;; - Alpha\ *:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # Should we change UNAME_MACHINE based on the output of uname instead - # of the specific Alpha model? - echo alpha-pc-interix - exit ;; - 21064:Windows_NT:50:3) - echo alpha-dec-winnt3.5 - exit ;; - Amiga*:UNIX_System_V:4.0:*) - echo m68k-unknown-sysv4 - exit ;; - *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-amigaos - exit ;; - *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-morphos - exit ;; - *:OS/390:*:*) - echo i370-ibm-openedition - exit ;; - *:z/VM:*:*) - echo s390-ibm-zvmoe - exit ;; - *:OS400:*:*) - echo powerpc-ibm-os400 - exit ;; - arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} - exit ;; - arm:riscos:*:*|arm:RISCOS:*:*) - echo arm-unknown-riscos - exit ;; - SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) - echo hppa1.1-hitachi-hiuxmpp - exit ;; - Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) - # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "`(/bin/universe) 2>/dev/null`" = att ; then - echo pyramid-pyramid-sysv3 - else - echo pyramid-pyramid-bsd - fi - exit ;; - NILE*:*:*:dcosx) - echo pyramid-pyramid-svr4 - exit ;; - DRS?6000:unix:4.0:6*) - echo sparc-icl-nx6 - exit ;; - DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7; exit ;; - esac ;; - s390x:SunOS:*:*) - echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - eval $set_cc_for_build - SUN_ARCH="i386" - # If there is a compiler, see if it is configured for 64-bit objects. - # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. - # This test works for both compilers. - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then - if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - SUN_ARCH="x86_64" - fi - fi - echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:6*:*) - # According to config.sub, this is the proper way to canonicalize - # SunOS6. Hard to guess exactly what SunOS6 will be like, but - # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in - Series*|S4*) - UNAME_RELEASE=`uname -v` - ;; - esac - # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit ;; - sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} - exit ;; - sun*:*:4.2BSD:*) - UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 - case "`/bin/arch`" in - sun3) - echo m68k-sun-sunos${UNAME_RELEASE} - ;; - sun4) - echo sparc-sun-sunos${UNAME_RELEASE} - ;; - esac - exit ;; - aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} - exit ;; - # The situation for MiNT is a little confusing. The machine name - # can be virtually everything (everything which is not - # "atarist" or "atariste" at least should have a processor - # > m68000). The system name ranges from "MiNT" over "FreeMiNT" - # to the lowercase version "mint" (or "freemint"). Finally - # the system name "TOS" denotes a system which is actually not - # MiNT. But MiNT is downward compatible to TOS, so this should - # be no problem. - atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} - exit ;; - hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} - exit ;; - *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint${UNAME_RELEASE} - exit ;; - m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} - exit ;; - powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} - exit ;; - RISC*:Mach:*:*) - echo mips-dec-mach_bsd4.3 - exit ;; - RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} - exit ;; - VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} - exit ;; - 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} - exit ;; - mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c -#ifdef __cplusplus -#include /* for printf() prototype */ - int main (int argc, char *argv[]) { -#else - int main (argc, argv) int argc; char *argv[]; { -#endif - #if defined (host_mips) && defined (MIPSEB) - #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); - #endif - #endif - exit (-1); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && - dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`$dummy $dummyarg` && - { echo "$SYSTEM_NAME"; exit; } - echo mips-mips-riscos${UNAME_RELEASE} - exit ;; - Motorola:PowerMAX_OS:*:*) - echo powerpc-motorola-powermax - exit ;; - Motorola:*:4.3:PL8-*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:Power_UNIX:*:*) - echo powerpc-harris-powerunix - exit ;; - m88k:CX/UX:7*:*) - echo m88k-harris-cxux7 - exit ;; - m88k:*:4*:R4*) - echo m88k-motorola-sysv4 - exit ;; - m88k:*:3*:R3*) - echo m88k-motorola-sysv3 - exit ;; - AViiON:dgux:*:*) - # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] - then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] - then - echo m88k-dg-dgux${UNAME_RELEASE} - else - echo m88k-dg-dguxbcs${UNAME_RELEASE} - fi - else - echo i586-dg-dgux${UNAME_RELEASE} - fi - exit ;; - M88*:DolphinOS:*:*) # DolphinOS (SVR3) - echo m88k-dolphin-sysv3 - exit ;; - M88*:*:R3*:*) - # Delta 88k system running SVR3 - echo m88k-motorola-sysv3 - exit ;; - XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) - echo m88k-tektronix-sysv3 - exit ;; - Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) - echo m68k-tektronix-bsd - exit ;; - *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit ;; - ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' - i*86:AIX:*:*) - echo i386-ibm-aix - exit ;; - ia64:AIX:*:*) - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit ;; - *:AIX:2:3) - if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - - main() - { - if (!__power_pc()) - exit(1); - puts("powerpc-ibm-aix3.2.5"); - exit(0); - } -EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` - then - echo "$SYSTEM_NAME" - else - echo rs6000-ibm-aix3.2.5 - fi - elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then - echo rs6000-ibm-aix3.2.4 - else - echo rs6000-ibm-aix3.2 - fi - exit ;; - *:AIX:*:[456]) - IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` - if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then - IBM_ARCH=rs6000 - else - IBM_ARCH=powerpc - fi - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit ;; - *:AIX:*:*) - echo rs6000-ibm-aix - exit ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) - echo romp-ibm-bsd4.4 - exit ;; - ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit ;; # report: romp-ibm BSD 4.3 - *:BOSX:*:*) - echo rs6000-bull-bosx - exit ;; - DPX/2?00:B.O.S.:*:*) - echo m68k-bull-sysv3 - exit ;; - 9000/[34]??:4.3bsd:1.*:*) - echo m68k-hp-bsd - exit ;; - hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) - echo m68k-hp-bsd4.4 - exit ;; - 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - case "${UNAME_MACHINE}" in - 9000/31? ) HP_ARCH=m68000 ;; - 9000/[34]?? ) HP_ARCH=m68k ;; - 9000/[678][0-9][0-9]) - if [ -x /usr/bin/getconf ]; then - sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "${sc_cpu_version}" in - 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 - 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 - 532) # CPU_PA_RISC2_0 - case "${sc_kernel_bits}" in - 32) HP_ARCH="hppa2.0n" ;; - 64) HP_ARCH="hppa2.0w" ;; - '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 - esac ;; - esac - fi - if [ "${HP_ARCH}" = "" ]; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - - #define _HPUX_SOURCE - #include - #include - - int main () - { - #if defined(_SC_KERNEL_BITS) - long bits = sysconf(_SC_KERNEL_BITS); - #endif - long cpu = sysconf (_SC_CPU_VERSION); - - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: - #if defined(_SC_KERNEL_BITS) - switch (bits) - { - case 64: puts ("hppa2.0w"); break; - case 32: puts ("hppa2.0n"); break; - default: puts ("hppa2.0"); break; - } break; - #else /* !defined(_SC_KERNEL_BITS) */ - puts ("hppa2.0"); break; - #endif - default: puts ("hppa1.0"); break; - } - exit (0); - } -EOF - (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` - test -z "$HP_ARCH" && HP_ARCH=hppa - fi ;; - esac - if [ ${HP_ARCH} = "hppa2.0w" ] - then - eval $set_cc_for_build - - # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating - # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler - # generating 64-bit code. GNU and HP use different nomenclature: - # - # $ CC_FOR_BUILD=cc ./config.guess - # => hppa2.0w-hp-hpux11.23 - # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess - # => hppa64-hp-hpux11.23 - - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | - grep __LP64__ >/dev/null - then - HP_ARCH="hppa2.0w" - else - HP_ARCH="hppa64" - fi - fi - echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit ;; - ia64:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - echo ia64-hp-hpux${HPUX_REV} - exit ;; - 3050*:HI-UX:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - int - main () - { - long cpu = sysconf (_SC_CPU_VERSION); - /* The order matters, because CPU_IS_HP_MC68K erroneously returns - true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct - results, however. */ - if (CPU_IS_PA_RISC (cpu)) - { - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; - case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; - default: puts ("hppa-hitachi-hiuxwe2"); break; - } - } - else if (CPU_IS_HP_MC68K (cpu)) - puts ("m68k-hitachi-hiuxwe2"); - else puts ("unknown-hitachi-hiuxwe2"); - exit (0); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - echo unknown-hitachi-hiuxwe2 - exit ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) - echo hppa1.1-hp-bsd - exit ;; - 9000/8??:4.3bsd:*:*) - echo hppa1.0-hp-bsd - exit ;; - *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) - echo hppa1.0-hp-mpeix - exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) - echo hppa1.1-hp-osf - exit ;; - hp8??:OSF1:*:*) - echo hppa1.0-hp-osf - exit ;; - i*86:OSF1:*:*) - if [ -x /usr/sbin/sysversion ] ; then - echo ${UNAME_MACHINE}-unknown-osf1mk - else - echo ${UNAME_MACHINE}-unknown-osf1 - fi - exit ;; - parisc*:Lites*:*:*) - echo hppa1.1-hp-lites - exit ;; - C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) - echo c1-convex-bsd - exit ;; - C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) - echo c34-convex-bsd - exit ;; - C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) - echo c38-convex-bsd - exit ;; - C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) - echo c4-convex-bsd - exit ;; - CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ - | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ - -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ - -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` - echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit ;; - sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:FreeBSD:*:*) - case ${UNAME_MACHINE} in - pc98) - echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - amd64) - echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - *) - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - esac - exit ;; - i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin - exit ;; - *:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 - exit ;; - i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 - exit ;; - i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 - exit ;; - *:Interix*:[3456]*) - case ${UNAME_MACHINE} in - x86) - echo i586-pc-interix${UNAME_RELEASE} - exit ;; - EM64T | authenticamd | genuineintel) - echo x86_64-unknown-interix${UNAME_RELEASE} - exit ;; - IA64) - echo ia64-unknown-interix${UNAME_RELEASE} - exit ;; - esac ;; - [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) - echo i${UNAME_MACHINE}-pc-mks - exit ;; - i*:Windows_NT*:* | Pentium*:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we - # UNAME_MACHINE based on the output of uname instead of i386? - echo i586-pc-interix - exit ;; - i*:UWIN*:*) - echo ${UNAME_MACHINE}-pc-uwin - exit ;; - amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-unknown-cygwin - exit ;; - p*:CYGWIN*:*) - echo powerpcle-unknown-cygwin - exit ;; - prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - *:GNU:*:*) - # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit ;; - *:GNU/*:*:*) - # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu - exit ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix - exit ;; - arm*:Linux:*:*) - eval $set_cc_for_build - if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ARM_EABI__ - then - echo ${UNAME_MACHINE}-unknown-linux-gnu - else - echo ${UNAME_MACHINE}-unknown-linux-gnueabi - fi - exit ;; - avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - cris:Linux:*:*) - echo cris-axis-linux-gnu - exit ;; - crisv32:Linux:*:*) - echo crisv32-axis-linux-gnu - exit ;; - frv:Linux:*:*) - echo frv-unknown-linux-gnu - exit ;; - ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - mips:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips - #undef mipsel - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mipsel - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips - #else - CPU= - #endif - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips64 - #undef mips64el - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mips64el - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips64 - #else - CPU= - #endif - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - or32:Linux:*:*) - echo or32-unknown-linux-gnu - exit ;; - ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu - exit ;; - ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu - exit ;; - alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in - EV5) UNAME_MACHINE=alphaev5 ;; - EV56) UNAME_MACHINE=alphaev56 ;; - PCA56) UNAME_MACHINE=alphapca56 ;; - PCA57) UNAME_MACHINE=alphapca56 ;; - EV6) UNAME_MACHINE=alphaev6 ;; - EV67) UNAME_MACHINE=alphaev67 ;; - EV68*) UNAME_MACHINE=alphaev68 ;; - esac - objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null - if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi - echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit ;; - padre:Linux:*:*) - echo sparc-unknown-linux-gnu - exit ;; - parisc:Linux:*:* | hppa:Linux:*:*) - # Look for CPU level - case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-gnu ;; - PA8*) echo hppa2.0-unknown-linux-gnu ;; - *) echo hppa-unknown-linux-gnu ;; - esac - exit ;; - parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-gnu - exit ;; - s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux - exit ;; - sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sh*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-gnu - exit ;; - x86_64:Linux:*:*) - echo x86_64-unknown-linux-gnu - exit ;; - xtensa*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - i*86:Linux:*:*) - # The BFD linker knows what the default object file format is, so - # first see if it will tell us. cd to the root directory to prevent - # problems with other programs or directories called `ld' in the path. - # Set LC_ALL=C to ensure ld outputs messages in English. - ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ - | sed -ne '/supported targets:/!d - s/[ ][ ]*/ /g - s/.*supported targets: *// - s/ .*// - p'` - case "$ld_supported_targets" in - elf32-i386) - TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" - ;; - a.out-i386-linux) - echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit ;; - "") - # Either a pre-BFD a.out linker (linux-gnuoldld) or - # one that does not give us useful --help. - echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit ;; - esac - # Determine whether the default compiler is a.out or elf - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - #ifdef __ELF__ - # ifdef __GLIBC__ - # if __GLIBC__ >= 2 - LIBC=gnu - # else - LIBC=gnulibc1 - # endif - # else - LIBC=gnulibc1 - # endif - #else - #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) - LIBC=gnu - #else - LIBC=gnuaout - #endif - #endif - #ifdef __dietlibc__ - LIBC=dietlibc - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^LIBC/{ - s: ::g - p - }'`" - test x"${LIBC}" != x && { - echo "${UNAME_MACHINE}-pc-linux-${LIBC}" - exit - } - test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } - ;; - i*86:DYNIX/ptx:4*:*) - # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. - # earlier versions are messed up and put the nodename in both - # sysname and nodename. - echo i386-sequent-sysv4 - exit ;; - i*86:UNIX_SV:4.2MP:2.*) - # Unixware is an offshoot of SVR4, but it has its own version - # number series starting with 2... - # I am not positive that other SVR4 systems won't match this, - # I just have to hope. -- rms. - # Use sysv4.2uw... so that sysv4* matches it. - echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit ;; - i*86:OS/2:*:*) - # If we were able to find `uname', then EMX Unix compatibility - # is probably installed. - echo ${UNAME_MACHINE}-pc-os2-emx - exit ;; - i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-unknown-stop - exit ;; - i*86:atheos:*:*) - echo ${UNAME_MACHINE}-unknown-atheos - exit ;; - i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable - exit ;; - i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) - echo i386-unknown-lynxos${UNAME_RELEASE} - exit ;; - i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` - if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} - else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} - fi - exit ;; - i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. - case `/bin/uname -X | grep "^Machine"` in - *486*) UNAME_MACHINE=i486 ;; - *Pentium) UNAME_MACHINE=i586 ;; - *Pent*|*Celeron) UNAME_MACHINE=i686 ;; - esac - echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit ;; - i*86:*:3.2:*) - if test -f /usr/options/cb.name; then - UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then - UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` - (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 - (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ - && UNAME_MACHINE=i586 - (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ - && UNAME_MACHINE=i686 - (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ - && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL - else - echo ${UNAME_MACHINE}-pc-sysv32 - fi - exit ;; - pc:*:*:*) - # Left here for compatibility: - # uname -m prints for DJGPP always 'pc', but it prints nothing about - # the processor, so we play safe by assuming i586. - # Note: whatever this is, it MUST be the same as what config.sub - # prints for the "djgpp" host, or else GDB configury will decide that - # this is a cross-build. - echo i586-pc-msdosdjgpp - exit ;; - Intel:Mach:3*:*) - echo i386-pc-mach3 - exit ;; - paragon:*:*:*) - echo i860-intel-osf1 - exit ;; - i860:*:4.*:*) # i860-SVR4 - if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 - else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 - fi - exit ;; - mini*:CTIX:SYS*5:*) - # "miniframe" - echo m68010-convergent-sysv - exit ;; - mc68k:UNIX:SYSTEM5:3.51m) - echo m68k-convergent-sysv - exit ;; - M680?0:D-NIX:5.3:*) - echo m68k-diab-dnix - exit ;; - M68*:*:R3V[5678]*:*) - test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; - 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) - OS_REL='' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; - 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; - NCR*:*:4.2:* | MPRAS*:*:4.2:*) - OS_REL='.3' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; - m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos${UNAME_RELEASE} - exit ;; - mc68030:UNIX_System_V:4.*:*) - echo m68k-atari-sysv4 - exit ;; - TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos${UNAME_RELEASE} - exit ;; - rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit ;; - PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) - echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit ;; - SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} - exit ;; - RM*:ReliantUNIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - RM*:SINIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - *:SINIX-*:*:*) - if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 - else - echo ns32k-sni-sysv - fi - exit ;; - PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says - echo i586-unisys-sysv4 - exit ;; - *:UNIX_System_V:4*:FTX*) - # From Gerald Hewes . - # How about differentiating between stratus architectures? -djm - echo hppa1.1-stratus-sysv4 - exit ;; - *:*:*:FTX*) - # From seanf@swdc.stratus.com. - echo i860-stratus-sysv4 - exit ;; - i*86:VOS:*:*) - # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos - exit ;; - *:VOS:*:*) - # From Paul.Green@stratus.com. - echo hppa1.1-stratus-vos - exit ;; - mc68*:A/UX:*:*) - echo m68k-apple-aux${UNAME_RELEASE} - exit ;; - news*:NEWS-OS:6*:*) - echo mips-sony-newsos6 - exit ;; - R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if [ -d /usr/nec ]; then - echo mips-nec-sysv${UNAME_RELEASE} - else - echo mips-unknown-sysv${UNAME_RELEASE} - fi - exit ;; - BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. - echo powerpc-be-beos - exit ;; - BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. - echo powerpc-apple-beos - exit ;; - BePC:BeOS:*:*) # BeOS running on Intel PC compatible. - echo i586-pc-beos - exit ;; - BePC:Haiku:*:*) # Haiku running on Intel PC compatible. - echo i586-pc-haiku - exit ;; - SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} - exit ;; - SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} - exit ;; - SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} - exit ;; - SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} - exit ;; - SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} - exit ;; - SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} - exit ;; - Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - case $UNAME_PROCESSOR in - unknown) UNAME_PROCESSOR=powerpc ;; - esac - echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit ;; - *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = "x86"; then - UNAME_PROCESSOR=i386 - UNAME_MACHINE=pc - fi - echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit ;; - *:QNX:*:4*) - echo i386-pc-qnx - exit ;; - NSE-?:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} - exit ;; - NSR-?:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} - exit ;; - *:NonStop-UX:*:*) - echo mips-compaq-nonstopux - exit ;; - BS2000:POSIX*:*:*) - echo bs2000-siemens-sysv - exit ;; - DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit ;; - *:Plan9:*:*) - # "uname -m" is not consistent, so use $cputype instead. 386 - # is converted to i386 for consistency with other x86 - # operating systems. - if test "$cputype" = "386"; then - UNAME_MACHINE=i386 - else - UNAME_MACHINE="$cputype" - fi - echo ${UNAME_MACHINE}-unknown-plan9 - exit ;; - *:TOPS-10:*:*) - echo pdp10-unknown-tops10 - exit ;; - *:TENEX:*:*) - echo pdp10-unknown-tenex - exit ;; - KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) - echo pdp10-dec-tops20 - exit ;; - XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) - echo pdp10-xkl-tops20 - exit ;; - *:TOPS-20:*:*) - echo pdp10-unknown-tops20 - exit ;; - *:ITS:*:*) - echo pdp10-unknown-its - exit ;; - SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} - exit ;; - *:DragonFly:*:*) - echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` - exit ;; - *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in - A*) echo alpha-dec-vms ; exit ;; - I*) echo ia64-dec-vms ; exit ;; - V*) echo vax-dec-vms ; exit ;; - esac ;; - *:XENIX:*:SysV) - echo i386-pc-xenix - exit ;; - i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' - exit ;; - i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos - exit ;; - i*86:AROS:*:*) - echo ${UNAME_MACHINE}-pc-aros - exit ;; -esac - -#echo '(No uname command or uname output not recognized.)' 1>&2 -#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 - -eval $set_cc_for_build -cat >$dummy.c < -# include -#endif -main () -{ -#if defined (sony) -#if defined (MIPSEB) - /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, - I don't know.... */ - printf ("mips-sony-bsd\n"); exit (0); -#else -#include - printf ("m68k-sony-newsos%s\n", -#ifdef NEWSOS4 - "4" -#else - "" -#endif - ); exit (0); -#endif -#endif - -#if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix\n"); exit (0); -#endif - -#if defined (hp300) && !defined (hpux) - printf ("m68k-hp-bsd\n"); exit (0); -#endif - -#if defined (NeXT) -#if !defined (__ARCHITECTURE__) -#define __ARCHITECTURE__ "m68k" -#endif - int version; - version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - if (version < 4) - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); - else - printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); - exit (0); -#endif - -#if defined (MULTIMAX) || defined (n16) -#if defined (UMAXV) - printf ("ns32k-encore-sysv\n"); exit (0); -#else -#if defined (CMU) - printf ("ns32k-encore-mach\n"); exit (0); -#else - printf ("ns32k-encore-bsd\n"); exit (0); -#endif -#endif -#endif - -#if defined (__386BSD__) - printf ("i386-pc-bsd\n"); exit (0); -#endif - -#if defined (sequent) -#if defined (i386) - printf ("i386-sequent-dynix\n"); exit (0); -#endif -#if defined (ns32000) - printf ("ns32k-sequent-dynix\n"); exit (0); -#endif -#endif - -#if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); - -#endif - -#if defined (vax) -# if !defined (ultrix) -# include -# if defined (BSD) -# if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -# else -# if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# endif -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# else - printf ("vax-dec-ultrix\n"); exit (0); -# endif -#endif - -#if defined (alliant) && defined (i860) - printf ("i860-alliant-bsd\n"); exit (0); -#endif - - exit (1); -} -EOF - -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - -# Apollos put the system type in the environment. - -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } - -# Convex versions that predate uname can use getsysinfo(1) - -if [ -x /usr/convex/getsysinfo ] -then - case `getsysinfo -f cpu_type` in - c1*) - echo c1-convex-bsd - exit ;; - c2*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - c34*) - echo c34-convex-bsd - exit ;; - c38*) - echo c38-convex-bsd - exit ;; - c4*) - echo c4-convex-bsd - exit ;; - esac -fi - -cat >&2 < in order to provide the needed -information to handle your system. - -config.guess timestamp = $timestamp - -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null` - -hostinfo = `(hostinfo) 2>/dev/null` -/bin/universe = `(/bin/universe) 2>/dev/null` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` -/bin/arch = `(/bin/arch) 2>/dev/null` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` - -UNAME_MACHINE = ${UNAME_MACHINE} -UNAME_RELEASE = ${UNAME_RELEASE} -UNAME_SYSTEM = ${UNAME_SYSTEM} -UNAME_VERSION = ${UNAME_VERSION} -EOF - -exit 1 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/bundled/replace/config.h.in b/bundled/replace/config.h.in deleted file mode 100644 index 00ad4b12..00000000 --- a/bundled/replace/config.h.in +++ /dev/null @@ -1,965 +0,0 @@ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Define if building universal (internal helper macro) */ -#undef AC_APPLE_UNIVERSAL_BUILD - -/* Broken RedHat 7.2 system header files */ -#undef BROKEN_REDHAT_7_SYSTEM_HEADERS - -/* Broken RHEL5 sys/capability.h */ -#undef BROKEN_RHEL5_SYS_CAP_HEADER - -/* Whether strndup is broken */ -#undef BROKEN_STRNDUP - -/* Whether strnlen is broken */ -#undef BROKEN_STRNLEN - -/* Whether dlopen takes unsigned int flags */ -#undef DLOPEN_TAKES_UNSIGNED_FLAGS - -/* Define to 1 if you have the header file. */ -#undef HAVE_ACL_LIBACL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_ARPA_INET_H - -/* Define to 1 if you have the `asprintf' function. */ -#undef HAVE_ASPRINTF - -/* Whether the bool type is available */ -#undef HAVE_BOOL - -/* Define to 1 if you have the `bzero' function. */ -#undef HAVE_BZERO - -/* Whether there is a C99 compliant vsnprintf */ -#undef HAVE_C99_VSNPRINTF - -/* Define to 1 if you have the `chown' function. */ -#undef HAVE_CHOWN - -/* Define to 1 if you have the `chroot' function. */ -#undef HAVE_CHROOT - -/* Define to 1 if you have the `chsize' function. */ -#undef HAVE_CHSIZE - -/* Whether or not we have comparison_fn_t */ -#undef HAVE_COMPARISON_FN_T - -/* Define to 1 if you have the header file. */ -#undef HAVE_COMPAT_H - -/* Whether the system has connect() */ -#undef HAVE_CONNECT - -/* Whether the system has the crypt() function */ -#undef HAVE_CRYPT - -/* Define to 1 if you have the header file. */ -#undef HAVE_CRYPT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_CTYPE_H - -/* Define to 1 if you have the declaration of `asprintf', and to 0 if you - don't. */ -#undef HAVE_DECL_ASPRINTF - -/* Define to 1 if you have the declaration of `snprintf', and to 0 if you - don't. */ -#undef HAVE_DECL_SNPRINTF - -/* Define to 1 if you have the declaration of `vasprintf', and to 0 if you - don't. */ -#undef HAVE_DECL_VASPRINTF - -/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you - don't. */ -#undef HAVE_DECL_VSNPRINTF - -/* Define to 1 if you have the header file. */ -#undef HAVE_DIRECT_H - -/* Define to 1 if you have the header file, and it defines `DIR'. - */ -#undef HAVE_DIRENT_H - -/* Define to 1 if you have the `dirfd' function. */ -#undef HAVE_DIRFD - -/* Whether dirfd() is available */ -#undef HAVE_DIRFD_DECL - -/* Define to 1 if you have the `dlclose' function. */ -#undef HAVE_DLCLOSE - -/* Define to 1 if you have the `dlerror' function. */ -#undef HAVE_DLERROR - -/* Define to 1 if you have the header file. */ -#undef HAVE_DLFCN_H - -/* Define to 1 if you have the `dlopen' function. */ -#undef HAVE_DLOPEN - -/* Define to 1 if you have the `dlsym' function. */ -#undef HAVE_DLSYM - -/* Define to 1 if you have the header file. */ -#undef HAVE_DL_H - -/* Define to 1 if you have the `dprintf' function. */ -#undef HAVE_DPRINTF - -/* Define to 1 if you have the `dup2' function. */ -#undef HAVE_DUP2 - -/* Whether environ() is available */ -#undef HAVE_ENVIRON_DECL - -/* Whether errno() is available */ -#undef HAVE_ERRNO_DECL - -/* Define to 1 if you have the header file. */ -#undef HAVE_FCNTL_H - -/* Define to 1 if there is support for fdatasync */ -#undef HAVE_FDATASYNC - -/* Define to 1 if you have the header file. */ -#undef HAVE_FNMATCH_H - -/* Whether the system has freeaddrinfo */ -#undef HAVE_FREEADDRINFO - -/* Whether the system has freeifaddrs */ -#undef HAVE_FREEIFADDRS - -/* Define to 1 if you have the `ftruncate' function. */ -#undef HAVE_FTRUNCATE - -/* Whether there is a __FUNCTION__ macro */ -#undef HAVE_FUNCTION_MACRO - -/* Whether the system has gai_strerror */ -#undef HAVE_GAI_STRERROR - -/* Whether the system has getaddrinfo */ -#undef HAVE_GETADDRINFO - -/* Define to 1 if you have the `getdents' function. */ -#undef HAVE_GETDENTS - -/* Define to 1 if you have the `getdirentries' function. */ -#undef HAVE_GETDIRENTRIES - -/* Define to 1 if you have the `getgrent_r' function. */ -#undef HAVE_GETGRENT_R - -/* Whether getgrent_r() is available */ -#undef HAVE_GETGRENT_R_DECL - -/* Define to 1 if you have the `getgrgid_r' function. */ -#undef HAVE_GETGRGID_R - -/* Define to 1 if you have the `getgrnam_r' function. */ -#undef HAVE_GETGRNAM_R - -/* Define to 1 if you have the `getgrouplist' function. */ -#undef HAVE_GETGROUPLIST - -/* Whether the system has gethostbyname() */ -#undef HAVE_GETHOSTBYNAME - -/* Whether the system has getifaddrs */ -#undef HAVE_GETIFADDRS - -/* Whether the system has getnameinfo */ -#undef HAVE_GETNAMEINFO - -/* Define to 1 if you have the `getpgrp' function. */ -#undef HAVE_GETPGRP - -/* Define to 1 if you have the `getpwent_r' function. */ -#undef HAVE_GETPWENT_R - -/* Whether getpwent_r() is available */ -#undef HAVE_GETPWENT_R_DECL - -/* Define to 1 if you have the `getpwnam_r' function. */ -#undef HAVE_GETPWNAM_R - -/* Define to 1 if you have the `getpwuid_r' function. */ -#undef HAVE_GETPWUID_R - -/* Define to 1 if you have the `get_current_dir_name' function. */ -#undef HAVE_GET_CURRENT_DIR_NAME - -/* Define to 1 if you have the header file. */ -#undef HAVE_GRP_H - -/* Whether iface AIX is available */ -#undef HAVE_IFACE_AIX - -/* Whether iface getifaddrs is available */ -#undef HAVE_IFACE_GETIFADDRS - -/* Whether iface ifconf is available */ -#undef HAVE_IFACE_IFCONF - -/* Whether iface ifreq is available */ -#undef HAVE_IFACE_IFREQ - -/* Define to 1 if you have the header file. */ -#undef HAVE_IFADDRS_H - -/* Whether the system has if_nametoindex() */ -#undef HAVE_IF_NAMETOINDEX - -/* Whether the compiler supports immediate structures */ -#undef HAVE_IMMEDIATE_STRUCTURES - -/* Define to 1 if you have the `inet_aton' function. */ -#undef HAVE_INET_ATON - -/* Define to 1 if you have the `inet_ntoa' function. */ -#undef HAVE_INET_NTOA - -/* Define to 1 if you have the `inet_ntop' function. */ -#undef HAVE_INET_NTOP - -/* Define to 1 if you have the `inet_pton' function. */ -#undef HAVE_INET_PTON - -/* Define to 1 if you have the `initgroups' function. */ -#undef HAVE_INITGROUPS - -/* Define to 1 if the system has the type `intptr_t'. */ -#undef HAVE_INTPTR_T - -/* Define to 1 if you have the header file. */ -#undef HAVE_INTTYPES_H - -/* Whether the system has IPv6 support */ -#undef HAVE_IPV6 - -/* Define to 1 if you have the `isatty' function. */ -#undef HAVE_ISATTY - -/* Define to 1 if you have the header file. */ -#undef HAVE_LANGINFO_H - -/* Define to 1 if you have the `lchown' function. */ -#undef HAVE_LCHOWN - -/* Define to 1 if you have the `inet' library (-linet). */ -#undef HAVE_LIBINET - -/* Define to 1 if you have the `ipv6' library (-lipv6). */ -#undef HAVE_LIBIPV6 - -/* Define to 1 if you have the `nsl' library (-lnsl). */ -#undef HAVE_LIBNSL - -/* Define to 1 if you have the `nsl_s' library (-lnsl_s). */ -#undef HAVE_LIBNSL_S - -/* Define to 1 if you have the `socket' library (-lsocket). */ -#undef HAVE_LIBSOCKET - -/* Define to 1 if you have the header file. */ -#undef HAVE_LIMITS_H - -/* Define to 1 if you have the `link' function. */ -#undef HAVE_LINK - -/* Whether the system has IPV6_V6ONLY in linux/in6.h */ -#undef HAVE_LINUX_IPV6_V6ONLY_26 - -/* Define to 1 if you have the header file. */ -#undef HAVE_LOCALE_H - -/* Define to 1 if the system has the type `long long'. */ -#undef HAVE_LONG_LONG - -/* Define to 1 if you have the `lstat' function. */ -#undef HAVE_LSTAT - -/* Define to 1 if you have the `memcpy' function. */ -#undef HAVE_MEMCPY - -/* Define to 1 if you have the `memmem' function. */ -#undef HAVE_MEMMEM - -/* Define to 1 if you have the `memmove' function. */ -#undef HAVE_MEMMOVE - -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - -/* Define to 1 if you have the `memset' function. */ -#undef HAVE_MEMSET - -/* Define if target mkdir supports mode option */ -#undef HAVE_MKDIR_MODE - -/* Define to 1 if you have the `mkdtemp' function. */ -#undef HAVE_MKDTEMP - -/* Define to 1 if you have the `mktime' function. */ -#undef HAVE_MKTIME - -/* Whether mmap works */ -#undef HAVE_MMAP - -/* Define to 1 if you have the header file. */ -#undef HAVE_MNTENT_H - -/* Define to 1 if you have the header file, and it defines `DIR'. */ -#undef HAVE_NDIR_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_NETDB_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_NETINET_IN_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_NETINET_IN_IP_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_NETINET_IN_SYSTM_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_NETINET_IP_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_NETINET_TCP_H - -/* usability of net/if.h */ -#undef HAVE_NET_IF_H - -/* Whether the open(2) accepts O_DIRECT */ -#undef HAVE_OPEN_O_DIRECT - -/* Define to 1 if you have the `pipe' function. */ -#undef HAVE_PIPE - -/* Define to 1 if you have the `pread' function. */ -#undef HAVE_PREAD - -/* Define to 1 if you have the `printf' function. */ -#undef HAVE_PRINTF - -/* Define to 1 if the system has the type `ptrdiff_t'. */ -#undef HAVE_PTRDIFF_T - -/* Define to 1 if you have the header file. */ -#undef HAVE_PWD_H - -/* Define to 1 if you have the `pwrite' function. */ -#undef HAVE_PWRITE - -/* Define to 1 if you have the `rand' function. */ -#undef HAVE_RAND - -/* Define to 1 if you have the `random' function. */ -#undef HAVE_RANDOM - -/* Define to 1 if you have the `readlink' function. */ -#undef HAVE_READLINK - -/* Define to 1 if you have the `realpath' function. */ -#undef HAVE_REALPATH - -/* Define to 1 if you have the `rename' function. */ -#undef HAVE_RENAME - -/* Define to 1 if the system has the type `sa_family_t'. */ -#undef HAVE_SA_FAMILY_T - -/* Whether mkstemp is secure */ -#undef HAVE_SECURE_MKSTEMP - -/* Define to 1 if you have the `setbuffer' function. */ -#undef HAVE_SETBUFFER - -/* Define to 1 if you have the `setegid' function. */ -#undef HAVE_SETEGID - -/* Define to 1 if you have the `setenv' function. */ -#undef HAVE_SETENV - -/* Whether setenv() is available */ -#undef HAVE_SETENV_DECL - -/* Define to 1 if you have the `seteuid' function. */ -#undef HAVE_SETEUID - -/* Define to 1 if you have the header file. */ -#undef HAVE_SETJMP_H - -/* Define to 1 if you have the `setlinebuf' function. */ -#undef HAVE_SETLINEBUF - -/* Define to 1 if you have the `setresgid' function. */ -#undef HAVE_SETRESGID - -/* Whether setresgid() is available */ -#undef HAVE_SETRESGID_DECL - -/* Define to 1 if you have the `setresuid' function. */ -#undef HAVE_SETRESUID - -/* Whether setresuid() is available */ -#undef HAVE_SETRESUID_DECL - -/* Define to 1 if you have the header file. */ -#undef HAVE_SHADOW_H - -/* Define to 1 if you have the `shl_findsym' function. */ -#undef HAVE_SHL_FINDSYM - -/* Define to 1 if you have the `shl_load' function. */ -#undef HAVE_SHL_LOAD - -/* Define to 1 if you have the `shl_unload' function. */ -#undef HAVE_SHL_UNLOAD - -/* Whether we have the atomic_t variable type */ -#undef HAVE_SIG_ATOMIC_T_TYPE - -/* Define to 1 if you have the `snprintf' function. */ -#undef HAVE_SNPRINTF - -/* Whether struct sockaddr has a sa_len member */ -#undef HAVE_SOCKADDR_SA_LEN - -/* Define to 1 if you have the `socketpair' function. */ -#undef HAVE_SOCKETPAIR - -/* Define to 1 if the system has the type `socklen_t'. */ -#undef HAVE_SOCKLEN_T - -/* Whether the sockaddr_in struct has a sin_len property */ -#undef HAVE_SOCK_SIN_LEN - -/* Define to 1 if you have the `srand' function. */ -#undef HAVE_SRAND - -/* Define to 1 if you have the `srandom' function. */ -#undef HAVE_SRANDOM - -/* Defined if struct sockaddr_storage has ss_family field */ -#undef HAVE_SS_FAMILY - -/* Define to 1 if you have the header file. */ -#undef HAVE_STANDARDS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDARG_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDBOOL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDINT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDIO_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STDLIB_H - -/* Define to 1 if you have the `strcasestr' function. */ -#undef HAVE_STRCASESTR - -/* Define to 1 if you have the `strdup' function. */ -#undef HAVE_STRDUP - -/* Define to 1 if you have the `strerror' function. */ -#undef HAVE_STRERROR - -/* Define to 1 if you have the `strerror_r' function. */ -#undef HAVE_STRERROR_R - -/* Define to 1 if you have the `strftime' function. */ -#undef HAVE_STRFTIME - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRINGS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_STRING_H - -/* Define to 1 if you have the `strlcat' function. */ -#undef HAVE_STRLCAT - -/* Define to 1 if you have the `strlcpy' function. */ -#undef HAVE_STRLCPY - -/* Define to 1 if you have the `strndup' function. */ -#undef HAVE_STRNDUP - -/* Define to 1 if you have the `strnlen' function. */ -#undef HAVE_STRNLEN - -/* Define to 1 if you have the header file. */ -#undef HAVE_STROPTS_H - -/* Define to 1 if you have the `strtok_r' function. */ -#undef HAVE_STRTOK_R - -/* Define to 1 if you have the `strtoll' function. */ -#undef HAVE_STRTOLL - -/* Define to 1 if you have the `strtoq' function. */ -#undef HAVE_STRTOQ - -/* Define to 1 if you have the `strtoull' function. */ -#undef HAVE_STRTOULL - -/* Define to 1 if you have the `strtouq' function. */ -#undef HAVE_STRTOUQ - -/* Define to 1 if the system has the type `struct addrinfo'. */ -#undef HAVE_STRUCT_ADDRINFO - -/* Whether struct ifaddrs is available */ -#undef HAVE_STRUCT_IFADDRS - -/* Define to 1 if the system has the type `struct sockaddr'. */ -#undef HAVE_STRUCT_SOCKADDR - -/* Define to 1 if the system has the type `struct sockaddr_in6'. */ -#undef HAVE_STRUCT_SOCKADDR_IN6 - -/* Define to 1 if `sa_len' is member of `struct sockaddr'. */ -#undef HAVE_STRUCT_SOCKADDR_SA_LEN - -/* Define to 1 if the system has the type `struct sockaddr_storage'. */ -#undef HAVE_STRUCT_SOCKADDR_STORAGE - -/* Define to 1 if `st_rdev' is member of `struct stat'. */ -#undef HAVE_STRUCT_STAT_ST_RDEV - -/* Define to 1 if your `struct stat' has `st_rdev'. Deprecated, use - `HAVE_STRUCT_STAT_ST_RDEV' instead. */ -#undef HAVE_ST_RDEV - -/* Define to 1 if you have the `symlink' function. */ -#undef HAVE_SYMLINK - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYSLOG_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_ACL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_CAPABILITY_H - -/* Define to 1 if you have the header file, and it defines `DIR'. - */ -#undef HAVE_SYS_DIR_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_FCNTL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_FILE_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_FILIO_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_FILSYS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_FS_S5PARAM_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_ID_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_IOCTL_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_IPC_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_MMAN_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_MODE_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_MOUNT_H - -/* Define to 1 if you have the header file, and it defines `DIR'. - */ -#undef HAVE_SYS_NDIR_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_PARAM_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_PRIV_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_RESOURCE_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_SECURITY_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_SELECT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_SHM_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_SOCKET_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_SOCKIO_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_SYSLOG_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TERMIO_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TIME_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_TYPES_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_UIO_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_SYS_UN_H - -/* Define to 1 if you have that is POSIX.1 compatible. */ -#undef HAVE_SYS_WAIT_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_TERMIOS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_TERMIO_H - -/* Define to 1 if you have the `timegm' function. */ -#undef HAVE_TIMEGM - -/* Define to 1 if you have the header file. */ -#undef HAVE_TIME_H - -/* Define to 1 if the system has the type `uintptr_t'. */ -#undef HAVE_UINTPTR_T - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNISTD_H - -/* If we need to build with unixscoket support */ -#undef HAVE_UNIXSOCKET - -/* Define to 1 if you have the header file. */ -#undef HAVE_UNIX_H - -/* Define to 1 if you have the `unsetenv' function. */ -#undef HAVE_UNSETENV - -/* Define to 1 if you have the `usleep' function. */ -#undef HAVE_USLEEP - -/* Define to 1 if you have the `utime' function. */ -#undef HAVE_UTIME - -/* Define to 1 if you have the `utimes' function. */ -#undef HAVE_UTIMES - -/* Define to 1 if you have the header file. */ -#undef HAVE_UTIME_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_VARARG_H - -/* Define to 1 if you have the `vasprintf' function. */ -#undef HAVE_VASPRINTF - -/* Whether va_copy() is available */ -#undef HAVE_VA_COPY - -/* Define to 1 if you have the `vdprintf' function. */ -#undef HAVE_VDPRINTF - -/* Whether the C compiler understands volatile */ -#undef HAVE_VOLATILE - -/* Define to 1 if you have the `vsnprintf' function. */ -#undef HAVE_VSNPRINTF - -/* Define to 1 if you have the `vsyslog' function. */ -#undef HAVE_VSYSLOG - -/* Define to 1 if you have the `wait4' function. */ -#undef HAVE_WAIT4 - -/* Define to 1 if you have the `waitpid' function. */ -#undef HAVE_WAITPID - -/* Define to 1 if you have the header file. */ -#undef HAVE_WINDOWS_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_WINSOCK2_H - -/* Define to 1 if you have the header file. */ -#undef HAVE_WS2TCPIP_H - -/* Whether the _Bool type is available */ -#undef HAVE__Bool - -/* Whether the __VA_ARGS__ macro is available */ -#undef HAVE__VA_ARGS__MACRO - -/* Defined if struct sockaddr_storage has __ss_family field */ -#undef HAVE___SS_FAMILY - -/* Define to 1 if you have the `__strtoll' function. */ -#undef HAVE___STRTOLL - -/* Define to 1 if you have the `__strtoull' function. */ -#undef HAVE___STRTOULL - -/* Whether __va_copy() is available */ -#undef HAVE___VA_COPY - -/* Whether there is a __func__ macro */ -#undef HAVE_func_MACRO - -/* LIBREPLACE_NETWORK_CHECKS were used */ -#undef LIBREPLACE_NETWORK_CHECKS - -/* Whether MMAP is broken */ -#undef MMAP_BLACKLIST - -/* Define to the address where bug reports for this package should be sent. */ -#undef PACKAGE_BUGREPORT - -/* Define to the full name of this package. */ -#undef PACKAGE_NAME - -/* Define to the full name and version of this package. */ -#undef PACKAGE_STRING - -/* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME - -/* Define to the version of this package. */ -#undef PACKAGE_VERSION - -/* Whether getpass should be replaced */ -#undef REPLACE_GETPASS - -/* getpass returns <9 chars where getpassphrase returns <265 chars */ -#undef REPLACE_GETPASS_BY_GETPASSPHRASE - -/* Whether inet_ntoa should be replaced */ -#undef REPLACE_INET_NTOA - -/* replace readdir */ -#undef REPLACE_READDIR - -/* replace readdir using getdents() */ -#undef REPLACE_READDIR_GETDENTS - -/* replace readdir using getdirentries() */ -#undef REPLACE_READDIR_GETDIRENTRIES - -/* Whether strptime should be replaced */ -#undef REPLACE_STRPTIME - -/* Whether seekdir returns an int */ -#undef SEEKDIR_RETURNS_INT - -/* The size of `char', as computed by sizeof. */ -#undef SIZEOF_CHAR - -/* The size of `int', as computed by sizeof. */ -#undef SIZEOF_INT - -/* The size of `long', as computed by sizeof. */ -#undef SIZEOF_LONG - -/* The size of `long long', as computed by sizeof. */ -#undef SIZEOF_LONG_LONG - -/* The size of `off_t', as computed by sizeof. */ -#undef SIZEOF_OFF_T - -/* The size of `short', as computed by sizeof. */ -#undef SIZEOF_SHORT - -/* The size of `size_t', as computed by sizeof. */ -#undef SIZEOF_SIZE_T - -/* The size of `ssize_t', as computed by sizeof. */ -#undef SIZEOF_SSIZE_T - -/* getgrent_r irix (similar to solaris) function prototype */ -#undef SOLARIS_GETGRENT_R - -/* getpwent_r irix (similar to solaris) function prototype */ -#undef SOLARIS_GETPWENT_R - -/* Define to 1 if you have the ANSI C header files. */ -#undef STDC_HEADERS - -/* Whether telldir takes a const pointer */ -#undef TELLDIR_TAKES_CONST_DIR - -/* Define to 1 if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# undef _ALL_SOURCE -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# undef _GNU_SOURCE -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# undef _POSIX_PTHREAD_SEMANTICS -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# undef _TANDEM_SOURCE -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# undef __EXTENSIONS__ -#endif - - -/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most - significant byte first (like Motorola and SPARC, unlike Intel). */ -#if defined AC_APPLE_UNIVERSAL_BUILD -# if defined __BIG_ENDIAN__ -# define WORDS_BIGENDIAN 1 -# endif -#else -# ifndef WORDS_BIGENDIAN -# undef WORDS_BIGENDIAN -# endif -#endif - -/* Number of bits in a file offset, on hosts where this is settable. */ -#undef _FILE_OFFSET_BITS - -/* Define for large files, on AIX-style hosts. */ -#undef _LARGE_FILES - -/* Define to 1 if on MINIX. */ -#undef _MINIX - - -#ifndef _OSF_SOURCE -# undef _OSF_SOURCE -#endif - - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -#undef _POSIX_1_SOURCE - -/* Whether to enable POSIX support */ -#undef _POSIX_C_SOURCE - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -#undef _POSIX_SOURCE - -/* Whether to enable System V compatibility */ -#undef _SYSV - - -#ifndef _XOPEN_SOURCE -# undef _XOPEN_SOURCE -#endif - - - -#ifndef _XOPEN_SOURCE_EXTENDED -# undef _XOPEN_SOURCE_EXTENDED -#endif - - -/* Define to `int' if doesn't define. */ -#undef gid_t - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -#undef inline -#endif - -/* Define to `unsigned' if does not define. */ -#undef ino_t - -/* Define to `short' if does not define. */ -#undef int16_t - -/* Define to `long' if does not define. */ -#undef int32_t - -/* Define to `long long' if does not define. */ -#undef int64_t - -/* Define to `char' if does not define. */ -#undef int8_t - -/* Define to `off_t' if does not define. */ -#undef loff_t - -/* Define to `int' if does not define. */ -#undef mode_t - -/* Define to `long int' if does not define. */ -#undef off_t - -/* Define to `loff_t' if does not define. */ -#undef offset_t - -/* Define to `int' if does not define. */ -#undef pid_t - -/* Define to `unsigned int' if does not define. */ -#undef size_t - -/* Define to `int' if does not define. */ -#undef ssize_t - -/* Define to `int' if doesn't define. */ -#undef uid_t - -/* Define to `unsigned short' if does not define. */ -#undef uint16_t - -/* Define to `unsigned long' if does not define. */ -#undef uint32_t - -/* Define to `unsigned long long' if does not define. */ -#undef uint64_t - -/* Define to `unsigned char' if does not define. */ -#undef uint8_t diff --git a/bundled/replace/config.sub b/bundled/replace/config.sub deleted file mode 100755 index a39437d0..00000000 --- a/bundled/replace/config.sub +++ /dev/null @@ -1,1686 +0,0 @@ -#! /bin/sh -# Configuration validation subroutine script. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 -# Free Software Foundation, Inc. - -timestamp='2009-04-17' - -# This file is (in principle) common to ALL GNU software. -# The presence of a machine in this file suggests that SOME GNU software -# can handle that machine. It does not imply ALL GNU software can. -# -# This file is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. -# -# Configuration subroutine to validate and canonicalize a configuration type. -# Supply the specified configuration type as an argument. -# If it is invalid, we print an error message on stderr and exit with code 1. -# Otherwise, we print the canonical config type on stdout and succeed. - -# This file is supposed to be the same for all GNU packages -# and recognize all the CPU types, system types and aliases -# that are meaningful with *any* GNU software. -# Each package is responsible for reporting which valid configurations -# it does not support. The user should be able to distinguish -# a failure to support a valid configuration from a meaningless -# configuration. - -# The goal of this file is to map all the various variations of a given -# machine specification into a single specification in the form: -# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM -# or in some cases, the newer four-part form: -# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM -# It is wrong to echo any other type of specification. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] CPU-MFR-OPSYS - $0 [OPTION] ALIAS - -Canonicalize a configuration name. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.sub ($timestamp) - -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" - exit 1 ;; - - *local*) - # First pass through any local machine types. - echo $1 - exit ;; - - * ) - break ;; - esac -done - -case $# in - 0) echo "$me: missing argument$help" >&2 - exit 1;; - 1) ;; - *) echo "$me: too many arguments$help" >&2 - exit 1;; -esac - -# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). -# Here we must recognize all the valid KERNEL-OS combinations. -maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` -case $maybe_os in - nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ - uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ - kopensolaris*-gnu* | \ - storm-chaos* | os2-emx* | rtmk-nova*) - os=-$maybe_os - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` - ;; - *) - basic_machine=`echo $1 | sed 's/-[^-]*$//'` - if [ $basic_machine != $1 ] - then os=`echo $1 | sed 's/.*-/-/'` - else os=; fi - ;; -esac - -### Let's recognize common machines as not being operating systems so -### that things like config.sub decstation-3100 work. We also -### recognize some manufacturers as not being operating systems, so we -### can provide default operating systems below. -case $os in - -sun*os*) - # Prevent following clause from handling this invalid input. - ;; - -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ - -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ - -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ - -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ - -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ - -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis | -knuth | -cray) - os= - basic_machine=$1 - ;; - -sim | -cisco | -oki | -wec | -winbond) - os= - basic_machine=$1 - ;; - -scout) - ;; - -wrs) - os=-vxworks - basic_machine=$1 - ;; - -chorusos*) - os=-chorusos - basic_machine=$1 - ;; - -chorusrdb) - os=-chorusrdb - basic_machine=$1 - ;; - -hiux*) - os=-hiuxwe2 - ;; - -sco6) - os=-sco5v6 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco5) - os=-sco3.2v5 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco4) - os=-sco3.2v4 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2.[4-9]*) - os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2v[4-9]*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco5v6*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco*) - os=-sco3.2v2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -udk*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -isc) - os=-isc2.2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -clix*) - basic_machine=clipper-intergraph - ;; - -isc*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -lynx*) - os=-lynxos - ;; - -ptx*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` - ;; - -windowsnt*) - os=`echo $os | sed -e 's/windowsnt/winnt/'` - ;; - -psos*) - os=-psos - ;; - -mint | -mint[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; -esac - -# Decode aliases for certain CPU-COMPANY combinations. -case $basic_machine in - # Recognize the basic CPU types without company name. - # Some are omitted here because they have special meanings below. - 1750a | 580 \ - | a29k \ - | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ - | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | am33_2.0 \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ - | bfin \ - | c4x | clipper \ - | d10v | d30v | dlx | dsp16xx \ - | fido | fr30 | frv \ - | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ - | i370 | i860 | i960 | ia64 \ - | ip2k | iq2000 \ - | lm32 \ - | m32c | m32r | m32rle | m68000 | m68k | m88k \ - | maxq | mb | microblaze | mcore | mep | metag \ - | mips | mipsbe | mipseb | mipsel | mipsle \ - | mips16 \ - | mips64 | mips64el \ - | mips64octeon | mips64octeonel \ - | mips64orion | mips64orionel \ - | mips64r5900 | mips64r5900el \ - | mips64vr | mips64vrel \ - | mips64vr4100 | mips64vr4100el \ - | mips64vr4300 | mips64vr4300el \ - | mips64vr5000 | mips64vr5000el \ - | mips64vr5900 | mips64vr5900el \ - | mipsisa32 | mipsisa32el \ - | mipsisa32r2 | mipsisa32r2el \ - | mipsisa64 | mipsisa64el \ - | mipsisa64r2 | mipsisa64r2el \ - | mipsisa64sb1 | mipsisa64sb1el \ - | mipsisa64sr71k | mipsisa64sr71kel \ - | mipstx39 | mipstx39el \ - | mn10200 | mn10300 \ - | moxie \ - | mt \ - | msp430 \ - | nios | nios2 \ - | ns16k | ns32k \ - | or32 \ - | pdp10 | pdp11 | pj | pjl \ - | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ - | pyramid \ - | score \ - | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ - | sh64 | sh64le \ - | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ - | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ - | spu | strongarm \ - | tahoe | thumb | tic4x | tic80 | tron \ - | v850 | v850e \ - | we32k \ - | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ - | z8k | z80) - basic_machine=$basic_machine-unknown - ;; - m6811 | m68hc11 | m6812 | m68hc12) - # Motorola 68HC11/12. - basic_machine=$basic_machine-unknown - os=-none - ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) - ;; - ms1) - basic_machine=mt-unknown - ;; - - # We use `pc' rather than `unknown' - # because (1) that's what they normally are, and - # (2) the word "unknown" tends to confuse beginning users. - i*86 | x86_64) - basic_machine=$basic_machine-pc - ;; - # Object if more than one company name word. - *-*-*) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; - # Recognize the basic CPU types with company name. - 580-* \ - | a29k-* \ - | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ - | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ - | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* | avr32-* \ - | bfin-* | bs2000-* \ - | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ - | clipper-* | craynv-* | cydra-* \ - | d10v-* | d30v-* | dlx-* \ - | elxsi-* \ - | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ - | h8300-* | h8500-* \ - | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ - | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* | iq2000-* \ - | lm32-* \ - | m32c-* | m32r-* | m32rle-* \ - | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ - | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ - | mips16-* \ - | mips64-* | mips64el-* \ - | mips64octeon-* | mips64octeonel-* \ - | mips64orion-* | mips64orionel-* \ - | mips64r5900-* | mips64r5900el-* \ - | mips64vr-* | mips64vrel-* \ - | mips64vr4100-* | mips64vr4100el-* \ - | mips64vr4300-* | mips64vr4300el-* \ - | mips64vr5000-* | mips64vr5000el-* \ - | mips64vr5900-* | mips64vr5900el-* \ - | mipsisa32-* | mipsisa32el-* \ - | mipsisa32r2-* | mipsisa32r2el-* \ - | mipsisa64-* | mipsisa64el-* \ - | mipsisa64r2-* | mipsisa64r2el-* \ - | mipsisa64sb1-* | mipsisa64sb1el-* \ - | mipsisa64sr71k-* | mipsisa64sr71kel-* \ - | mipstx39-* | mipstx39el-* \ - | mmix-* \ - | mt-* \ - | msp430-* \ - | nios-* | nios2-* \ - | none-* | np1-* | ns16k-* | ns32k-* \ - | orion-* \ - | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ - | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ - | pyramid-* \ - | romp-* | rs6000-* \ - | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ - | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ - | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ - | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ - | tahoe-* | thumb-* \ - | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* | tile-* \ - | tron-* \ - | v850-* | v850e-* | vax-* \ - | we32k-* \ - | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ - | xstormy16-* | xtensa*-* \ - | ymp-* \ - | z8k-* | z80-*) - ;; - # Recognize the basic CPU types without company name, with glob match. - xtensa*) - basic_machine=$basic_machine-unknown - ;; - # Recognize the various machine names and aliases which stand - # for a CPU type and a company and sometimes even an OS. - 386bsd) - basic_machine=i386-unknown - os=-bsd - ;; - 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) - basic_machine=m68000-att - ;; - 3b*) - basic_machine=we32k-att - ;; - a29khif) - basic_machine=a29k-amd - os=-udi - ;; - abacus) - basic_machine=abacus-unknown - ;; - adobe68k) - basic_machine=m68010-adobe - os=-scout - ;; - alliant | fx80) - basic_machine=fx80-alliant - ;; - altos | altos3068) - basic_machine=m68k-altos - ;; - am29k) - basic_machine=a29k-none - os=-bsd - ;; - amd64) - basic_machine=x86_64-pc - ;; - amd64-*) - basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - amdahl) - basic_machine=580-amdahl - os=-sysv - ;; - amiga | amiga-*) - basic_machine=m68k-unknown - ;; - amigaos | amigados) - basic_machine=m68k-unknown - os=-amigaos - ;; - amigaunix | amix) - basic_machine=m68k-unknown - os=-sysv4 - ;; - apollo68) - basic_machine=m68k-apollo - os=-sysv - ;; - apollo68bsd) - basic_machine=m68k-apollo - os=-bsd - ;; - aros) - basic_machine=i386-pc - os=-aros - ;; - aux) - basic_machine=m68k-apple - os=-aux - ;; - balance) - basic_machine=ns32k-sequent - os=-dynix - ;; - blackfin) - basic_machine=bfin-unknown - os=-linux - ;; - blackfin-*) - basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux - ;; - c90) - basic_machine=c90-cray - os=-unicos - ;; - cegcc) - basic_machine=arm-unknown - os=-cegcc - ;; - convex-c1) - basic_machine=c1-convex - os=-bsd - ;; - convex-c2) - basic_machine=c2-convex - os=-bsd - ;; - convex-c32) - basic_machine=c32-convex - os=-bsd - ;; - convex-c34) - basic_machine=c34-convex - os=-bsd - ;; - convex-c38) - basic_machine=c38-convex - os=-bsd - ;; - cray | j90) - basic_machine=j90-cray - os=-unicos - ;; - craynv) - basic_machine=craynv-cray - os=-unicosmp - ;; - cr16) - basic_machine=cr16-unknown - os=-elf - ;; - crds | unos) - basic_machine=m68k-crds - ;; - crisv32 | crisv32-* | etraxfs*) - basic_machine=crisv32-axis - ;; - cris | cris-* | etrax*) - basic_machine=cris-axis - ;; - crx) - basic_machine=crx-unknown - os=-elf - ;; - da30 | da30-*) - basic_machine=m68k-da30 - ;; - decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) - basic_machine=mips-dec - ;; - decsystem10* | dec10*) - basic_machine=pdp10-dec - os=-tops10 - ;; - decsystem20* | dec20*) - basic_machine=pdp10-dec - os=-tops20 - ;; - delta | 3300 | motorola-3300 | motorola-delta \ - | 3300-motorola | delta-motorola) - basic_machine=m68k-motorola - ;; - delta88) - basic_machine=m88k-motorola - os=-sysv3 - ;; - dicos) - basic_machine=i686-pc - os=-dicos - ;; - djgpp) - basic_machine=i586-pc - os=-msdosdjgpp - ;; - dpx20 | dpx20-*) - basic_machine=rs6000-bull - os=-bosx - ;; - dpx2* | dpx2*-bull) - basic_machine=m68k-bull - os=-sysv3 - ;; - ebmon29k) - basic_machine=a29k-amd - os=-ebmon - ;; - elxsi) - basic_machine=elxsi-elxsi - os=-bsd - ;; - encore | umax | mmax) - basic_machine=ns32k-encore - ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - os=-ose - ;; - fx2800) - basic_machine=i860-alliant - ;; - genix) - basic_machine=ns32k-ns - ;; - gmicro) - basic_machine=tron-gmicro - os=-sysv - ;; - go32) - basic_machine=i386-pc - os=-go32 - ;; - h3050r* | hiux*) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - h8300hms) - basic_machine=h8300-hitachi - os=-hms - ;; - h8300xray) - basic_machine=h8300-hitachi - os=-xray - ;; - h8500hms) - basic_machine=h8500-hitachi - os=-hms - ;; - harris) - basic_machine=m88k-harris - os=-sysv3 - ;; - hp300-*) - basic_machine=m68k-hp - ;; - hp300bsd) - basic_machine=m68k-hp - os=-bsd - ;; - hp300hpux) - basic_machine=m68k-hp - os=-hpux - ;; - hp3k9[0-9][0-9] | hp9[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k2[0-9][0-9] | hp9k31[0-9]) - basic_machine=m68000-hp - ;; - hp9k3[2-9][0-9]) - basic_machine=m68k-hp - ;; - hp9k6[0-9][0-9] | hp6[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k7[0-79][0-9] | hp7[0-79][0-9]) - basic_machine=hppa1.1-hp - ;; - hp9k78[0-9] | hp78[0-9]) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][13679] | hp8[0-9][13679]) - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][0-9] | hp8[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hppa-next) - os=-nextstep3 - ;; - hppaosf) - basic_machine=hppa1.1-hp - os=-osf - ;; - hppro) - basic_machine=hppa1.1-hp - os=-proelf - ;; - i370-ibm* | ibm*) - basic_machine=i370-ibm - ;; -# I'm not sure what "Sysv32" means. Should this be sysv3.2? - i*86v32) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv32 - ;; - i*86v4*) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv4 - ;; - i*86v) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv - ;; - i*86sol2) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-solaris2 - ;; - i386mach) - basic_machine=i386-mach - os=-mach - ;; - i386-vsta | vsta) - basic_machine=i386-unknown - os=-vsta - ;; - iris | iris4d) - basic_machine=mips-sgi - case $os in - -irix*) - ;; - *) - os=-irix4 - ;; - esac - ;; - isi68 | isi) - basic_machine=m68k-isi - os=-sysv - ;; - m68knommu) - basic_machine=m68k-unknown - os=-linux - ;; - m68knommu-*) - basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux - ;; - m88k-omron*) - basic_machine=m88k-omron - ;; - magnum | m3230) - basic_machine=mips-mips - os=-sysv - ;; - merlin) - basic_machine=ns32k-utek - os=-sysv - ;; - mingw32) - basic_machine=i386-pc - os=-mingw32 - ;; - mingw32ce) - basic_machine=arm-unknown - os=-mingw32ce - ;; - miniframe) - basic_machine=m68000-convergent - ;; - *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; - mips3*-*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` - ;; - mips3*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown - ;; - monitor) - basic_machine=m68k-rom68k - os=-coff - ;; - morphos) - basic_machine=powerpc-unknown - os=-morphos - ;; - msdos) - basic_machine=i386-pc - os=-msdos - ;; - ms1-*) - basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` - ;; - mvs) - basic_machine=i370-ibm - os=-mvs - ;; - ncr3000) - basic_machine=i486-ncr - os=-sysv4 - ;; - netbsd386) - basic_machine=i386-unknown - os=-netbsd - ;; - netwinder) - basic_machine=armv4l-rebel - os=-linux - ;; - news | news700 | news800 | news900) - basic_machine=m68k-sony - os=-newsos - ;; - news1000) - basic_machine=m68030-sony - os=-newsos - ;; - news-3600 | risc-news) - basic_machine=mips-sony - os=-newsos - ;; - necv70) - basic_machine=v70-nec - os=-sysv - ;; - next | m*-next ) - basic_machine=m68k-next - case $os in - -nextstep* ) - ;; - -ns2*) - os=-nextstep2 - ;; - *) - os=-nextstep3 - ;; - esac - ;; - nh3000) - basic_machine=m68k-harris - os=-cxux - ;; - nh[45]000) - basic_machine=m88k-harris - os=-cxux - ;; - nindy960) - basic_machine=i960-intel - os=-nindy - ;; - mon960) - basic_machine=i960-intel - os=-mon960 - ;; - nonstopux) - basic_machine=mips-compaq - os=-nonstopux - ;; - np1) - basic_machine=np1-gould - ;; - nsr-tandem) - basic_machine=nsr-tandem - ;; - op50n-* | op60c-*) - basic_machine=hppa1.1-oki - os=-proelf - ;; - openrisc | openrisc-*) - basic_machine=or32-unknown - ;; - os400) - basic_machine=powerpc-ibm - os=-os400 - ;; - OSE68000 | ose68000) - basic_machine=m68000-ericsson - os=-ose - ;; - os68k) - basic_machine=m68k-none - os=-os68k - ;; - pa-hitachi) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - paragon) - basic_machine=i860-intel - os=-osf - ;; - parisc) - basic_machine=hppa-unknown - os=-linux - ;; - parisc-*) - basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux - ;; - pbd) - basic_machine=sparc-tti - ;; - pbb) - basic_machine=m68k-tti - ;; - pc532 | pc532-*) - basic_machine=ns32k-pc532 - ;; - pc98) - basic_machine=i386-pc - ;; - pc98-*) - basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium | p5 | k5 | k6 | nexgen | viac3) - basic_machine=i586-pc - ;; - pentiumpro | p6 | 6x86 | athlon | athlon_*) - basic_machine=i686-pc - ;; - pentiumii | pentium2 | pentiumiii | pentium3) - basic_machine=i686-pc - ;; - pentium4) - basic_machine=i786-pc - ;; - pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) - basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumpro-* | p6-* | 6x86-* | athlon-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium4-*) - basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pn) - basic_machine=pn-gould - ;; - power) basic_machine=power-ibm - ;; - ppc) basic_machine=powerpc-unknown - ;; - ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppcle | powerpclittle | ppc-le | powerpc-little) - basic_machine=powerpcle-unknown - ;; - ppcle-* | powerpclittle-*) - basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64) basic_machine=powerpc64-unknown - ;; - ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64le | powerpc64little | ppc64-le | powerpc64-little) - basic_machine=powerpc64le-unknown - ;; - ppc64le-* | powerpc64little-*) - basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ps2) - basic_machine=i386-ibm - ;; - pw32) - basic_machine=i586-unknown - os=-pw32 - ;; - rdos) - basic_machine=i386-pc - os=-rdos - ;; - rom68k) - basic_machine=m68k-rom68k - os=-coff - ;; - rm[46]00) - basic_machine=mips-siemens - ;; - rtpc | rtpc-*) - basic_machine=romp-ibm - ;; - s390 | s390-*) - basic_machine=s390-ibm - ;; - s390x | s390x-*) - basic_machine=s390x-ibm - ;; - sa29200) - basic_machine=a29k-amd - os=-udi - ;; - sb1) - basic_machine=mipsisa64sb1-unknown - ;; - sb1el) - basic_machine=mipsisa64sb1el-unknown - ;; - sde) - basic_machine=mipsisa32-sde - os=-elf - ;; - sei) - basic_machine=mips-sei - os=-seiux - ;; - sequent) - basic_machine=i386-sequent - ;; - sh) - basic_machine=sh-hitachi - os=-hms - ;; - sh5el) - basic_machine=sh5le-unknown - ;; - sh64) - basic_machine=sh64-unknown - ;; - sparclite-wrs | simso-wrs) - basic_machine=sparclite-wrs - os=-vxworks - ;; - sps7) - basic_machine=m68k-bull - os=-sysv2 - ;; - spur) - basic_machine=spur-unknown - ;; - st2000) - basic_machine=m68k-tandem - ;; - stratus) - basic_machine=i860-stratus - os=-sysv4 - ;; - sun2) - basic_machine=m68000-sun - ;; - sun2os3) - basic_machine=m68000-sun - os=-sunos3 - ;; - sun2os4) - basic_machine=m68000-sun - os=-sunos4 - ;; - sun3os3) - basic_machine=m68k-sun - os=-sunos3 - ;; - sun3os4) - basic_machine=m68k-sun - os=-sunos4 - ;; - sun4os3) - basic_machine=sparc-sun - os=-sunos3 - ;; - sun4os4) - basic_machine=sparc-sun - os=-sunos4 - ;; - sun4sol2) - basic_machine=sparc-sun - os=-solaris2 - ;; - sun3 | sun3-*) - basic_machine=m68k-sun - ;; - sun4) - basic_machine=sparc-sun - ;; - sun386 | sun386i | roadrunner) - basic_machine=i386-sun - ;; - sv1) - basic_machine=sv1-cray - os=-unicos - ;; - symmetry) - basic_machine=i386-sequent - os=-dynix - ;; - t3e) - basic_machine=alphaev5-cray - os=-unicos - ;; - t90) - basic_machine=t90-cray - os=-unicos - ;; - tic54x | c54x*) - basic_machine=tic54x-unknown - os=-coff - ;; - tic55x | c55x*) - basic_machine=tic55x-unknown - os=-coff - ;; - tic6x | c6x*) - basic_machine=tic6x-unknown - os=-coff - ;; - tile*) - basic_machine=tile-unknown - os=-linux-gnu - ;; - tx39) - basic_machine=mipstx39-unknown - ;; - tx39el) - basic_machine=mipstx39el-unknown - ;; - toad1) - basic_machine=pdp10-xkl - os=-tops20 - ;; - tower | tower-32) - basic_machine=m68k-ncr - ;; - tpf) - basic_machine=s390x-ibm - os=-tpf - ;; - udi29k) - basic_machine=a29k-amd - os=-udi - ;; - ultra3) - basic_machine=a29k-nyu - os=-sym1 - ;; - v810 | necv810) - basic_machine=v810-nec - os=-none - ;; - vaxv) - basic_machine=vax-dec - os=-sysv - ;; - vms) - basic_machine=vax-dec - os=-vms - ;; - vpp*|vx|vx-*) - basic_machine=f301-fujitsu - ;; - vxworks960) - basic_machine=i960-wrs - os=-vxworks - ;; - vxworks68) - basic_machine=m68k-wrs - os=-vxworks - ;; - vxworks29k) - basic_machine=a29k-wrs - os=-vxworks - ;; - w65*) - basic_machine=w65-wdc - os=-none - ;; - w89k-*) - basic_machine=hppa1.1-winbond - os=-proelf - ;; - xbox) - basic_machine=i686-pc - os=-mingw32 - ;; - xps | xps100) - basic_machine=xps100-honeywell - ;; - ymp) - basic_machine=ymp-cray - os=-unicos - ;; - z8k-*-coff) - basic_machine=z8k-unknown - os=-sim - ;; - z80-*-coff) - basic_machine=z80-unknown - os=-sim - ;; - none) - basic_machine=none-none - os=-none - ;; - -# Here we handle the default manufacturer of certain CPU types. It is in -# some cases the only manufacturer, in others, it is the most popular. - w89k) - basic_machine=hppa1.1-winbond - ;; - op50n) - basic_machine=hppa1.1-oki - ;; - op60c) - basic_machine=hppa1.1-oki - ;; - romp) - basic_machine=romp-ibm - ;; - mmix) - basic_machine=mmix-knuth - ;; - rs6000) - basic_machine=rs6000-ibm - ;; - vax) - basic_machine=vax-dec - ;; - pdp10) - # there are many clones, so DEC is not a safe bet - basic_machine=pdp10-unknown - ;; - pdp11) - basic_machine=pdp11-dec - ;; - we32k) - basic_machine=we32k-att - ;; - sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele) - basic_machine=sh-unknown - ;; - sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) - basic_machine=sparc-sun - ;; - cydra) - basic_machine=cydra-cydrome - ;; - orion) - basic_machine=orion-highlevel - ;; - orion105) - basic_machine=clipper-highlevel - ;; - mac | mpw | mac-mpw) - basic_machine=m68k-apple - ;; - pmac | pmac-mpw) - basic_machine=powerpc-apple - ;; - *-unknown) - # Make sure to match an already-canonicalized machine name. - ;; - *) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; -esac - -# Here we canonicalize certain aliases for manufacturers. -case $basic_machine in - *-digital*) - basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` - ;; - *-commodore*) - basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` - ;; - *) - ;; -esac - -# Decode manufacturer-specific aliases for certain operating systems. - -if [ x"$os" != x"" ] -then -case $os in - # First match some system type aliases - # that might get confused with valid system types. - # -solaris* is a basic system type, with this one exception. - -solaris1 | -solaris1.*) - os=`echo $os | sed -e 's|solaris1|sunos4|'` - ;; - -solaris) - os=-solaris2 - ;; - -svr4*) - os=-sysv4 - ;; - -unixware*) - os=-sysv4.2uw - ;; - -gnu/linux*) - os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` - ;; - # First accept the basic system types. - # The portable systems comes first. - # Each alternative MUST END IN A *, to match a version number. - # -sysv* is not here because it comes later, after sysvr4. - -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ - | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ - | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ - | -kopensolaris* \ - | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ - | -aos* | -aros* \ - | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ - | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -openbsd* | -solidbsd* \ - | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ - | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ - | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ - | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ - | -chorusos* | -chorusrdb* | -cegcc* \ - | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ - | -uxpv* | -beos* | -mpeix* | -udk* \ - | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ - | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ - | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ - | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ - | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) - # Remember, each alternative MUST END IN *, to match a version number. - ;; - -qnx*) - case $basic_machine in - x86-* | i*86-*) - ;; - *) - os=-nto$os - ;; - esac - ;; - -nto-qnx*) - ;; - -nto*) - os=`echo $os | sed -e 's|nto|nto-qnx|'` - ;; - -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ - | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) - ;; - -mac*) - os=`echo $os | sed -e 's|mac|macos|'` - ;; - -linux-dietlibc) - os=-linux-dietlibc - ;; - -linux*) - os=`echo $os | sed -e 's|linux|linux-gnu|'` - ;; - -sunos5*) - os=`echo $os | sed -e 's|sunos5|solaris2|'` - ;; - -sunos6*) - os=`echo $os | sed -e 's|sunos6|solaris3|'` - ;; - -opened*) - os=-openedition - ;; - -os400*) - os=-os400 - ;; - -wince*) - os=-wince - ;; - -osfrose*) - os=-osfrose - ;; - -osf*) - os=-osf - ;; - -utek*) - os=-bsd - ;; - -dynix*) - os=-bsd - ;; - -acis*) - os=-aos - ;; - -atheos*) - os=-atheos - ;; - -syllable*) - os=-syllable - ;; - -386bsd) - os=-bsd - ;; - -ctix* | -uts*) - os=-sysv - ;; - -nova*) - os=-rtmk-nova - ;; - -ns2 ) - os=-nextstep2 - ;; - -nsk*) - os=-nsk - ;; - # Preserve the version number of sinix5. - -sinix5.*) - os=`echo $os | sed -e 's|sinix|sysv|'` - ;; - -sinix*) - os=-sysv4 - ;; - -tpf*) - os=-tpf - ;; - -triton*) - os=-sysv3 - ;; - -oss*) - os=-sysv3 - ;; - -svr4) - os=-sysv4 - ;; - -svr3) - os=-sysv3 - ;; - -sysvr4) - os=-sysv4 - ;; - # This must come after -sysvr4. - -sysv*) - ;; - -ose*) - os=-ose - ;; - -es1800*) - os=-ose - ;; - -xenix) - os=-xenix - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - os=-mint - ;; - -aros*) - os=-aros - ;; - -kaos*) - os=-kaos - ;; - -zvmoe) - os=-zvmoe - ;; - -dicos*) - os=-dicos - ;; - -none) - ;; - *) - # Get rid of the `-' at the beginning of $os. - os=`echo $os | sed 's/[^-]*-//'` - echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 - exit 1 - ;; -esac -else - -# Here we handle the default operating systems that come with various machines. -# The value should be what the vendor currently ships out the door with their -# machine or put another way, the most popular os provided with the machine. - -# Note that if you're going to try to match "-MANUFACTURER" here (say, -# "-sun"), then you have to tell the case statement up towards the top -# that MANUFACTURER isn't an operating system. Otherwise, code above -# will signal an error saying that MANUFACTURER isn't an operating -# system, and we'll never get to this point. - -case $basic_machine in - score-*) - os=-elf - ;; - spu-*) - os=-elf - ;; - *-acorn) - os=-riscix1.2 - ;; - arm*-rebel) - os=-linux - ;; - arm*-semi) - os=-aout - ;; - c4x-* | tic4x-*) - os=-coff - ;; - # This must come before the *-dec entry. - pdp10-*) - os=-tops20 - ;; - pdp11-*) - os=-none - ;; - *-dec | vax-*) - os=-ultrix4.2 - ;; - m68*-apollo) - os=-domain - ;; - i386-sun) - os=-sunos4.0.2 - ;; - m68000-sun) - os=-sunos3 - # This also exists in the configure program, but was not the - # default. - # os=-sunos4 - ;; - m68*-cisco) - os=-aout - ;; - mep-*) - os=-elf - ;; - mips*-cisco) - os=-elf - ;; - mips*-*) - os=-elf - ;; - or32-*) - os=-coff - ;; - *-tti) # must be before sparc entry or we get the wrong os. - os=-sysv3 - ;; - sparc-* | *-sun) - os=-sunos4.1.1 - ;; - *-be) - os=-beos - ;; - *-haiku) - os=-haiku - ;; - *-ibm) - os=-aix - ;; - *-knuth) - os=-mmixware - ;; - *-wec) - os=-proelf - ;; - *-winbond) - os=-proelf - ;; - *-oki) - os=-proelf - ;; - *-hp) - os=-hpux - ;; - *-hitachi) - os=-hiux - ;; - i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=-sysv - ;; - *-cbm) - os=-amigaos - ;; - *-dg) - os=-dgux - ;; - *-dolphin) - os=-sysv3 - ;; - m68k-ccur) - os=-rtu - ;; - m88k-omron*) - os=-luna - ;; - *-next ) - os=-nextstep - ;; - *-sequent) - os=-ptx - ;; - *-crds) - os=-unos - ;; - *-ns) - os=-genix - ;; - i370-*) - os=-mvs - ;; - *-next) - os=-nextstep3 - ;; - *-gould) - os=-sysv - ;; - *-highlevel) - os=-bsd - ;; - *-encore) - os=-bsd - ;; - *-sgi) - os=-irix - ;; - *-siemens) - os=-sysv4 - ;; - *-masscomp) - os=-rtu - ;; - f30[01]-fujitsu | f700-fujitsu) - os=-uxpv - ;; - *-rom68k) - os=-coff - ;; - *-*bug) - os=-coff - ;; - *-apple) - os=-macos - ;; - *-atari*) - os=-mint - ;; - *) - os=-none - ;; -esac -fi - -# Here we handle the case where we know the os, and the CPU type, but not the -# manufacturer. We pick the logical manufacturer. -vendor=unknown -case $basic_machine in - *-unknown) - case $os in - -riscix*) - vendor=acorn - ;; - -sunos*) - vendor=sun - ;; - -aix*) - vendor=ibm - ;; - -beos*) - vendor=be - ;; - -hpux*) - vendor=hp - ;; - -mpeix*) - vendor=hp - ;; - -hiux*) - vendor=hitachi - ;; - -unos*) - vendor=crds - ;; - -dgux*) - vendor=dg - ;; - -luna*) - vendor=omron - ;; - -genix*) - vendor=ns - ;; - -mvs* | -opened*) - vendor=ibm - ;; - -os400*) - vendor=ibm - ;; - -ptx*) - vendor=sequent - ;; - -tpf*) - vendor=ibm - ;; - -vxsim* | -vxworks* | -windiss*) - vendor=wrs - ;; - -aux*) - vendor=apple - ;; - -hms*) - vendor=hitachi - ;; - -mpw* | -macos*) - vendor=apple - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - vendor=atari - ;; - -vos*) - vendor=stratus - ;; - esac - basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` - ;; -esac - -echo $basic_machine$os -exit - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/bundled/replace/configure b/bundled/replace/configure deleted file mode 100755 index 2397e5fd..00000000 --- a/bundled/replace/configure +++ /dev/null @@ -1,27830 +0,0 @@ -#! /bin/sh -# Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.63. -# -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, -# 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. -# This configure script is free software; the Free Software Foundation -# gives unlimited permission to copy, distribute and modify it. -## --------------------- ## -## M4sh Initialization. ## -## --------------------- ## - -# Be more Bourne compatible -DUALCASE=1; export DUALCASE # for MKS sh -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in - *posix*) set -o posix ;; -esac - -fi - - - - -# PATH needs CR -# Avoid depending upon Character Ranges. -as_cr_letters='abcdefghijklmnopqrstuvwxyz' -as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -as_cr_Letters=$as_cr_letters$as_cr_LETTERS -as_cr_digits='0123456789' -as_cr_alnum=$as_cr_Letters$as_cr_digits - -as_nl=' -' -export as_nl -# Printing a long string crashes Solaris 7 /usr/bin/printf. -as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo -if (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then - as_echo='printf %s\n' - as_echo_n='printf %s' -else - if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then - as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' - as_echo_n='/usr/ucb/echo -n' - else - as_echo_body='eval expr "X$1" : "X\\(.*\\)"' - as_echo_n_body='eval - arg=$1; - case $arg in - *"$as_nl"*) - expr "X$arg" : "X\\(.*\\)$as_nl"; - arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; - esac; - expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" - ' - export as_echo_n_body - as_echo_n='sh -c $as_echo_n_body as_echo' - fi - export as_echo_body - as_echo='sh -c $as_echo_body as_echo' -fi - -# The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then - PATH_SEPARATOR=: - (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { - (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || - PATH_SEPARATOR=';' - } -fi - -# Support unset when possible. -if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - - -# IFS -# We need space, tab and new line, in precisely that order. Quoting is -# there to prevent editors from complaining about space-tab. -# (If _AS_PATH_WALK were called with IFS unset, it would disable word -# splitting by setting IFS to empty value.) -IFS=" "" $as_nl" - -# Find who we are. Look in the path if we contain no directory separator. -case $0 in - *[\\/]* ) as_myself=$0 ;; - *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break -done -IFS=$as_save_IFS - - ;; -esac -# We did not find ourselves, most probably we were run as `sh COMMAND' -# in which case we are not to be found in the path. -if test "x$as_myself" = x; then - as_myself=$0 -fi -if test ! -f "$as_myself"; then - $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 - { (exit 1); exit 1; } -fi - -# Work around bugs in pre-3.0 UWIN ksh. -for as_var in ENV MAIL MAILPATH -do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var -done -PS1='$ ' -PS2='> ' -PS4='+ ' - -# NLS nuisances. -LC_ALL=C -export LC_ALL -LANGUAGE=C -export LANGUAGE - -# Required to use basename. -if expr a : '\(a\)' >/dev/null 2>&1 && - test "X`expr 00001 : '.*\(...\)'`" = X001; then - as_expr=expr -else - as_expr=false -fi - -if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then - as_basename=basename -else - as_basename=false -fi - - -# Name of the executable. -as_me=`$as_basename -- "$0" || -$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$0" | - sed '/^.*\/\([^/][^/]*\)\/*$/{ - s//\1/ - q - } - /^X\/\(\/\/\)$/{ - s//\1/ - q - } - /^X\/\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - -# CDPATH. -$as_unset CDPATH - - -if test "x$CONFIG_SHELL" = x; then - if (eval ":") 2>/dev/null; then - as_have_required=yes -else - as_have_required=no -fi - - if test $as_have_required = yes && (eval ": -(as_func_return () { - (exit \$1) -} -as_func_success () { - as_func_return 0 -} -as_func_failure () { - as_func_return 1 -} -as_func_ret_success () { - return 0 -} -as_func_ret_failure () { - return 1 -} - -exitcode=0 -if as_func_success; then - : -else - exitcode=1 - echo as_func_success failed. -fi - -if as_func_failure; then - exitcode=1 - echo as_func_failure succeeded. -fi - -if as_func_ret_success; then - : -else - exitcode=1 - echo as_func_ret_success failed. -fi - -if as_func_ret_failure; then - exitcode=1 - echo as_func_ret_failure succeeded. -fi - -if ( set x; as_func_ret_success y && test x = \"\$1\" ); then - : -else - exitcode=1 - echo positional parameters were not saved. -fi - -test \$exitcode = 0) || { (exit 1); exit 1; } - -( - as_lineno_1=\$LINENO - as_lineno_2=\$LINENO - test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" && - test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; } -") 2> /dev/null; then - : -else - as_candidate_shells= - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - case $as_dir in - /*) - for as_base in sh bash ksh sh5; do - as_candidate_shells="$as_candidate_shells $as_dir/$as_base" - done;; - esac -done -IFS=$as_save_IFS - - - for as_shell in $as_candidate_shells $SHELL; do - # Try only shells that exist, to save several forks. - if { test -f "$as_shell" || test -f "$as_shell.exe"; } && - { ("$as_shell") 2> /dev/null <<\_ASEOF -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in - *posix*) set -o posix ;; -esac - -fi - - -: -_ASEOF -}; then - CONFIG_SHELL=$as_shell - as_have_required=yes - if { "$as_shell" 2> /dev/null <<\_ASEOF -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in - *posix*) set -o posix ;; -esac - -fi - - -: -(as_func_return () { - (exit $1) -} -as_func_success () { - as_func_return 0 -} -as_func_failure () { - as_func_return 1 -} -as_func_ret_success () { - return 0 -} -as_func_ret_failure () { - return 1 -} - -exitcode=0 -if as_func_success; then - : -else - exitcode=1 - echo as_func_success failed. -fi - -if as_func_failure; then - exitcode=1 - echo as_func_failure succeeded. -fi - -if as_func_ret_success; then - : -else - exitcode=1 - echo as_func_ret_success failed. -fi - -if as_func_ret_failure; then - exitcode=1 - echo as_func_ret_failure succeeded. -fi - -if ( set x; as_func_ret_success y && test x = "$1" ); then - : -else - exitcode=1 - echo positional parameters were not saved. -fi - -test $exitcode = 0) || { (exit 1); exit 1; } - -( - as_lineno_1=$LINENO - as_lineno_2=$LINENO - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; } - -_ASEOF -}; then - break -fi - -fi - - done - - if test "x$CONFIG_SHELL" != x; then - for as_var in BASH_ENV ENV - do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var - done - export CONFIG_SHELL - exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} -fi - - - if test $as_have_required = no; then - echo This script requires a shell more modern than all the - echo shells that I found on your system. Please install a - echo modern shell, or manually run the script under such a - echo shell if you do have one. - { (exit 1); exit 1; } -fi - - -fi - -fi - - - -(eval "as_func_return () { - (exit \$1) -} -as_func_success () { - as_func_return 0 -} -as_func_failure () { - as_func_return 1 -} -as_func_ret_success () { - return 0 -} -as_func_ret_failure () { - return 1 -} - -exitcode=0 -if as_func_success; then - : -else - exitcode=1 - echo as_func_success failed. -fi - -if as_func_failure; then - exitcode=1 - echo as_func_failure succeeded. -fi - -if as_func_ret_success; then - : -else - exitcode=1 - echo as_func_ret_success failed. -fi - -if as_func_ret_failure; then - exitcode=1 - echo as_func_ret_failure succeeded. -fi - -if ( set x; as_func_ret_success y && test x = \"\$1\" ); then - : -else - exitcode=1 - echo positional parameters were not saved. -fi - -test \$exitcode = 0") || { - echo No shell found that supports shell functions. - echo Please tell bug-autoconf@gnu.org about your system, - echo including any error possibly output before this message. - echo This can help us improve future autoconf versions. - echo Configuration will now proceed without shell functions. -} - - - - as_lineno_1=$LINENO - as_lineno_2=$LINENO - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { - - # Create $as_me.lineno as a copy of $as_myself, but with $LINENO - # uniformly replaced by the line number. The first 'sed' inserts a - # line-number line after each line using $LINENO; the second 'sed' - # does the real work. The second script uses 'N' to pair each - # line-number line with the line containing $LINENO, and appends - # trailing '-' during substitution so that $LINENO is not a special - # case at line end. - # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the - # scripts with optimization help from Paolo Bonzini. Blame Lee - # E. McMahon (1931-1989) for sed's syntax. :-) - sed -n ' - p - /[$]LINENO/= - ' <$as_myself | - sed ' - s/[$]LINENO.*/&-/ - t lineno - b - :lineno - N - :loop - s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ - t loop - s/-\n.*// - ' >$as_me.lineno && - chmod +x "$as_me.lineno" || - { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 - { (exit 1); exit 1; }; } - - # Don't try to exec as it changes $[0], causing all sort of problems - # (the dirname of $[0] is not the place where we might find the - # original and so on. Autoconf is especially sensitive to this). - . "./$as_me.lineno" - # Exit status is that of the last command. - exit -} - - -if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then - as_dirname=dirname -else - as_dirname=false -fi - -ECHO_C= ECHO_N= ECHO_T= -case `echo -n x` in --n*) - case `echo 'x\c'` in - *c*) ECHO_T=' ';; # ECHO_T is single tab character. - *) ECHO_C='\c';; - esac;; -*) - ECHO_N='-n';; -esac -if expr a : '\(a\)' >/dev/null 2>&1 && - test "X`expr 00001 : '.*\(...\)'`" = X001; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -if test -d conf$$.dir; then - rm -f conf$$.dir/conf$$.file -else - rm -f conf$$.dir - mkdir conf$$.dir 2>/dev/null -fi -if (echo >conf$$.file) 2>/dev/null; then - if ln -s conf$$.file conf$$ 2>/dev/null; then - as_ln_s='ln -s' - # ... but there are two gotchas: - # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. - # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -p'. - ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -p' - elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln - else - as_ln_s='cp -p' - fi -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file -rmdir conf$$.dir 2>/dev/null - -if mkdir -p . 2>/dev/null; then - as_mkdir_p=: -else - test -d ./-p && rmdir ./-p - as_mkdir_p=false -fi - -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' -else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' -fi -as_executable_p=$as_test_x - -# Sed expression to map a string onto a valid CPP name. -as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" - -# Sed expression to map a string onto a valid variable name. -as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" - - - -exec 7<&0 &1 - -# Name of the host. -# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, -# so uname gets run too. -ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` - -# -# Initializations. -# -ac_default_prefix=/usr/local -ac_clean_files= -ac_config_libobj_dir=. -LIBOBJS= -cross_compiling=no -subdirs= -MFLAGS= -MAKEFLAGS= -SHELL=${CONFIG_SHELL-/bin/sh} - -# Identity of this package. -PACKAGE_NAME= -PACKAGE_TARNAME= -PACKAGE_VERSION= -PACKAGE_STRING= -PACKAGE_BUGREPORT= - -ac_unique_file="replace.c" -ac_unique_file="replace.c" -# Factoring default headers for most tests. -ac_includes_default="\ -#include -#ifdef HAVE_SYS_TYPES_H -# include -#endif -#ifdef HAVE_SYS_STAT_H -# include -#endif -#ifdef STDC_HEADERS -# include -# include -#else -# ifdef HAVE_STDLIB_H -# include -# endif -#endif -#ifdef HAVE_STRING_H -# if !defined STDC_HEADERS && defined HAVE_MEMORY_H -# include -# endif -# include -#endif -#ifdef HAVE_STRINGS_H -# include -#endif -#ifdef HAVE_INTTYPES_H -# include -#endif -#ifdef HAVE_STDINT_H -# include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif" - -ac_subst_vars='LTLIBOBJS -sharedbuilddir -LIBDL -LIBOBJS -libreplace_cv_immediate_structures -INSTALL_DATA -INSTALL_SCRIPT -INSTALL_PROGRAM -EGREP -GREP -CPP -OBJEXT -EXEEXT -ac_ct_CC -CPPFLAGS -LDFLAGS -CFLAGS -CC -target_os -target_vendor -target_cpu -target -host_os -host_vendor -host_cpu -host -build_os -build_vendor -build_cpu -build -LIBREPLACEOBJ -libreplacedir -target_alias -host_alias -build_alias -LIBS -ECHO_T -ECHO_N -ECHO_C -DEFS -mandir -localedir -libdir -psdir -pdfdir -dvidir -htmldir -infodir -docdir -oldincludedir -includedir -localstatedir -sharedstatedir -sysconfdir -datadir -datarootdir -libexecdir -sbindir -bindir -program_transform_name -prefix -exec_prefix -PACKAGE_BUGREPORT -PACKAGE_STRING -PACKAGE_VERSION -PACKAGE_TARNAME -PACKAGE_NAME -PATH_SEPARATOR -SHELL' -ac_subst_files='' -ac_user_opts=' -enable_option_checking -enable_largefile -with_shared_build_dir -' - ac_precious_vars='build_alias -host_alias -target_alias -CC -CFLAGS -LDFLAGS -LIBS -CPPFLAGS -CPP' - - -# Initialize some variables set by options. -ac_init_help= -ac_init_version=false -ac_unrecognized_opts= -ac_unrecognized_sep= -# The variables have the same names as the options, with -# dashes changed to underlines. -cache_file=/dev/null -exec_prefix=NONE -no_create= -no_recursion= -prefix=NONE -program_prefix=NONE -program_suffix=NONE -program_transform_name=s,x,x, -silent= -site= -srcdir= -verbose= -x_includes=NONE -x_libraries=NONE - -# Installation directory options. -# These are left unexpanded so users can "make install exec_prefix=/foo" -# and all the variables that are supposed to be based on exec_prefix -# by default will actually change. -# Use braces instead of parens because sh, perl, etc. also accept them. -# (The list follows the same order as the GNU Coding Standards.) -bindir='${exec_prefix}/bin' -sbindir='${exec_prefix}/sbin' -libexecdir='${exec_prefix}/libexec' -datarootdir='${prefix}/share' -datadir='${datarootdir}' -sysconfdir='${prefix}/etc' -sharedstatedir='${prefix}/com' -localstatedir='${prefix}/var' -includedir='${prefix}/include' -oldincludedir='/usr/include' -docdir='${datarootdir}/doc/${PACKAGE}' -infodir='${datarootdir}/info' -htmldir='${docdir}' -dvidir='${docdir}' -pdfdir='${docdir}' -psdir='${docdir}' -libdir='${exec_prefix}/lib' -localedir='${datarootdir}/locale' -mandir='${datarootdir}/man' - -ac_prev= -ac_dashdash= -for ac_option -do - # If the previous option needs an argument, assign it. - if test -n "$ac_prev"; then - eval $ac_prev=\$ac_option - ac_prev= - continue - fi - - case $ac_option in - *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; - *) ac_optarg=yes ;; - esac - - # Accept the important Cygnus configure options, so we can diagnose typos. - - case $ac_dashdash$ac_option in - --) - ac_dashdash=yes ;; - - -bindir | --bindir | --bindi | --bind | --bin | --bi) - ac_prev=bindir ;; - -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) - bindir=$ac_optarg ;; - - -build | --build | --buil | --bui | --bu) - ac_prev=build_alias ;; - -build=* | --build=* | --buil=* | --bui=* | --bu=*) - build_alias=$ac_optarg ;; - - -cache-file | --cache-file | --cache-fil | --cache-fi \ - | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) - ac_prev=cache_file ;; - -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ - | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) - cache_file=$ac_optarg ;; - - --config-cache | -C) - cache_file=config.cache ;; - - -datadir | --datadir | --datadi | --datad) - ac_prev=datadir ;; - -datadir=* | --datadir=* | --datadi=* | --datad=*) - datadir=$ac_optarg ;; - - -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ - | --dataroo | --dataro | --datar) - ac_prev=datarootdir ;; - -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ - | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) - datarootdir=$ac_optarg ;; - - -disable-* | --disable-*) - ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - { $as_echo "$as_me: error: invalid feature name: $ac_useropt" >&2 - { (exit 1); exit 1; }; } - ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` - case $ac_user_opts in - *" -"enable_$ac_useropt" -"*) ;; - *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" - ac_unrecognized_sep=', ';; - esac - eval enable_$ac_useropt=no ;; - - -docdir | --docdir | --docdi | --doc | --do) - ac_prev=docdir ;; - -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) - docdir=$ac_optarg ;; - - -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) - ac_prev=dvidir ;; - -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) - dvidir=$ac_optarg ;; - - -enable-* | --enable-*) - ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - { $as_echo "$as_me: error: invalid feature name: $ac_useropt" >&2 - { (exit 1); exit 1; }; } - ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` - case $ac_user_opts in - *" -"enable_$ac_useropt" -"*) ;; - *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" - ac_unrecognized_sep=', ';; - esac - eval enable_$ac_useropt=\$ac_optarg ;; - - -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ - | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ - | --exec | --exe | --ex) - ac_prev=exec_prefix ;; - -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ - | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ - | --exec=* | --exe=* | --ex=*) - exec_prefix=$ac_optarg ;; - - -gas | --gas | --ga | --g) - # Obsolete; use --with-gas. - with_gas=yes ;; - - -help | --help | --hel | --he | -h) - ac_init_help=long ;; - -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) - ac_init_help=recursive ;; - -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) - ac_init_help=short ;; - - -host | --host | --hos | --ho) - ac_prev=host_alias ;; - -host=* | --host=* | --hos=* | --ho=*) - host_alias=$ac_optarg ;; - - -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) - ac_prev=htmldir ;; - -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ - | --ht=*) - htmldir=$ac_optarg ;; - - -includedir | --includedir | --includedi | --included | --include \ - | --includ | --inclu | --incl | --inc) - ac_prev=includedir ;; - -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ - | --includ=* | --inclu=* | --incl=* | --inc=*) - includedir=$ac_optarg ;; - - -infodir | --infodir | --infodi | --infod | --info | --inf) - ac_prev=infodir ;; - -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) - infodir=$ac_optarg ;; - - -libdir | --libdir | --libdi | --libd) - ac_prev=libdir ;; - -libdir=* | --libdir=* | --libdi=* | --libd=*) - libdir=$ac_optarg ;; - - -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ - | --libexe | --libex | --libe) - ac_prev=libexecdir ;; - -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ - | --libexe=* | --libex=* | --libe=*) - libexecdir=$ac_optarg ;; - - -localedir | --localedir | --localedi | --localed | --locale) - ac_prev=localedir ;; - -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) - localedir=$ac_optarg ;; - - -localstatedir | --localstatedir | --localstatedi | --localstated \ - | --localstate | --localstat | --localsta | --localst | --locals) - ac_prev=localstatedir ;; - -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ - | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) - localstatedir=$ac_optarg ;; - - -mandir | --mandir | --mandi | --mand | --man | --ma | --m) - ac_prev=mandir ;; - -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) - mandir=$ac_optarg ;; - - -nfp | --nfp | --nf) - # Obsolete; use --without-fp. - with_fp=no ;; - - -no-create | --no-create | --no-creat | --no-crea | --no-cre \ - | --no-cr | --no-c | -n) - no_create=yes ;; - - -no-recursion | --no-recursion | --no-recursio | --no-recursi \ - | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) - no_recursion=yes ;; - - -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ - | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ - | --oldin | --oldi | --old | --ol | --o) - ac_prev=oldincludedir ;; - -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ - | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ - | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) - oldincludedir=$ac_optarg ;; - - -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) - ac_prev=prefix ;; - -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) - prefix=$ac_optarg ;; - - -program-prefix | --program-prefix | --program-prefi | --program-pref \ - | --program-pre | --program-pr | --program-p) - ac_prev=program_prefix ;; - -program-prefix=* | --program-prefix=* | --program-prefi=* \ - | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) - program_prefix=$ac_optarg ;; - - -program-suffix | --program-suffix | --program-suffi | --program-suff \ - | --program-suf | --program-su | --program-s) - ac_prev=program_suffix ;; - -program-suffix=* | --program-suffix=* | --program-suffi=* \ - | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) - program_suffix=$ac_optarg ;; - - -program-transform-name | --program-transform-name \ - | --program-transform-nam | --program-transform-na \ - | --program-transform-n | --program-transform- \ - | --program-transform | --program-transfor \ - | --program-transfo | --program-transf \ - | --program-trans | --program-tran \ - | --progr-tra | --program-tr | --program-t) - ac_prev=program_transform_name ;; - -program-transform-name=* | --program-transform-name=* \ - | --program-transform-nam=* | --program-transform-na=* \ - | --program-transform-n=* | --program-transform-=* \ - | --program-transform=* | --program-transfor=* \ - | --program-transfo=* | --program-transf=* \ - | --program-trans=* | --program-tran=* \ - | --progr-tra=* | --program-tr=* | --program-t=*) - program_transform_name=$ac_optarg ;; - - -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) - ac_prev=pdfdir ;; - -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) - pdfdir=$ac_optarg ;; - - -psdir | --psdir | --psdi | --psd | --ps) - ac_prev=psdir ;; - -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) - psdir=$ac_optarg ;; - - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - silent=yes ;; - - -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) - ac_prev=sbindir ;; - -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ - | --sbi=* | --sb=*) - sbindir=$ac_optarg ;; - - -sharedstatedir | --sharedstatedir | --sharedstatedi \ - | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ - | --sharedst | --shareds | --shared | --share | --shar \ - | --sha | --sh) - ac_prev=sharedstatedir ;; - -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ - | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ - | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ - | --sha=* | --sh=*) - sharedstatedir=$ac_optarg ;; - - -site | --site | --sit) - ac_prev=site ;; - -site=* | --site=* | --sit=*) - site=$ac_optarg ;; - - -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) - ac_prev=srcdir ;; - -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) - srcdir=$ac_optarg ;; - - -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ - | --syscon | --sysco | --sysc | --sys | --sy) - ac_prev=sysconfdir ;; - -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ - | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) - sysconfdir=$ac_optarg ;; - - -target | --target | --targe | --targ | --tar | --ta | --t) - ac_prev=target_alias ;; - -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) - target_alias=$ac_optarg ;; - - -v | -verbose | --verbose | --verbos | --verbo | --verb) - verbose=yes ;; - - -version | --version | --versio | --versi | --vers | -V) - ac_init_version=: ;; - - -with-* | --with-*) - ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - { $as_echo "$as_me: error: invalid package name: $ac_useropt" >&2 - { (exit 1); exit 1; }; } - ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` - case $ac_user_opts in - *" -"with_$ac_useropt" -"*) ;; - *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" - ac_unrecognized_sep=', ';; - esac - eval with_$ac_useropt=\$ac_optarg ;; - - -without-* | --without-*) - ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` - # Reject names that are not valid shell variable names. - expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - { $as_echo "$as_me: error: invalid package name: $ac_useropt" >&2 - { (exit 1); exit 1; }; } - ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` - case $ac_user_opts in - *" -"with_$ac_useropt" -"*) ;; - *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" - ac_unrecognized_sep=', ';; - esac - eval with_$ac_useropt=no ;; - - --x) - # Obsolete; use --with-x. - with_x=yes ;; - - -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ - | --x-incl | --x-inc | --x-in | --x-i) - ac_prev=x_includes ;; - -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ - | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) - x_includes=$ac_optarg ;; - - -x-libraries | --x-libraries | --x-librarie | --x-librari \ - | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) - ac_prev=x_libraries ;; - -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ - | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) - x_libraries=$ac_optarg ;; - - -*) { $as_echo "$as_me: error: unrecognized option: $ac_option -Try \`$0 --help' for more information." >&2 - { (exit 1); exit 1; }; } - ;; - - *=*) - ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` - # Reject names that are not valid shell variable names. - expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && - { $as_echo "$as_me: error: invalid variable name: $ac_envvar" >&2 - { (exit 1); exit 1; }; } - eval $ac_envvar=\$ac_optarg - export $ac_envvar ;; - - *) - # FIXME: should be removed in autoconf 3.0. - $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 - expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && - $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 - : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} - ;; - - esac -done - -if test -n "$ac_prev"; then - ac_option=--`echo $ac_prev | sed 's/_/-/g'` - { $as_echo "$as_me: error: missing argument to $ac_option" >&2 - { (exit 1); exit 1; }; } -fi - -if test -n "$ac_unrecognized_opts"; then - case $enable_option_checking in - no) ;; - fatal) { $as_echo "$as_me: error: unrecognized options: $ac_unrecognized_opts" >&2 - { (exit 1); exit 1; }; } ;; - *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; - esac -fi - -# Check all directory arguments for consistency. -for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ - datadir sysconfdir sharedstatedir localstatedir includedir \ - oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir -do - eval ac_val=\$$ac_var - # Remove trailing slashes. - case $ac_val in - */ ) - ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` - eval $ac_var=\$ac_val;; - esac - # Be sure to have absolute directory names. - case $ac_val in - [\\/$]* | ?:[\\/]* ) continue;; - NONE | '' ) case $ac_var in *prefix ) continue;; esac;; - esac - { $as_echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 - { (exit 1); exit 1; }; } -done - -# There might be people who depend on the old broken behavior: `$host' -# used to hold the argument of --host etc. -# FIXME: To remove some day. -build=$build_alias -host=$host_alias -target=$target_alias - -# FIXME: To remove some day. -if test "x$host_alias" != x; then - if test "x$build_alias" = x; then - cross_compiling=maybe - $as_echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used." >&2 - elif test "x$build_alias" != "x$host_alias"; then - cross_compiling=yes - fi -fi - -ac_tool_prefix= -test -n "$host_alias" && ac_tool_prefix=$host_alias- - -test "$silent" = yes && exec 6>/dev/null - - -ac_pwd=`pwd` && test -n "$ac_pwd" && -ac_ls_di=`ls -di .` && -ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || - { $as_echo "$as_me: error: working directory cannot be determined" >&2 - { (exit 1); exit 1; }; } -test "X$ac_ls_di" = "X$ac_pwd_ls_di" || - { $as_echo "$as_me: error: pwd does not report name of working directory" >&2 - { (exit 1); exit 1; }; } - - -# Find the source files, if location was not specified. -if test -z "$srcdir"; then - ac_srcdir_defaulted=yes - # Try the directory containing this script, then the parent directory. - ac_confdir=`$as_dirname -- "$as_myself" || -$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_myself" : 'X\(//\)[^/]' \| \ - X"$as_myself" : 'X\(//\)$' \| \ - X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_myself" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - srcdir=$ac_confdir - if test ! -r "$srcdir/$ac_unique_file"; then - srcdir=.. - fi -else - ac_srcdir_defaulted=no -fi -if test ! -r "$srcdir/$ac_unique_file"; then - test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." - { $as_echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 - { (exit 1); exit 1; }; } -fi -ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" -ac_abs_confdir=`( - cd "$srcdir" && test -r "./$ac_unique_file" || { $as_echo "$as_me: error: $ac_msg" >&2 - { (exit 1); exit 1; }; } - pwd)` -# When building in place, set srcdir=. -if test "$ac_abs_confdir" = "$ac_pwd"; then - srcdir=. -fi -# Remove unnecessary trailing slashes from srcdir. -# Double slashes in file names in object file debugging info -# mess up M-x gdb in Emacs. -case $srcdir in -*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; -esac -for ac_var in $ac_precious_vars; do - eval ac_env_${ac_var}_set=\${${ac_var}+set} - eval ac_env_${ac_var}_value=\$${ac_var} - eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} - eval ac_cv_env_${ac_var}_value=\$${ac_var} -done - -# -# Report the --help message. -# -if test "$ac_init_help" = "long"; then - # Omit some internal or obsolete options to make the list less imposing. - # This message is too long to be a string in the A/UX 3.1 sh. - cat <<_ACEOF -\`configure' configures this package to adapt to many kinds of systems. - -Usage: $0 [OPTION]... [VAR=VALUE]... - -To assign environment variables (e.g., CC, CFLAGS...), specify them as -VAR=VALUE. See below for descriptions of some of the useful variables. - -Defaults for the options are specified in brackets. - -Configuration: - -h, --help display this help and exit - --help=short display options specific to this package - --help=recursive display the short help of all the included packages - -V, --version display version information and exit - -q, --quiet, --silent do not print \`checking...' messages - --cache-file=FILE cache test results in FILE [disabled] - -C, --config-cache alias for \`--cache-file=config.cache' - -n, --no-create do not create output files - --srcdir=DIR find the sources in DIR [configure dir or \`..'] - -Installation directories: - --prefix=PREFIX install architecture-independent files in PREFIX - [$ac_default_prefix] - --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX - [PREFIX] - -By default, \`make install' will install all the files in -\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify -an installation prefix other than \`$ac_default_prefix' using \`--prefix', -for instance \`--prefix=\$HOME'. - -For better control, use the options below. - -Fine tuning of the installation directories: - --bindir=DIR user executables [EPREFIX/bin] - --sbindir=DIR system admin executables [EPREFIX/sbin] - --libexecdir=DIR program executables [EPREFIX/libexec] - --sysconfdir=DIR read-only single-machine data [PREFIX/etc] - --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] - --localstatedir=DIR modifiable single-machine data [PREFIX/var] - --libdir=DIR object code libraries [EPREFIX/lib] - --includedir=DIR C header files [PREFIX/include] - --oldincludedir=DIR C header files for non-gcc [/usr/include] - --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] - --datadir=DIR read-only architecture-independent data [DATAROOTDIR] - --infodir=DIR info documentation [DATAROOTDIR/info] - --localedir=DIR locale-dependent data [DATAROOTDIR/locale] - --mandir=DIR man documentation [DATAROOTDIR/man] - --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] - --htmldir=DIR html documentation [DOCDIR] - --dvidir=DIR dvi documentation [DOCDIR] - --pdfdir=DIR pdf documentation [DOCDIR] - --psdir=DIR ps documentation [DOCDIR] -_ACEOF - - cat <<\_ACEOF - -System types: - --build=BUILD configure for building on BUILD [guessed] - --host=HOST cross-compile to build programs to run on HOST [BUILD] - --target=TARGET configure for building compilers for TARGET [HOST] -_ACEOF -fi - -if test -n "$ac_init_help"; then - - cat <<\_ACEOF - -Optional Features: - --disable-option-checking ignore unrecognized --enable/--with options - --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) - --enable-FEATURE[=ARG] include FEATURE [ARG=yes] - --disable-largefile omit support for large files - -Optional Packages: - --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] - --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) - --with-shared-build-dir=DIR - temporary build directory where libraries are - installed [$srcdir/sharedbuild] - -Some influential environment variables: - CC C compiler command - CFLAGS C compiler flags - LDFLAGS linker flags, e.g. -L if you have libraries in a - nonstandard directory - LIBS libraries to pass to the linker, e.g. -l - CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I if - you have headers in a nonstandard directory - CPP C preprocessor - -Use these variables to override the choices made by `configure' or to help -it to find libraries and programs with nonstandard names/locations. - -_ACEOF -ac_status=$? -fi - -if test "$ac_init_help" = "recursive"; then - # If there are subdirs, report their specific --help. - for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue - test -d "$ac_dir" || - { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || - continue - ac_builddir=. - -case "$ac_dir" in -.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; -*) - ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` - # A ".." for each directory in $ac_dir_suffix. - ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` - case $ac_top_builddir_sub in - "") ac_top_builddir_sub=. ac_top_build_prefix= ;; - *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; - esac ;; -esac -ac_abs_top_builddir=$ac_pwd -ac_abs_builddir=$ac_pwd$ac_dir_suffix -# for backward compatibility: -ac_top_builddir=$ac_top_build_prefix - -case $srcdir in - .) # We are building in place. - ac_srcdir=. - ac_top_srcdir=$ac_top_builddir_sub - ac_abs_top_srcdir=$ac_pwd ;; - [\\/]* | ?:[\\/]* ) # Absolute name. - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir - ac_abs_top_srcdir=$srcdir ;; - *) # Relative name. - ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_top_build_prefix$srcdir - ac_abs_top_srcdir=$ac_pwd/$srcdir ;; -esac -ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix - - cd "$ac_dir" || { ac_status=$?; continue; } - # Check for guested configure. - if test -f "$ac_srcdir/configure.gnu"; then - echo && - $SHELL "$ac_srcdir/configure.gnu" --help=recursive - elif test -f "$ac_srcdir/configure"; then - echo && - $SHELL "$ac_srcdir/configure" --help=recursive - else - $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 - fi || ac_status=$? - cd "$ac_pwd" || { ac_status=$?; break; } - done -fi - -test -n "$ac_init_help" && exit $ac_status -if $ac_init_version; then - cat <<\_ACEOF -configure -generated by GNU Autoconf 2.63 - -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, -2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. -This configure script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it. -_ACEOF - exit -fi -cat >config.log <<_ACEOF -This file contains any messages produced by compilers while -running configure, to aid debugging if configure makes a mistake. - -It was created by $as_me, which was -generated by GNU Autoconf 2.63. Invocation command line was - - $ $0 $@ - -_ACEOF -exec 5>>config.log -{ -cat <<_ASUNAME -## --------- ## -## Platform. ## -## --------- ## - -hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` - -/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` -/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` -/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` -/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` - -_ASUNAME - -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - $as_echo "PATH: $as_dir" -done -IFS=$as_save_IFS - -} >&5 - -cat >&5 <<_ACEOF - - -## ----------- ## -## Core tests. ## -## ----------- ## - -_ACEOF - - -# Keep a trace of the command line. -# Strip out --no-create and --no-recursion so they do not pile up. -# Strip out --silent because we don't want to record it for future runs. -# Also quote any args containing shell meta-characters. -# Make two passes to allow for proper duplicate-argument suppression. -ac_configure_args= -ac_configure_args0= -ac_configure_args1= -ac_must_keep_next=false -for ac_pass in 1 2 -do - for ac_arg - do - case $ac_arg in - -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil) - continue ;; - *\'*) - ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; - esac - case $ac_pass in - 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; - 2) - ac_configure_args1="$ac_configure_args1 '$ac_arg'" - if test $ac_must_keep_next = true; then - ac_must_keep_next=false # Got value, back to normal. - else - case $ac_arg in - *=* | --config-cache | -C | -disable-* | --disable-* \ - | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ - | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ - | -with-* | --with-* | -without-* | --without-* | --x) - case "$ac_configure_args0 " in - "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; - esac - ;; - -* ) ac_must_keep_next=true ;; - esac - fi - ac_configure_args="$ac_configure_args '$ac_arg'" - ;; - esac - done -done -$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } -$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } - -# When interrupted or exit'd, cleanup temporary files, and complete -# config.log. We remove comments because anyway the quotes in there -# would cause problems or look ugly. -# WARNING: Use '\'' to represent an apostrophe within the trap. -# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. -trap 'exit_status=$? - # Save into config.log some information that might help in debugging. - { - echo - - cat <<\_ASBOX -## ---------------- ## -## Cache variables. ## -## ---------------- ## -_ASBOX - echo - # The following way of writing the cache mishandles newlines in values, -( - for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do - eval ac_val=\$$ac_var - case $ac_val in #( - *${as_nl}*) - case $ac_var in #( - *_cv_*) { $as_echo "$as_me:$LINENO: WARNING: cache variable $ac_var contains a newline" >&5 -$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; - esac - case $ac_var in #( - _ | IFS | as_nl) ;; #( - BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( - *) $as_unset $ac_var ;; - esac ;; - esac - done - (set) 2>&1 | - case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( - *${as_nl}ac_space=\ *) - sed -n \ - "s/'\''/'\''\\\\'\'''\''/g; - s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" - ;; #( - *) - sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" - ;; - esac | - sort -) - echo - - cat <<\_ASBOX -## ----------------- ## -## Output variables. ## -## ----------------- ## -_ASBOX - echo - for ac_var in $ac_subst_vars - do - eval ac_val=\$$ac_var - case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; - esac - $as_echo "$ac_var='\''$ac_val'\''" - done | sort - echo - - if test -n "$ac_subst_files"; then - cat <<\_ASBOX -## ------------------- ## -## File substitutions. ## -## ------------------- ## -_ASBOX - echo - for ac_var in $ac_subst_files - do - eval ac_val=\$$ac_var - case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; - esac - $as_echo "$ac_var='\''$ac_val'\''" - done | sort - echo - fi - - if test -s confdefs.h; then - cat <<\_ASBOX -## ----------- ## -## confdefs.h. ## -## ----------- ## -_ASBOX - echo - cat confdefs.h - echo - fi - test "$ac_signal" != 0 && - $as_echo "$as_me: caught signal $ac_signal" - $as_echo "$as_me: exit $exit_status" - } >&5 - rm -f core *.core core.conftest.* && - rm -f -r conftest* confdefs* conf$$* $ac_clean_files && - exit $exit_status -' 0 -for ac_signal in 1 2 13 15; do - trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal -done -ac_signal=0 - -# confdefs.h avoids OS command line length limits that DEFS can exceed. -rm -f -r conftest* confdefs.h - -# Predefined preprocessor variables. - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_NAME "$PACKAGE_NAME" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_TARNAME "$PACKAGE_TARNAME" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_VERSION "$PACKAGE_VERSION" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_STRING "$PACKAGE_STRING" -_ACEOF - - -cat >>confdefs.h <<_ACEOF -#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" -_ACEOF - - -# Let the site file select an alternate cache file if it wants to. -# Prefer an explicitly selected file to automatically selected ones. -ac_site_file1=NONE -ac_site_file2=NONE -if test -n "$CONFIG_SITE"; then - ac_site_file1=$CONFIG_SITE -elif test "x$prefix" != xNONE; then - ac_site_file1=$prefix/share/config.site - ac_site_file2=$prefix/etc/config.site -else - ac_site_file1=$ac_default_prefix/share/config.site - ac_site_file2=$ac_default_prefix/etc/config.site -fi -for ac_site_file in "$ac_site_file1" "$ac_site_file2" -do - test "x$ac_site_file" = xNONE && continue - if test -r "$ac_site_file"; then - { $as_echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 -$as_echo "$as_me: loading site script $ac_site_file" >&6;} - sed 's/^/| /' "$ac_site_file" >&5 - . "$ac_site_file" - fi -done - -if test -r "$cache_file"; then - # Some versions of bash will fail to source /dev/null (special - # files actually), so we avoid doing that. - if test -f "$cache_file"; then - { $as_echo "$as_me:$LINENO: loading cache $cache_file" >&5 -$as_echo "$as_me: loading cache $cache_file" >&6;} - case $cache_file in - [\\/]* | ?:[\\/]* ) . "$cache_file";; - *) . "./$cache_file";; - esac - fi -else - { $as_echo "$as_me:$LINENO: creating cache $cache_file" >&5 -$as_echo "$as_me: creating cache $cache_file" >&6;} - >$cache_file -fi - -# Check that the precious variables saved in the cache have kept the same -# value. -ac_cache_corrupted=false -for ac_var in $ac_precious_vars; do - eval ac_old_set=\$ac_cv_env_${ac_var}_set - eval ac_new_set=\$ac_env_${ac_var}_set - eval ac_old_val=\$ac_cv_env_${ac_var}_value - eval ac_new_val=\$ac_env_${ac_var}_value - case $ac_old_set,$ac_new_set in - set,) - { $as_echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} - ac_cache_corrupted=: ;; - ,set) - { $as_echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 -$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} - ac_cache_corrupted=: ;; - ,);; - *) - if test "x$ac_old_val" != "x$ac_new_val"; then - # differences in whitespace do not lead to failure. - ac_old_val_w=`echo x $ac_old_val` - ac_new_val_w=`echo x $ac_new_val` - if test "$ac_old_val_w" != "$ac_new_val_w"; then - { $as_echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 -$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} - ac_cache_corrupted=: - else - { $as_echo "$as_me:$LINENO: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 -$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} - eval $ac_var=\$ac_old_val - fi - { $as_echo "$as_me:$LINENO: former value: \`$ac_old_val'" >&5 -$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} - { $as_echo "$as_me:$LINENO: current value: \`$ac_new_val'" >&5 -$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} - fi;; - esac - # Pass precious variables to config.status. - if test "$ac_new_set" = set; then - case $ac_new_val in - *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; - *) ac_arg=$ac_var=$ac_new_val ;; - esac - case " $ac_configure_args " in - *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. - *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; - esac - fi -done -if $ac_cache_corrupted; then - { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} - { $as_echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 -$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} - { { $as_echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 -$as_echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} - { (exit 1); exit 1; }; } -fi - - - - - - - - - - - - - - - - - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - - -ac_config_headers="$ac_config_headers config.h" - - -CFLAGS="$CFLAGS -I$srcdir" - - - -#LIBREPLACE_ALL_CHECKS: START" - -ac_aux_dir= -for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do - if test -f "$ac_dir/install-sh"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install-sh -c" - break - elif test -f "$ac_dir/install.sh"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install.sh -c" - break - elif test -f "$ac_dir/shtool"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/shtool install -c" - break - fi -done -if test -z "$ac_aux_dir"; then - { { $as_echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&5 -$as_echo "$as_me: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&2;} - { (exit 1); exit 1; }; } -fi - -# These three variables are undocumented and unsupported, -# and are intended to be withdrawn in a future Autoconf release. -# They can cause serious problems if a builder's source tree is in a directory -# whose full name contains unusual characters. -ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. -ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. -ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. - - - -echo "LIBREPLACE_LOCATION_CHECKS: START" - -libreplacedir="" -libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace" -for d in $libreplacepaths; do - if test -f "$d/replace.c"; then - libreplacedir="$d" - - break; - fi -done -if test x"$libreplacedir" = "x"; then - { { $as_echo "$as_me:$LINENO: error: cannot find libreplace in $libreplacepaths" >&5 -$as_echo "$as_me: error: cannot find libreplace in $libreplacepaths" >&2;} - { (exit 1); exit 1; }; } -fi -LIBREPLACEOBJ="$libreplacedir/replace.o" - - -# Make sure we can run config.sub. -$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || - { { $as_echo "$as_me:$LINENO: error: cannot run $SHELL $ac_aux_dir/config.sub" >&5 -$as_echo "$as_me: error: cannot run $SHELL $ac_aux_dir/config.sub" >&2;} - { (exit 1); exit 1; }; } - -{ $as_echo "$as_me:$LINENO: checking build system type" >&5 -$as_echo_n "checking build system type... " >&6; } -if test "${ac_cv_build+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_build_alias=$build_alias -test "x$ac_build_alias" = x && - ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` -test "x$ac_build_alias" = x && - { { $as_echo "$as_me:$LINENO: error: cannot guess build type; you must specify one" >&5 -$as_echo "$as_me: error: cannot guess build type; you must specify one" >&2;} - { (exit 1); exit 1; }; } -ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || - { { $as_echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&5 -$as_echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&2;} - { (exit 1); exit 1; }; } - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_build" >&5 -$as_echo "$ac_cv_build" >&6; } -case $ac_cv_build in -*-*-*) ;; -*) { { $as_echo "$as_me:$LINENO: error: invalid value of canonical build" >&5 -$as_echo "$as_me: error: invalid value of canonical build" >&2;} - { (exit 1); exit 1; }; };; -esac -build=$ac_cv_build -ac_save_IFS=$IFS; IFS='-' -set x $ac_cv_build -shift -build_cpu=$1 -build_vendor=$2 -shift; shift -# Remember, the first character of IFS is used to create $*, -# except with old shells: -build_os=$* -IFS=$ac_save_IFS -case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac - - -{ $as_echo "$as_me:$LINENO: checking host system type" >&5 -$as_echo_n "checking host system type... " >&6; } -if test "${ac_cv_host+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "x$host_alias" = x; then - ac_cv_host=$ac_cv_build -else - ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || - { { $as_echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&5 -$as_echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&2;} - { (exit 1); exit 1; }; } -fi - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_host" >&5 -$as_echo "$ac_cv_host" >&6; } -case $ac_cv_host in -*-*-*) ;; -*) { { $as_echo "$as_me:$LINENO: error: invalid value of canonical host" >&5 -$as_echo "$as_me: error: invalid value of canonical host" >&2;} - { (exit 1); exit 1; }; };; -esac -host=$ac_cv_host -ac_save_IFS=$IFS; IFS='-' -set x $ac_cv_host -shift -host_cpu=$1 -host_vendor=$2 -shift; shift -# Remember, the first character of IFS is used to create $*, -# except with old shells: -host_os=$* -IFS=$ac_save_IFS -case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac - - -{ $as_echo "$as_me:$LINENO: checking target system type" >&5 -$as_echo_n "checking target system type... " >&6; } -if test "${ac_cv_target+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "x$target_alias" = x; then - ac_cv_target=$ac_cv_host -else - ac_cv_target=`$SHELL "$ac_aux_dir/config.sub" $target_alias` || - { { $as_echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $target_alias failed" >&5 -$as_echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $target_alias failed" >&2;} - { (exit 1); exit 1; }; } -fi - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_target" >&5 -$as_echo "$ac_cv_target" >&6; } -case $ac_cv_target in -*-*-*) ;; -*) { { $as_echo "$as_me:$LINENO: error: invalid value of canonical target" >&5 -$as_echo "$as_me: error: invalid value of canonical target" >&2;} - { (exit 1); exit 1; }; };; -esac -target=$ac_cv_target -ac_save_IFS=$IFS; IFS='-' -set x $ac_cv_target -shift -target_cpu=$1 -target_vendor=$2 -shift; shift -# Remember, the first character of IFS is used to create $*, -# except with old shells: -target_os=$* -IFS=$ac_save_IFS -case $target_os in *\ *) target_os=`echo "$target_os" | sed 's/ /-/g'`;; esac - - -# The aliases save the names the user supplied, while $host etc. -# will get canonicalized. -test -n "$target_alias" && - test "$program_prefix$program_suffix$program_transform_name" = \ - NONENONEs,x,x, && - program_prefix=${target_alias}- - -echo "LIBREPLACE_LOCATION_CHECKS: END" - - - -echo "LIBREPLACE_CC_CHECKS: START" - - -ac_cv_prog_cc_Ae=no - -savedCFLAGS=$CFLAGS -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. -set dummy ${ac_tool_prefix}gcc; ac_word=$2 -{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_CC+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_CC="${ac_tool_prefix}gcc" - $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done -IFS=$as_save_IFS - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:$LINENO: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi -if test -z "$ac_cv_prog_CC"; then - ac_ct_CC=$CC - # Extract the first word of "gcc", so it can be a program name with args. -set dummy gcc; ac_word=$2 -{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_ac_ct_CC="gcc" - $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done -IFS=$as_save_IFS - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - { $as_echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 -$as_echo "$ac_ct_CC" >&6; } -else - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - - if test "x$ac_ct_CC" = x; then - CC="" - else - case $cross_compiling:$ac_tool_warned in -yes:) -{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} -ac_tool_warned=yes ;; -esac - CC=$ac_ct_CC - fi -else - CC="$ac_cv_prog_CC" -fi - -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. -set dummy ${ac_tool_prefix}cc; ac_word=$2 -{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_CC+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_CC="${ac_tool_prefix}cc" - $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done -IFS=$as_save_IFS - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:$LINENO: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - - - fi -fi -if test -z "$CC"; then - # Extract the first word of "cc", so it can be a program name with args. -set dummy cc; ac_word=$2 -{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_CC+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - ac_prog_rejected=no -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then - ac_prog_rejected=yes - continue - fi - ac_cv_prog_CC="cc" - $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done -IFS=$as_save_IFS - -if test $ac_prog_rejected = yes; then - # We found a bogon in the path, so make sure we never use it. - set dummy $ac_cv_prog_CC - shift - if test $# != 0; then - # We chose a different compiler from the bogus one. - # However, it has the same basename, so the bogon will be chosen - # first if we set CC to just the basename; use the full file name. - shift - ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" - fi -fi -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:$LINENO: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi -if test -z "$CC"; then - if test -n "$ac_tool_prefix"; then - for ac_prog in cl.exe - do - # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. -set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_CC+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_CC="$ac_tool_prefix$ac_prog" - $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done -IFS=$as_save_IFS - -fi -fi -CC=$ac_cv_prog_CC -if test -n "$CC"; then - { $as_echo "$as_me:$LINENO: result: $CC" >&5 -$as_echo "$CC" >&6; } -else - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - - - test -n "$CC" && break - done -fi -if test -z "$CC"; then - ac_ct_CC=$CC - for ac_prog in cl.exe -do - # Extract the first word of "$ac_prog", so it can be a program name with args. -set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test -n "$ac_ct_CC"; then - ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_prog_ac_ct_CC="$ac_prog" - $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done -done -IFS=$as_save_IFS - -fi -fi -ac_ct_CC=$ac_cv_prog_ac_ct_CC -if test -n "$ac_ct_CC"; then - { $as_echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 -$as_echo "$ac_ct_CC" >&6; } -else - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - - - test -n "$ac_ct_CC" && break -done - - if test "x$ac_ct_CC" = x; then - CC="" - else - case $cross_compiling:$ac_tool_warned in -yes:) -{ $as_echo "$as_me:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} -ac_tool_warned=yes ;; -esac - CC=$ac_ct_CC - fi -fi - -fi - - -test -z "$CC" && { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: no acceptable C compiler found in \$PATH -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; }; } - -# Provide some information about the compiler. -$as_echo "$as_me:$LINENO: checking for C compiler version" >&5 -set X $ac_compile -ac_compiler=$2 -{ (ac_try="$ac_compiler --version >&5" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compiler --version >&5") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } -{ (ac_try="$ac_compiler -v >&5" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compiler -v >&5") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } -{ (ac_try="$ac_compiler -V >&5" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compiler -V >&5") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" -# Try to create an executable without -o first, disregard a.out. -# It will help us diagnose broken compilers, and finding out an intuition -# of exeext. -{ $as_echo "$as_me:$LINENO: checking for C compiler default output file name" >&5 -$as_echo_n "checking for C compiler default output file name... " >&6; } -ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` - -# The possible output files: -ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" - -ac_rmfiles= -for ac_file in $ac_files -do - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; - * ) ac_rmfiles="$ac_rmfiles $ac_file";; - esac -done -rm -f $ac_rmfiles - -if { (ac_try="$ac_link_default" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link_default") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; then - # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. -# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' -# in a Makefile. We should not override ac_cv_exeext if it was cached, -# so that the user can short-circuit this test for compilers unknown to -# Autoconf. -for ac_file in $ac_files '' -do - test -f "$ac_file" || continue - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) - ;; - [ab].out ) - # We found the default executable, but exeext='' is most - # certainly right. - break;; - *.* ) - if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; - then :; else - ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - fi - # We set ac_cv_exeext here because the later test for it is not - # safe: cross compilers may not add the suffix if given an `-o' - # argument, so we may need to know it at that point already. - # Even if this section looks crufty: it has the advantage of - # actually working. - break;; - * ) - break;; - esac -done -test "$ac_cv_exeext" = no && ac_cv_exeext= - -else - ac_file='' -fi - -{ $as_echo "$as_me:$LINENO: result: $ac_file" >&5 -$as_echo "$ac_file" >&6; } -if test -z "$ac_file"; then - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: C compiler cannot create executables -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: C compiler cannot create executables -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } -fi - -ac_exeext=$ac_cv_exeext - -# Check that the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -{ $as_echo "$as_me:$LINENO: checking whether the C compiler works" >&5 -$as_echo_n "checking whether the C compiler works... " >&6; } -# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 -# If not cross compiling, check that we can run a simple program. -if test "$cross_compiling" != yes; then - if { ac_try='./$ac_file' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - cross_compiling=no - else - if test "$cross_compiling" = maybe; then - cross_compiling=yes - else - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'. -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot run C compiled programs. -If you meant to cross compile, use \`--host'. -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; }; } - fi - fi -fi -{ $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } - -rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out -ac_clean_files=$ac_clean_files_save -# Check that the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -{ $as_echo "$as_me:$LINENO: checking whether we are cross compiling" >&5 -$as_echo_n "checking whether we are cross compiling... " >&6; } -{ $as_echo "$as_me:$LINENO: result: $cross_compiling" >&5 -$as_echo "$cross_compiling" >&6; } - -{ $as_echo "$as_me:$LINENO: checking for suffix of executables" >&5 -$as_echo_n "checking for suffix of executables... " >&6; } -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; then - # If both `conftest.exe' and `conftest' are `present' (well, observable) -# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will -# work properly (i.e., refer to `conftest.exe'), while it won't with -# `rm'. -for ac_file in conftest.exe conftest conftest.*; do - test -f "$ac_file" || continue - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; - *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` - break;; - * ) break;; - esac -done -else - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; }; } -fi - -rm -f conftest$ac_cv_exeext -{ $as_echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5 -$as_echo "$ac_cv_exeext" >&6; } - -rm -f conftest.$ac_ext -EXEEXT=$ac_cv_exeext -ac_exeext=$EXEEXT -{ $as_echo "$as_me:$LINENO: checking for suffix of object files" >&5 -$as_echo_n "checking for suffix of object files... " >&6; } -if test "${ac_cv_objext+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.o conftest.obj -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; then - for ac_file in conftest.o conftest.obj conftest.*; do - test -f "$ac_file" || continue; - case $ac_file in - *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; - *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` - break;; - esac -done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute suffix of object files: cannot compile -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; }; } -fi - -rm -f conftest.$ac_cv_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_objext" >&5 -$as_echo "$ac_cv_objext" >&6; } -OBJEXT=$ac_cv_objext -ac_objext=$OBJEXT -{ $as_echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5 -$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } -if test "${ac_cv_c_compiler_gnu+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ -#ifndef __GNUC__ - choke me -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_compiler_gnu=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_compiler_gnu=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -ac_cv_c_compiler_gnu=$ac_compiler_gnu - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5 -$as_echo "$ac_cv_c_compiler_gnu" >&6; } -if test $ac_compiler_gnu = yes; then - GCC=yes -else - GCC= -fi -ac_test_CFLAGS=${CFLAGS+set} -ac_save_CFLAGS=$CFLAGS -{ $as_echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 -$as_echo_n "checking whether $CC accepts -g... " >&6; } -if test "${ac_cv_prog_cc_g+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_save_c_werror_flag=$ac_c_werror_flag - ac_c_werror_flag=yes - ac_cv_prog_cc_g=no - CFLAGS="-g" - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_prog_cc_g=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - CFLAGS="" - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_c_werror_flag=$ac_save_c_werror_flag - CFLAGS="-g" - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_prog_cc_g=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - ac_c_werror_flag=$ac_save_c_werror_flag -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5 -$as_echo "$ac_cv_prog_cc_g" >&6; } -if test "$ac_test_CFLAGS" = set; then - CFLAGS=$ac_save_CFLAGS -elif test $ac_cv_prog_cc_g = yes; then - if test "$GCC" = yes; then - CFLAGS="-g -O2" - else - CFLAGS="-g" - fi -else - if test "$GCC" = yes; then - CFLAGS="-O2" - else - CFLAGS= - fi -fi -{ $as_echo "$as_me:$LINENO: checking for $CC option to accept ISO C89" >&5 -$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } -if test "${ac_cv_prog_cc_c89+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_prog_cc_c89=no -ac_save_CC=$CC -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#include -#include -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} - -/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has - function prototypes and stuff, but not '\xHH' hex character constants. - These don't provoke an error unfortunately, instead are silently treated - as 'x'. The following induces an error, until -std is added to get - proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an - array size at least. It's necessary to write '\x00'==0 to get something - that's true only with -std. */ -int osf4_cc_array ['\x00' == 0 ? 1 : -1]; - -/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters - inside strings and character constants. */ -#define FOO(x) 'x' -int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; - -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -int -main () -{ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - ; - return 0; -} -_ACEOF -for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ - -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" -do - CC="$ac_save_CC $ac_arg" - rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_prog_cc_c89=$ac_arg -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext - test "x$ac_cv_prog_cc_c89" != "xno" && break -done -rm -f conftest.$ac_ext -CC=$ac_save_CC - -fi -# AC_CACHE_VAL -case "x$ac_cv_prog_cc_c89" in - x) - { $as_echo "$as_me:$LINENO: result: none needed" >&5 -$as_echo "none needed" >&6; } ;; - xno) - { $as_echo "$as_me:$LINENO: result: unsupported" >&5 -$as_echo "unsupported" >&6; } ;; - *) - CC="$CC $ac_cv_prog_cc_c89" - { $as_echo "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5 -$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; -esac - - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - -CFLAGS=$savedCFLAGS - -if test x"$GCC" != x"yes" ; then - { $as_echo "$as_me:$LINENO: checking for $CC option to accept ISO C99" >&5 -$as_echo_n "checking for $CC option to accept ISO C99... " >&6; } -if test "${ac_cv_prog_cc_c99+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_prog_cc_c99=no -ac_save_CC=$CC -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#include -#include -#include - -// Check varargs macros. These examples are taken from C99 6.10.3.5. -#define debug(...) fprintf (stderr, __VA_ARGS__) -#define showlist(...) puts (#__VA_ARGS__) -#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) -static void -test_varargs_macros (void) -{ - int x = 1234; - int y = 5678; - debug ("Flag"); - debug ("X = %d\n", x); - showlist (The first, second, and third items.); - report (x>y, "x is %d but y is %d", x, y); -} - -// Check long long types. -#define BIG64 18446744073709551615ull -#define BIG32 4294967295ul -#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) -#if !BIG_OK - your preprocessor is broken; -#endif -#if BIG_OK -#else - your preprocessor is broken; -#endif -static long long int bignum = -9223372036854775807LL; -static unsigned long long int ubignum = BIG64; - -struct incomplete_array -{ - int datasize; - double data[]; -}; - -struct named_init { - int number; - const wchar_t *name; - double average; -}; - -typedef const char *ccp; - -static inline int -test_restrict (ccp restrict text) -{ - // See if C++-style comments work. - // Iterate through items via the restricted pointer. - // Also check for declarations in for loops. - for (unsigned int i = 0; *(text+i) != '\0'; ++i) - continue; - return 0; -} - -// Check varargs and va_copy. -static void -test_varargs (const char *format, ...) -{ - va_list args; - va_start (args, format); - va_list args_copy; - va_copy (args_copy, args); - - const char *str; - int number; - float fnumber; - - while (*format) - { - switch (*format++) - { - case 's': // string - str = va_arg (args_copy, const char *); - break; - case 'd': // int - number = va_arg (args_copy, int); - break; - case 'f': // float - fnumber = va_arg (args_copy, double); - break; - default: - break; - } - } - va_end (args_copy); - va_end (args); -} - -int -main () -{ - - // Check bool. - _Bool success = false; - - // Check restrict. - if (test_restrict ("String literal") == 0) - success = true; - char *restrict newvar = "Another string"; - - // Check varargs. - test_varargs ("s, d' f .", "string", 65, 34.234); - test_varargs_macros (); - - // Check flexible array members. - struct incomplete_array *ia = - malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); - ia->datasize = 10; - for (int i = 0; i < ia->datasize; ++i) - ia->data[i] = i * 1.234; - - // Check named initializers. - struct named_init ni = { - .number = 34, - .name = L"Test wide string", - .average = 543.34343, - }; - - ni.number = 58; - - int dynamic_array[ni.number]; - dynamic_array[ni.number - 1] = 543; - - // work around unused variable warnings - return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x' - || dynamic_array[ni.number - 1] != 543); - - ; - return 0; -} -_ACEOF -for ac_arg in '' -std=gnu99 -std=c99 -c99 -AC99 -xc99=all -qlanglvl=extc99 -do - CC="$ac_save_CC $ac_arg" - rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_prog_cc_c99=$ac_arg -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext - test "x$ac_cv_prog_cc_c99" != "xno" && break -done -rm -f conftest.$ac_ext -CC=$ac_save_CC - -fi -# AC_CACHE_VAL -case "x$ac_cv_prog_cc_c99" in - x) - { $as_echo "$as_me:$LINENO: result: none needed" >&5 -$as_echo "none needed" >&6; } ;; - xno) - { $as_echo "$as_me:$LINENO: result: unsupported" >&5 -$as_echo "unsupported" >&6; } ;; - *) - CC="$CC $ac_cv_prog_cc_c99" - { $as_echo "$as_me:$LINENO: result: $ac_cv_prog_cc_c99" >&5 -$as_echo "$ac_cv_prog_cc_c99" >&6; } ;; -esac - - - -fi - -if test x"$GCC" = x"yes" ; then - { $as_echo "$as_me:$LINENO: checking for version of gcc" >&5 -$as_echo_n "checking for version of gcc... " >&6; } - GCC_VERSION=`$CC -dumpversion` - { $as_echo "$as_me:$LINENO: result: ${GCC_VERSION}" >&5 -$as_echo "${GCC_VERSION}" >&6; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ $as_echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 -$as_echo_n "checking how to run the C preprocessor... " >&6; } -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if test "${ac_cv_prog_CPP+set}" = set; then - $as_echo_n "(cached) " >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Broken: fails on valid input. -continue -fi - -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - # Broken: success on invalid input. -continue -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Passes both tests. -ac_preproc_ok=: -break -fi - -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - break -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -{ $as_echo "$as_me:$LINENO: result: $CPP" >&5 -$as_echo "$CPP" >&6; } -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer to if __STDC__ is defined, since - # exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifdef __STDC__ -# include -#else -# include -#endif - Syntax error -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Broken: fails on valid input. -continue -fi - -rm -f conftest.err conftest.$ac_ext - - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - # Broken: success on invalid input. -continue -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - # Passes both tests. -ac_preproc_ok=: -break -fi - -rm -f conftest.err conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.err conftest.$ac_ext -if $ac_preproc_ok; then - : -else - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; }; } -fi - -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu - - -{ $as_echo "$as_me:$LINENO: checking for grep that handles long lines and -e" >&5 -$as_echo_n "checking for grep that handles long lines and -e... " >&6; } -if test "${ac_cv_path_GREP+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test -z "$GREP"; then - ac_path_GREP_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in grep ggrep; do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" - { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue -# Check for GNU ac_path_GREP and select it if it is found. - # Check for GNU $ac_path_GREP -case `"$ac_path_GREP" --version 2>&1` in -*GNU*) - ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; -*) - ac_count=0 - $as_echo_n 0123456789 >"conftest.in" - while : - do - cat "conftest.in" "conftest.in" >"conftest.tmp" - mv "conftest.tmp" "conftest.in" - cp "conftest.in" "conftest.nl" - $as_echo 'GREP' >> "conftest.nl" - "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break - diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - ac_count=`expr $ac_count + 1` - if test $ac_count -gt ${ac_path_GREP_max-0}; then - # Best one so far, save it but keep looking for a better one - ac_cv_path_GREP="$ac_path_GREP" - ac_path_GREP_max=$ac_count - fi - # 10*(2^10) chars as input seems more than enough - test $ac_count -gt 10 && break - done - rm -f conftest.in conftest.tmp conftest.nl conftest.out;; -esac - - $ac_path_GREP_found && break 3 - done - done -done -IFS=$as_save_IFS - if test -z "$ac_cv_path_GREP"; then - { { $as_echo "$as_me:$LINENO: error: no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5 -$as_echo "$as_me: error: no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;} - { (exit 1); exit 1; }; } - fi -else - ac_cv_path_GREP=$GREP -fi - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_GREP" >&5 -$as_echo "$ac_cv_path_GREP" >&6; } - GREP="$ac_cv_path_GREP" - - -{ $as_echo "$as_me:$LINENO: checking for egrep" >&5 -$as_echo_n "checking for egrep... " >&6; } -if test "${ac_cv_path_EGREP+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 - then ac_cv_path_EGREP="$GREP -E" - else - if test -z "$EGREP"; then - ac_path_EGREP_found=false - # Loop through the user's path and test for each of PROGNAME-LIST - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in egrep; do - for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" - { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue -# Check for GNU ac_path_EGREP and select it if it is found. - # Check for GNU $ac_path_EGREP -case `"$ac_path_EGREP" --version 2>&1` in -*GNU*) - ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; -*) - ac_count=0 - $as_echo_n 0123456789 >"conftest.in" - while : - do - cat "conftest.in" "conftest.in" >"conftest.tmp" - mv "conftest.tmp" "conftest.in" - cp "conftest.in" "conftest.nl" - $as_echo 'EGREP' >> "conftest.nl" - "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break - diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break - ac_count=`expr $ac_count + 1` - if test $ac_count -gt ${ac_path_EGREP_max-0}; then - # Best one so far, save it but keep looking for a better one - ac_cv_path_EGREP="$ac_path_EGREP" - ac_path_EGREP_max=$ac_count - fi - # 10*(2^10) chars as input seems more than enough - test $ac_count -gt 10 && break - done - rm -f conftest.in conftest.tmp conftest.nl conftest.out;; -esac - - $ac_path_EGREP_found && break 3 - done - done -done -IFS=$as_save_IFS - if test -z "$ac_cv_path_EGREP"; then - { { $as_echo "$as_me:$LINENO: error: no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5 -$as_echo "$as_me: error: no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;} - { (exit 1); exit 1; }; } - fi -else - ac_cv_path_EGREP=$EGREP -fi - - fi -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_EGREP" >&5 -$as_echo "$ac_cv_path_EGREP" >&6; } - EGREP="$ac_cv_path_EGREP" - - -{ $as_echo "$as_me:$LINENO: checking for ANSI C header files" >&5 -$as_echo_n "checking for ANSI C header files... " >&6; } -if test "${ac_cv_header_stdc+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#include -#include - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_header_stdc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_header_stdc=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "memchr" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "free" >/dev/null 2>&1; then - : -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then - : -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) \ - (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - return 2; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - : -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -ac_cv_header_stdc=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5 -$as_echo "$ac_cv_header_stdc" >&6; } -if test $ac_cv_header_stdc = yes; then - -cat >>confdefs.h <<\_ACEOF -#define STDC_HEADERS 1 -_ACEOF - -fi - -# On IRIX 5.3, sys/types and inttypes.h are conflicting. - - - - - - - - - -for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ - inttypes.h stdint.h unistd.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default - -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - eval "$as_ac_Header=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_Header=no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - - if test "${ac_cv_header_minix_config_h+set}" = set; then - { $as_echo "$as_me:$LINENO: checking for minix/config.h" >&5 -$as_echo_n "checking for minix/config.h... " >&6; } -if test "${ac_cv_header_minix_config_h+set}" = set; then - $as_echo_n "(cached) " >&6 -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_minix_config_h" >&5 -$as_echo "$ac_cv_header_minix_config_h" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking minix/config.h usability" >&5 -$as_echo_n "checking minix/config.h usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking minix/config.h presence" >&5 -$as_echo_n "checking minix/config.h presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: minix/config.h: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: minix/config.h: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: minix/config.h: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: minix/config.h: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: minix/config.h: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: minix/config.h: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: minix/config.h: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: minix/config.h: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: minix/config.h: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for minix/config.h" >&5 -$as_echo_n "checking for minix/config.h... " >&6; } -if test "${ac_cv_header_minix_config_h+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_header_minix_config_h=$ac_header_preproc -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_minix_config_h" >&5 -$as_echo "$ac_cv_header_minix_config_h" >&6; } - -fi -if test "x$ac_cv_header_minix_config_h" = x""yes; then - MINIX=yes -else - MINIX= -fi - - - if test "$MINIX" = yes; then - -cat >>confdefs.h <<\_ACEOF -#define _POSIX_SOURCE 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define _POSIX_1_SOURCE 2 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define _MINIX 1 -_ACEOF - - fi - - - - { $as_echo "$as_me:$LINENO: checking whether it is safe to define __EXTENSIONS__" >&5 -$as_echo_n "checking whether it is safe to define __EXTENSIONS__... " >&6; } -if test "${ac_cv_safe_to_define___extensions__+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -# define __EXTENSIONS__ 1 - $ac_includes_default -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_safe_to_define___extensions__=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_safe_to_define___extensions__=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_safe_to_define___extensions__" >&5 -$as_echo "$ac_cv_safe_to_define___extensions__" >&6; } - test $ac_cv_safe_to_define___extensions__ = yes && - cat >>confdefs.h <<\_ACEOF -#define __EXTENSIONS__ 1 -_ACEOF - - cat >>confdefs.h <<\_ACEOF -#define _ALL_SOURCE 1 -_ACEOF - - cat >>confdefs.h <<\_ACEOF -#define _GNU_SOURCE 1 -_ACEOF - - cat >>confdefs.h <<\_ACEOF -#define _POSIX_PTHREAD_SEMANTICS 1 -_ACEOF - - cat >>confdefs.h <<\_ACEOF -#define _TANDEM_SOURCE 1 -_ACEOF - - - - { $as_echo "$as_me:$LINENO: checking whether byte ordering is bigendian" >&5 -$as_echo_n "checking whether byte ordering is bigendian... " >&6; } -if test "${ac_cv_c_bigendian+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_c_bigendian=unknown - # See if we're dealing with a universal compiler. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifndef __APPLE_CC__ - not a universal capable compiler - #endif - typedef int dummy; - -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - # Check for potential -arch flags. It is not universal unless - # there are some -arch flags. Note that *ppc* also matches - # ppc64. This check is also rather less than ideal. - case "${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}" in #( - *-arch*ppc*|*-arch*i386*|*-arch*x86_64*) ac_cv_c_bigendian=universal;; - esac -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - if test $ac_cv_c_bigendian = unknown; then - # See if sys/param.h defines the BYTE_ORDER macro. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - #include - -int -main () -{ -#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \ - && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \ - && LITTLE_ENDIAN) - bogus endian macros - #endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - # It does; now see whether it defined to BIG_ENDIAN or not. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - #include - -int -main () -{ -#if BYTE_ORDER != BIG_ENDIAN - not big endian - #endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_c_bigendian=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_c_bigendian=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - fi - if test $ac_cv_c_bigendian = unknown; then - # See if defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris). - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -int -main () -{ -#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN) - bogus endian macros - #endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - # It does; now see whether it defined to _BIG_ENDIAN or not. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -int -main () -{ -#ifndef _BIG_ENDIAN - not big endian - #endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_c_bigendian=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_c_bigendian=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - fi - if test $ac_cv_c_bigendian = unknown; then - # Compile a test program. - if test "$cross_compiling" = yes; then - # Try to guess by grepping values from an object file. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -short int ascii_mm[] = - { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; - short int ascii_ii[] = - { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; - int use_ascii (int i) { - return ascii_mm[i] + ascii_ii[i]; - } - short int ebcdic_ii[] = - { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; - short int ebcdic_mm[] = - { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; - int use_ebcdic (int i) { - return ebcdic_mm[i] + ebcdic_ii[i]; - } - extern int foo; - -int -main () -{ -return use_ascii (foo) == use_ebcdic (foo); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then - ac_cv_c_bigendian=yes - fi - if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then - if test "$ac_cv_c_bigendian" = unknown; then - ac_cv_c_bigendian=no - else - # finding both strings is unlikely to happen, but who knows? - ac_cv_c_bigendian=unknown - fi - fi -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ - - /* Are we little or big endian? From Harbison&Steele. */ - union - { - long int l; - char c[sizeof (long int)]; - } u; - u.l = 1; - return u.c[sizeof (long int) - 1] == 1; - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_c_bigendian=no -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -ac_cv_c_bigendian=yes -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - - fi -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_bigendian" >&5 -$as_echo "$ac_cv_c_bigendian" >&6; } - case $ac_cv_c_bigendian in #( - yes) - cat >>confdefs.h <<\_ACEOF -#define WORDS_BIGENDIAN 1 -_ACEOF -;; #( - no) - ;; #( - universal) - -cat >>confdefs.h <<\_ACEOF -#define AC_APPLE_UNIVERSAL_BUILD 1 -_ACEOF - - ;; #( - *) - { { $as_echo "$as_me:$LINENO: error: unknown endianness - presetting ac_cv_c_bigendian=no (or yes) will help" >&5 -$as_echo "$as_me: error: unknown endianness - presetting ac_cv_c_bigendian=no (or yes) will help" >&2;} - { (exit 1); exit 1; }; } ;; - esac - -{ $as_echo "$as_me:$LINENO: checking for inline" >&5 -$as_echo_n "checking for inline... " >&6; } -if test "${ac_cv_c_inline+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_c_inline=no -for ac_kw in inline __inline__ __inline; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#ifndef __cplusplus -typedef int foo_t; -static $ac_kw foo_t static_foo () {return 0; } -$ac_kw foo_t foo () {return 0; } -#endif - -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_c_inline=$ac_kw -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - test "$ac_cv_c_inline" != no && break -done - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_inline" >&5 -$as_echo "$ac_cv_c_inline" >&6; } - - -case $ac_cv_c_inline in - inline | yes) ;; - *) - case $ac_cv_c_inline in - no) ac_val=;; - *) ac_val=$ac_cv_c_inline;; - esac - cat >>confdefs.h <<_ACEOF -#ifndef __cplusplus -#define inline $ac_val -#endif -_ACEOF - ;; -esac - - -saved_CFLAGS="$CFLAGS"; -c99_init=no -if test x"$c99_init" = x"no"; then - { $as_echo "$as_me:$LINENO: checking for C99 designated initializers" >&5 -$as_echo_n "checking for C99 designated initializers... " >&6; } - CFLAGS="$saved_CFLAGS"; - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ - struct foo {int x;char y;}; - struct foo bar = { .y = 'X', .x = 1 }; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; }; c99_init=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -if test x"$c99_init" = x"no"; then - { $as_echo "$as_me:$LINENO: checking for C99 designated initializers with -AC99" >&5 -$as_echo_n "checking for C99 designated initializers with -AC99... " >&6; } - CFLAGS="$saved_CFLAGS -AC99"; - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ - struct foo {int x;char y;}; - struct foo bar = { .y = 'X', .x = 1 }; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; }; c99_init=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -if test x"$c99_init" = x"no"; then - { $as_echo "$as_me:$LINENO: checking for C99 designated initializers with -qlanglvl=extc99" >&5 -$as_echo_n "checking for C99 designated initializers with -qlanglvl=extc99... " >&6; } - CFLAGS="$saved_CFLAGS -qlanglvl=extc99"; - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ - struct foo {int x;char y;}; - struct foo bar = { .y = 'X', .x = 1 }; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; }; c99_init=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -if test x"$c99_init" = x"no"; then - { $as_echo "$as_me:$LINENO: checking for C99 designated initializers with -qlanglvl=stdc99" >&5 -$as_echo_n "checking for C99 designated initializers with -qlanglvl=stdc99... " >&6; } - CFLAGS="$saved_CFLAGS -qlanglvl=stdc99"; - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ - struct foo {int x;char y;}; - struct foo bar = { .y = 'X', .x = 1 }; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; }; c99_init=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -if test x"$c99_init" = x"no"; then - { $as_echo "$as_me:$LINENO: checking for C99 designated initializers with -c99" >&5 -$as_echo_n "checking for C99 designated initializers with -c99... " >&6; } - CFLAGS="$saved_CFLAGS -c99" - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ - struct foo {int x;char y;}; - struct foo bar = { .y = 'X', .x = 1 }; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; }; c99_init=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -if test "`uname`" = "HP-UX"; then - if test "$ac_cv_c_compiler_gnu" = no; then - # special override for broken HP-UX compiler - I can't find a way to test - # this properly (its a compiler bug) - CFLAGS="$CFLAGS -AC99"; - c99_init=yes; - fi -fi - -if test x"$c99_init" = x"yes"; then - saved_CFLAGS="" - -else - CFLAGS="$saved_CFLAGS" - saved_CFLAGS="" - { $as_echo "$as_me:$LINENO: WARNING: c99 structure initializer are not supported" >&5 -$as_echo "$as_me: WARNING: c99 structure initializer are not supported" >&2;} -fi - - -# Find a good install program. We prefer a C program (faster), -# so one script is as good as another. But avoid the broken or -# incompatible versions: -# SysV /etc/install, /usr/sbin/install -# SunOS /usr/etc/install -# IRIX /sbin/install -# AIX /bin/install -# AmigaOS /C/install, which installs bootblocks on floppy discs -# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag -# AFS /usr/afsws/bin/install, which mishandles nonexistent args -# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" -# OS/2's system install, which has a completely different semantic -# ./install, which can be erroneously created by make from ./install.sh. -# Reject install programs that cannot install multiple files. -{ $as_echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5 -$as_echo_n "checking for a BSD-compatible install... " >&6; } -if test -z "$INSTALL"; then -if test "${ac_cv_path_install+set}" = set; then - $as_echo_n "(cached) " >&6 -else - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - # Account for people who put trailing slashes in PATH elements. -case $as_dir/ in - ./ | .// | /cC/* | \ - /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ - ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \ - /usr/ucb/* ) ;; - *) - # OSF1 and SCO ODT 3.0 have their own names for install. - # Don't use installbsd from OSF since it installs stuff as root - # by default. - for ac_prog in ginstall scoinst install; do - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then - if test $ac_prog = install && - grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # AIX install. It has an incompatible calling convention. - : - elif test $ac_prog = install && - grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then - # program-specific install script used by HP pwplus--don't use. - : - else - rm -rf conftest.one conftest.two conftest.dir - echo one > conftest.one - echo two > conftest.two - mkdir conftest.dir - if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && - test -s conftest.one && test -s conftest.two && - test -s conftest.dir/conftest.one && - test -s conftest.dir/conftest.two - then - ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" - break 3 - fi - fi - fi - done - done - ;; -esac - -done -IFS=$as_save_IFS - -rm -rf conftest.one conftest.two conftest.dir - -fi - if test "${ac_cv_path_install+set}" = set; then - INSTALL=$ac_cv_path_install - else - # As a last resort, use the slow shell script. Don't cache a - # value for INSTALL within a source directory, because that will - # break other packages using the cache if that directory is - # removed, or if the value is a relative name. - INSTALL=$ac_install_sh - fi -fi -{ $as_echo "$as_me:$LINENO: result: $INSTALL" >&5 -$as_echo "$INSTALL" >&6; } - -# Use test -z because SunOS4 sh mishandles braces in ${var-val}. -# It thinks the first close brace ends the variable substitution. -test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' - -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' - -test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' - - -{ $as_echo "$as_me:$LINENO: checking for library containing strerror" >&5 -$as_echo_n "checking for library containing strerror... " >&6; } -if test "${ac_cv_search_strerror+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char strerror (); -int -main () -{ -return strerror (); - ; - return 0; -} -_ACEOF -for ac_lib in '' cposix; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_search_strerror=$ac_res -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext - if test "${ac_cv_search_strerror+set}" = set; then - break -fi -done -if test "${ac_cv_search_strerror+set}" = set; then - : -else - ac_cv_search_strerror=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_search_strerror" >&5 -$as_echo "$ac_cv_search_strerror" >&6; } -ac_res=$ac_cv_search_strerror -if test "$ac_res" != no; then - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -fi - - - - - - cat >>confdefs.h <<\EOF -#ifndef _XOPEN_SOURCE_EXTENDED -#define _XOPEN_SOURCE_EXTENDED 1 -#endif -EOF - - -# Check whether --enable-largefile was given. -if test "${enable_largefile+set}" = set; then - enableval=$enable_largefile; -fi - -if test "$enable_largefile" != no; then - - { $as_echo "$as_me:$LINENO: checking for special C compiler options needed for large files" >&5 -$as_echo_n "checking for special C compiler options needed for large files... " >&6; } -if test "${ac_cv_sys_largefile_CC+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_sys_largefile_CC=no - if test "$GCC" != yes; then - ac_save_CC=$CC - while :; do - # IRIX 6.2 and later do not support large files by default, - # so use the C compiler's -n32 option if that helps. - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - /* Check that off_t can represent 2**63 - 1 correctly. - We can't simply define LARGE_OFF_T to be 9223372036854775807, - since some C++ compilers masquerading as C compilers - incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) - int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; -int -main () -{ - - ; - return 0; -} -_ACEOF - rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext - CC="$CC -n32" - rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_sys_largefile_CC=' -n32'; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext - break - done - CC=$ac_save_CC - rm -f conftest.$ac_ext - fi -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sys_largefile_CC" >&5 -$as_echo "$ac_cv_sys_largefile_CC" >&6; } - if test "$ac_cv_sys_largefile_CC" != no; then - CC=$CC$ac_cv_sys_largefile_CC - fi - - { $as_echo "$as_me:$LINENO: checking for _FILE_OFFSET_BITS value needed for large files" >&5 -$as_echo_n "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; } -if test "${ac_cv_sys_file_offset_bits+set}" = set; then - $as_echo_n "(cached) " >&6 -else - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - /* Check that off_t can represent 2**63 - 1 correctly. - We can't simply define LARGE_OFF_T to be 9223372036854775807, - since some C++ compilers masquerading as C compilers - incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) - int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_sys_file_offset_bits=no; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#define _FILE_OFFSET_BITS 64 -#include - /* Check that off_t can represent 2**63 - 1 correctly. - We can't simply define LARGE_OFF_T to be 9223372036854775807, - since some C++ compilers masquerading as C compilers - incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) - int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_sys_file_offset_bits=64; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - ac_cv_sys_file_offset_bits=unknown - break -done -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sys_file_offset_bits" >&5 -$as_echo "$ac_cv_sys_file_offset_bits" >&6; } -case $ac_cv_sys_file_offset_bits in #( - no | unknown) ;; - *) -cat >>confdefs.h <<_ACEOF -#define _FILE_OFFSET_BITS $ac_cv_sys_file_offset_bits -_ACEOF -;; -esac -rm -rf conftest* - if test $ac_cv_sys_file_offset_bits = unknown; then - { $as_echo "$as_me:$LINENO: checking for _LARGE_FILES value needed for large files" >&5 -$as_echo_n "checking for _LARGE_FILES value needed for large files... " >&6; } -if test "${ac_cv_sys_large_files+set}" = set; then - $as_echo_n "(cached) " >&6 -else - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - /* Check that off_t can represent 2**63 - 1 correctly. - We can't simply define LARGE_OFF_T to be 9223372036854775807, - since some C++ compilers masquerading as C compilers - incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) - int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_sys_large_files=no; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#define _LARGE_FILES 1 -#include - /* Check that off_t can represent 2**63 - 1 correctly. - We can't simply define LARGE_OFF_T to be 9223372036854775807, - since some C++ compilers masquerading as C compilers - incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) - int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]; -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_sys_large_files=1; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - ac_cv_sys_large_files=unknown - break -done -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sys_large_files" >&5 -$as_echo "$ac_cv_sys_large_files" >&6; } -case $ac_cv_sys_large_files in #( - no | unknown) ;; - *) -cat >>confdefs.h <<_ACEOF -#define _LARGE_FILES $ac_cv_sys_large_files -_ACEOF -;; -esac -rm -rf conftest* - fi -fi - - -case "$host_os" in - *irix6*) cat >> confdefs.h <<\EOF -#include -EOF - - ;; - *hpux*) - # mmap on HPUX is completely broken... - -cat >>confdefs.h <<\_ACEOF -#define MMAP_BLACKLIST 1 -_ACEOF - - if test "`uname -r`" = "B.11.00" -o "`uname -r`" = "B.11.11"; then - { $as_echo "$as_me:$LINENO: WARNING: Enabling HPUX 11.00/11.11 header bug workaround" >&5 -$as_echo "$as_me: WARNING: Enabling HPUX 11.00/11.11 header bug workaround" >&2;} - CFLAGS="$CFLAGS -Dpread=pread64 -Dpwrite=pwrite64" - fi - if test "`uname -r`" = "B.11.23"; then - { $as_echo "$as_me:$LINENO: WARNING: Enabling HPUX 11.23 machine/sys/getppdp.h bug workaround" >&5 -$as_echo "$as_me: WARNING: Enabling HPUX 11.23 machine/sys/getppdp.h bug workaround" >&2;} - CFLAGS="$CFLAGS -D_MACHINE_SYS_GETPPDP_INCLUDED" - fi - ;; - *aix*) - -cat >>confdefs.h <<\_ACEOF -#define BROKEN_STRNDUP 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define BROKEN_STRNLEN 1 -_ACEOF - - if test "${GCC}" != "yes"; then - ## for funky AIX compiler using strncpy() - CFLAGS="$CFLAGS -D_LINUX_SOURCE_COMPAT -qmaxmem=32000" - fi - ;; - *osf*) - # this brings in socklen_t - - - - - cat >>confdefs.h <<\EOF -#ifndef _XOPEN_SOURCE -#define _XOPEN_SOURCE 600 -#endif -EOF - - - - - - cat >>confdefs.h <<\EOF -#ifndef _OSF_SOURCE -#define _OSF_SOURCE 1 -#endif -EOF - - ;; - # - # VOS may need to have POSIX support and System V compatibility enabled. - # - *vos*) - case "$CFLAGS" in - *-D_POSIX_C_SOURCE*);; - *) - CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112L" - -cat >>confdefs.h <<\_ACEOF -#define _POSIX_C_SOURCE 200112L -_ACEOF - - ;; - esac - case "$CFLAGS" in - *-D_SYSV*|*-D_SVID_SOURCE*);; - *) - CFLAGS="$CFLAGS -D_SYSV" - -cat >>confdefs.h <<\_ACEOF -#define _SYSV 1 -_ACEOF - - ;; - esac - ;; -esac - - - - -for ac_header in standards.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -# Solaris needs HAVE_LONG_LONG defined -{ $as_echo "$as_me:$LINENO: checking for long long" >&5 -$as_echo_n "checking for long long... " >&6; } -if test "${ac_cv_type_long_long+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_long_long=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (long long)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((long long))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_long_long=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_long_long" >&5 -$as_echo "$ac_cv_type_long_long" >&6; } -if test "x$ac_cv_type_long_long" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_LONG_LONG 1 -_ACEOF - - -fi - - -# The cast to long int works around a bug in the HP C Compiler -# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects -# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. -# This bug is HP SR number 8606223364. -{ $as_echo "$as_me:$LINENO: checking size of int" >&5 -$as_echo_n "checking size of int... " >&6; } -if test "${ac_cv_sizeof_int+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (int))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (int))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (int))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (int))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo= ac_hi= -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (int))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr '(' $ac_mid ')' + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_int=$ac_lo;; -'') if test "$ac_cv_type_int" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (int) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (int) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_int=0 - fi ;; -esac -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -static long int longval () { return (long int) (sizeof (int)); } -static unsigned long int ulongval () { return (long int) (sizeof (int)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - return 1; - if (((long int) (sizeof (int))) < 0) - { - long int i = longval (); - if (i != ((long int) (sizeof (int)))) - return 1; - fprintf (f, "%ld", i); - } - else - { - unsigned long int i = ulongval (); - if (i != ((long int) (sizeof (int)))) - return 1; - fprintf (f, "%lu", i); - } - /* Do not output a trailing newline, as this causes \r\n confusion - on some platforms. */ - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_int=`cat conftest.val` -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -if test "$ac_cv_type_int" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (int) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (int) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_int=0 - fi -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.val -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sizeof_int" >&5 -$as_echo "$ac_cv_sizeof_int" >&6; } - - - -cat >>confdefs.h <<_ACEOF -#define SIZEOF_INT $ac_cv_sizeof_int -_ACEOF - - -# The cast to long int works around a bug in the HP C Compiler -# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects -# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. -# This bug is HP SR number 8606223364. -{ $as_echo "$as_me:$LINENO: checking size of char" >&5 -$as_echo_n "checking size of char... " >&6; } -if test "${ac_cv_sizeof_char+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (char))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (char))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (char))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (char))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo= ac_hi= -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (char))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr '(' $ac_mid ')' + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_char=$ac_lo;; -'') if test "$ac_cv_type_char" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (char) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (char) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_char=0 - fi ;; -esac -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -static long int longval () { return (long int) (sizeof (char)); } -static unsigned long int ulongval () { return (long int) (sizeof (char)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - return 1; - if (((long int) (sizeof (char))) < 0) - { - long int i = longval (); - if (i != ((long int) (sizeof (char)))) - return 1; - fprintf (f, "%ld", i); - } - else - { - unsigned long int i = ulongval (); - if (i != ((long int) (sizeof (char)))) - return 1; - fprintf (f, "%lu", i); - } - /* Do not output a trailing newline, as this causes \r\n confusion - on some platforms. */ - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_char=`cat conftest.val` -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -if test "$ac_cv_type_char" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (char) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (char) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_char=0 - fi -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.val -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sizeof_char" >&5 -$as_echo "$ac_cv_sizeof_char" >&6; } - - - -cat >>confdefs.h <<_ACEOF -#define SIZEOF_CHAR $ac_cv_sizeof_char -_ACEOF - - -# The cast to long int works around a bug in the HP C Compiler -# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects -# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. -# This bug is HP SR number 8606223364. -{ $as_echo "$as_me:$LINENO: checking size of short" >&5 -$as_echo_n "checking size of short... " >&6; } -if test "${ac_cv_sizeof_short+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (short))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (short))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (short))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (short))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo= ac_hi= -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (short))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr '(' $ac_mid ')' + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_short=$ac_lo;; -'') if test "$ac_cv_type_short" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (short) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (short) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_short=0 - fi ;; -esac -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -static long int longval () { return (long int) (sizeof (short)); } -static unsigned long int ulongval () { return (long int) (sizeof (short)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - return 1; - if (((long int) (sizeof (short))) < 0) - { - long int i = longval (); - if (i != ((long int) (sizeof (short)))) - return 1; - fprintf (f, "%ld", i); - } - else - { - unsigned long int i = ulongval (); - if (i != ((long int) (sizeof (short)))) - return 1; - fprintf (f, "%lu", i); - } - /* Do not output a trailing newline, as this causes \r\n confusion - on some platforms. */ - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_short=`cat conftest.val` -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -if test "$ac_cv_type_short" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (short) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (short) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_short=0 - fi -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.val -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sizeof_short" >&5 -$as_echo "$ac_cv_sizeof_short" >&6; } - - - -cat >>confdefs.h <<_ACEOF -#define SIZEOF_SHORT $ac_cv_sizeof_short -_ACEOF - - -# The cast to long int works around a bug in the HP C Compiler -# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects -# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. -# This bug is HP SR number 8606223364. -{ $as_echo "$as_me:$LINENO: checking size of long" >&5 -$as_echo_n "checking size of long... " >&6; } -if test "${ac_cv_sizeof_long+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (long))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (long))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (long))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (long))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo= ac_hi= -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (long))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr '(' $ac_mid ')' + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_long=$ac_lo;; -'') if test "$ac_cv_type_long" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (long) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (long) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_long=0 - fi ;; -esac -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -static long int longval () { return (long int) (sizeof (long)); } -static unsigned long int ulongval () { return (long int) (sizeof (long)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - return 1; - if (((long int) (sizeof (long))) < 0) - { - long int i = longval (); - if (i != ((long int) (sizeof (long)))) - return 1; - fprintf (f, "%ld", i); - } - else - { - unsigned long int i = ulongval (); - if (i != ((long int) (sizeof (long)))) - return 1; - fprintf (f, "%lu", i); - } - /* Do not output a trailing newline, as this causes \r\n confusion - on some platforms. */ - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_long=`cat conftest.val` -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -if test "$ac_cv_type_long" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (long) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (long) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_long=0 - fi -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.val -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sizeof_long" >&5 -$as_echo "$ac_cv_sizeof_long" >&6; } - - - -cat >>confdefs.h <<_ACEOF -#define SIZEOF_LONG $ac_cv_sizeof_long -_ACEOF - - -# The cast to long int works around a bug in the HP C Compiler -# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects -# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. -# This bug is HP SR number 8606223364. -{ $as_echo "$as_me:$LINENO: checking size of long long" >&5 -$as_echo_n "checking size of long long... " >&6; } -if test "${ac_cv_sizeof_long_long+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (long long))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (long long))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (long long))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (long long))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo= ac_hi= -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (long long))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr '(' $ac_mid ')' + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_long_long=$ac_lo;; -'') if test "$ac_cv_type_long_long" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (long long) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (long long) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_long_long=0 - fi ;; -esac -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -static long int longval () { return (long int) (sizeof (long long)); } -static unsigned long int ulongval () { return (long int) (sizeof (long long)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - return 1; - if (((long int) (sizeof (long long))) < 0) - { - long int i = longval (); - if (i != ((long int) (sizeof (long long)))) - return 1; - fprintf (f, "%ld", i); - } - else - { - unsigned long int i = ulongval (); - if (i != ((long int) (sizeof (long long)))) - return 1; - fprintf (f, "%lu", i); - } - /* Do not output a trailing newline, as this causes \r\n confusion - on some platforms. */ - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_long_long=`cat conftest.val` -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -if test "$ac_cv_type_long_long" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (long long) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (long long) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_long_long=0 - fi -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.val -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sizeof_long_long" >&5 -$as_echo "$ac_cv_sizeof_long_long" >&6; } - - - -cat >>confdefs.h <<_ACEOF -#define SIZEOF_LONG_LONG $ac_cv_sizeof_long_long -_ACEOF - - - -{ $as_echo "$as_me:$LINENO: checking for int8_t" >&5 -$as_echo_n "checking for int8_t... " >&6; } -if test "${ac_cv_type_int8_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_int8_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (int8_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((int8_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_int8_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_int8_t" >&5 -$as_echo "$ac_cv_type_int8_t" >&6; } -if test "x$ac_cv_type_int8_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define int8_t char -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for uint8_t" >&5 -$as_echo_n "checking for uint8_t... " >&6; } -if test "${ac_cv_type_uint8_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_uint8_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (uint8_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((uint8_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_uint8_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_uint8_t" >&5 -$as_echo "$ac_cv_type_uint8_t" >&6; } -if test "x$ac_cv_type_uint8_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define uint8_t unsigned char -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for int16_t" >&5 -$as_echo_n "checking for int16_t... " >&6; } -if test "${ac_cv_type_int16_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_int16_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (int16_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((int16_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_int16_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_int16_t" >&5 -$as_echo "$ac_cv_type_int16_t" >&6; } -if test "x$ac_cv_type_int16_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define int16_t short -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for uint16_t" >&5 -$as_echo_n "checking for uint16_t... " >&6; } -if test "${ac_cv_type_uint16_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_uint16_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (uint16_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((uint16_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_uint16_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_uint16_t" >&5 -$as_echo "$ac_cv_type_uint16_t" >&6; } -if test "x$ac_cv_type_uint16_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define uint16_t unsigned short -_ACEOF - -fi - - -if test $ac_cv_sizeof_int -eq 4 ; then -{ $as_echo "$as_me:$LINENO: checking for int32_t" >&5 -$as_echo_n "checking for int32_t... " >&6; } -if test "${ac_cv_type_int32_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_int32_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (int32_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((int32_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_int32_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_int32_t" >&5 -$as_echo "$ac_cv_type_int32_t" >&6; } -if test "x$ac_cv_type_int32_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define int32_t int -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for uint32_t" >&5 -$as_echo_n "checking for uint32_t... " >&6; } -if test "${ac_cv_type_uint32_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_uint32_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (uint32_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((uint32_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_uint32_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_uint32_t" >&5 -$as_echo "$ac_cv_type_uint32_t" >&6; } -if test "x$ac_cv_type_uint32_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define uint32_t unsigned int -_ACEOF - -fi - -elif test $ac_cv_size_long -eq 4 ; then -{ $as_echo "$as_me:$LINENO: checking for int32_t" >&5 -$as_echo_n "checking for int32_t... " >&6; } -if test "${ac_cv_type_int32_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_int32_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (int32_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((int32_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_int32_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_int32_t" >&5 -$as_echo "$ac_cv_type_int32_t" >&6; } -if test "x$ac_cv_type_int32_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define int32_t long -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for uint32_t" >&5 -$as_echo_n "checking for uint32_t... " >&6; } -if test "${ac_cv_type_uint32_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_uint32_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (uint32_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((uint32_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_uint32_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_uint32_t" >&5 -$as_echo "$ac_cv_type_uint32_t" >&6; } -if test "x$ac_cv_type_uint32_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define uint32_t unsigned long -_ACEOF - -fi - -else -{ { $as_echo "$as_me:$LINENO: error: LIBREPLACE no 32-bit type found" >&5 -$as_echo "$as_me: error: LIBREPLACE no 32-bit type found" >&2;} - { (exit 1); exit 1; }; } -fi - -{ $as_echo "$as_me:$LINENO: checking for int64_t" >&5 -$as_echo_n "checking for int64_t... " >&6; } -if test "${ac_cv_type_int64_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_int64_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (int64_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((int64_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_int64_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_int64_t" >&5 -$as_echo "$ac_cv_type_int64_t" >&6; } -if test "x$ac_cv_type_int64_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define int64_t long long -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for uint64_t" >&5 -$as_echo_n "checking for uint64_t... " >&6; } -if test "${ac_cv_type_uint64_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_uint64_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (uint64_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((uint64_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_uint64_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_uint64_t" >&5 -$as_echo "$ac_cv_type_uint64_t" >&6; } -if test "x$ac_cv_type_uint64_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define uint64_t unsigned long long -_ACEOF - -fi - - -{ $as_echo "$as_me:$LINENO: checking for size_t" >&5 -$as_echo_n "checking for size_t... " >&6; } -if test "${ac_cv_type_size_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_size_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (size_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((size_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_size_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_size_t" >&5 -$as_echo "$ac_cv_type_size_t" >&6; } -if test "x$ac_cv_type_size_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define size_t unsigned int -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for ssize_t" >&5 -$as_echo_n "checking for ssize_t... " >&6; } -if test "${ac_cv_type_ssize_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_ssize_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (ssize_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((ssize_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_ssize_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_ssize_t" >&5 -$as_echo "$ac_cv_type_ssize_t" >&6; } -if test "x$ac_cv_type_ssize_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define ssize_t int -_ACEOF - -fi - - -# The cast to long int works around a bug in the HP C Compiler -# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects -# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. -# This bug is HP SR number 8606223364. -{ $as_echo "$as_me:$LINENO: checking size of off_t" >&5 -$as_echo_n "checking size of off_t... " >&6; } -if test "${ac_cv_sizeof_off_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (off_t))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (off_t))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (off_t))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (off_t))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo= ac_hi= -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (off_t))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr '(' $ac_mid ')' + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_off_t=$ac_lo;; -'') if test "$ac_cv_type_off_t" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (off_t) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (off_t) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_off_t=0 - fi ;; -esac -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -static long int longval () { return (long int) (sizeof (off_t)); } -static unsigned long int ulongval () { return (long int) (sizeof (off_t)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - return 1; - if (((long int) (sizeof (off_t))) < 0) - { - long int i = longval (); - if (i != ((long int) (sizeof (off_t)))) - return 1; - fprintf (f, "%ld", i); - } - else - { - unsigned long int i = ulongval (); - if (i != ((long int) (sizeof (off_t)))) - return 1; - fprintf (f, "%lu", i); - } - /* Do not output a trailing newline, as this causes \r\n confusion - on some platforms. */ - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_off_t=`cat conftest.val` -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -if test "$ac_cv_type_off_t" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (off_t) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (off_t) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_off_t=0 - fi -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.val -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sizeof_off_t" >&5 -$as_echo "$ac_cv_sizeof_off_t" >&6; } - - - -cat >>confdefs.h <<_ACEOF -#define SIZEOF_OFF_T $ac_cv_sizeof_off_t -_ACEOF - - -# The cast to long int works around a bug in the HP C Compiler -# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects -# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. -# This bug is HP SR number 8606223364. -{ $as_echo "$as_me:$LINENO: checking size of size_t" >&5 -$as_echo_n "checking size of size_t... " >&6; } -if test "${ac_cv_sizeof_size_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (size_t))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (size_t))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (size_t))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (size_t))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo= ac_hi= -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (size_t))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr '(' $ac_mid ')' + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_size_t=$ac_lo;; -'') if test "$ac_cv_type_size_t" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (size_t) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (size_t) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_size_t=0 - fi ;; -esac -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -static long int longval () { return (long int) (sizeof (size_t)); } -static unsigned long int ulongval () { return (long int) (sizeof (size_t)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - return 1; - if (((long int) (sizeof (size_t))) < 0) - { - long int i = longval (); - if (i != ((long int) (sizeof (size_t)))) - return 1; - fprintf (f, "%ld", i); - } - else - { - unsigned long int i = ulongval (); - if (i != ((long int) (sizeof (size_t)))) - return 1; - fprintf (f, "%lu", i); - } - /* Do not output a trailing newline, as this causes \r\n confusion - on some platforms. */ - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_size_t=`cat conftest.val` -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -if test "$ac_cv_type_size_t" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (size_t) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (size_t) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_size_t=0 - fi -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.val -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sizeof_size_t" >&5 -$as_echo "$ac_cv_sizeof_size_t" >&6; } - - - -cat >>confdefs.h <<_ACEOF -#define SIZEOF_SIZE_T $ac_cv_sizeof_size_t -_ACEOF - - -# The cast to long int works around a bug in the HP C Compiler -# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects -# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. -# This bug is HP SR number 8606223364. -{ $as_echo "$as_me:$LINENO: checking size of ssize_t" >&5 -$as_echo_n "checking size of ssize_t... " >&6; } -if test "${ac_cv_sizeof_ssize_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then - # Depending upon the size, compute the lo and hi bounds. -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (ssize_t))) >= 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=0 ac_mid=0 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (ssize_t))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr $ac_mid + 1` - if test $ac_lo -le $ac_mid; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (ssize_t))) < 0)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=-1 ac_mid=-1 - while :; do - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (ssize_t))) >= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_lo=$ac_mid; break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_hi=`expr '(' $ac_mid ')' - 1` - if test $ac_mid -le $ac_hi; then - ac_lo= ac_hi= - break - fi - ac_mid=`expr 2 '*' $ac_mid` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - done -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo= ac_hi= -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -# Binary search between lo and hi bounds. -while test "x$ac_lo" != "x$ac_hi"; do - ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static int test_array [1 - 2 * !(((long int) (sizeof (ssize_t))) <= $ac_mid)]; -test_array [0] = 0 - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_hi=$ac_mid -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_lo=`expr '(' $ac_mid ')' + 1` -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -done -case $ac_lo in -?*) ac_cv_sizeof_ssize_t=$ac_lo;; -'') if test "$ac_cv_type_ssize_t" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (ssize_t) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (ssize_t) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_ssize_t=0 - fi ;; -esac -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -static long int longval () { return (long int) (sizeof (ssize_t)); } -static unsigned long int ulongval () { return (long int) (sizeof (ssize_t)); } -#include -#include -int -main () -{ - - FILE *f = fopen ("conftest.val", "w"); - if (! f) - return 1; - if (((long int) (sizeof (ssize_t))) < 0) - { - long int i = longval (); - if (i != ((long int) (sizeof (ssize_t)))) - return 1; - fprintf (f, "%ld", i); - } - else - { - unsigned long int i = ulongval (); - if (i != ((long int) (sizeof (ssize_t)))) - return 1; - fprintf (f, "%lu", i); - } - /* Do not output a trailing newline, as this causes \r\n confusion - on some platforms. */ - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_sizeof_ssize_t=`cat conftest.val` -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -if test "$ac_cv_type_ssize_t" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot compute sizeof (ssize_t) -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot compute sizeof (ssize_t) -See \`config.log' for more details." >&2;} - { (exit 77); exit 77; }; }; } - else - ac_cv_sizeof_ssize_t=0 - fi -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi -rm -f conftest.val -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_sizeof_ssize_t" >&5 -$as_echo "$ac_cv_sizeof_ssize_t" >&6; } - - - -cat >>confdefs.h <<_ACEOF -#define SIZEOF_SSIZE_T $ac_cv_sizeof_ssize_t -_ACEOF - - - -{ $as_echo "$as_me:$LINENO: checking for intptr_t" >&5 -$as_echo_n "checking for intptr_t... " >&6; } -if test "${ac_cv_type_intptr_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_intptr_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (intptr_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((intptr_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_intptr_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_intptr_t" >&5 -$as_echo "$ac_cv_type_intptr_t" >&6; } -if test "x$ac_cv_type_intptr_t" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_INTPTR_T 1 -_ACEOF - - -fi -{ $as_echo "$as_me:$LINENO: checking for uintptr_t" >&5 -$as_echo_n "checking for uintptr_t... " >&6; } -if test "${ac_cv_type_uintptr_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_uintptr_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (uintptr_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((uintptr_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_uintptr_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_uintptr_t" >&5 -$as_echo "$ac_cv_type_uintptr_t" >&6; } -if test "x$ac_cv_type_uintptr_t" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_UINTPTR_T 1 -_ACEOF - - -fi -{ $as_echo "$as_me:$LINENO: checking for ptrdiff_t" >&5 -$as_echo_n "checking for ptrdiff_t... " >&6; } -if test "${ac_cv_type_ptrdiff_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_ptrdiff_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (ptrdiff_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((ptrdiff_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_ptrdiff_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_ptrdiff_t" >&5 -$as_echo "$ac_cv_type_ptrdiff_t" >&6; } -if test "x$ac_cv_type_ptrdiff_t" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_PTRDIFF_T 1 -_ACEOF - - -fi - - -if test x"$ac_cv_type_long_long" != x"yes";then - { { $as_echo "$as_me:$LINENO: error: LIBREPLACE needs type 'long long'" >&5 -$as_echo "$as_me: error: LIBREPLACE needs type 'long long'" >&2;} - { (exit 1); exit 1; }; } -fi -if test $ac_cv_sizeof_long_long -lt 8;then - { { $as_echo "$as_me:$LINENO: error: LIBREPLACE needs sizeof(long long) >= 8" >&5 -$as_echo "$as_me: error: LIBREPLACE needs sizeof(long long) >= 8" >&2;} - { (exit 1); exit 1; }; } -fi - -############################################ -# check if the compiler can do immediate structures - -{ $as_echo "$as_me:$LINENO: checking for immediate structures" >&5 -$as_echo_n "checking for immediate structures... " >&6; } -if test "${libreplace_cv_immediate_structures+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #include - -int -main () -{ - - typedef struct {unsigned x;} FOOBAR; - #define X_FOOBAR(x) ((FOOBAR) { x }) - #define FOO_ONE X_FOOBAR(1) - FOOBAR f = FOO_ONE; - static const struct { - FOOBAR y; - } f2[] = { - {FOO_ONE} - }; - static const FOOBAR f3[] = {FOO_ONE}; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_immediate_structures=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_immediate_structures=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_immediate_structures" >&5 -$as_echo "$libreplace_cv_immediate_structures" >&6; } -if test x"$libreplace_cv_immediate_structures" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_IMMEDIATE_STRUCTURES 1 -_ACEOF - -fi - - -echo "LIBREPLACE_CC_CHECKS: END" - - - -echo "LIBREPLACE_BROKEN_CHECKS: START" - -libreplacedir="" -libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace" -for d in $libreplacepaths; do - if test -f "$d/replace.c"; then - libreplacedir="$d" - - break; - fi -done -if test x"$libreplacedir" = "x"; then - { { $as_echo "$as_me:$LINENO: error: cannot find libreplace in $libreplacepaths" >&5 -$as_echo "$as_me: error: cannot find libreplace in $libreplacepaths" >&2;} - { (exit 1); exit 1; }; } -fi - -LIBREPLACEOBJ="$libreplacedir/replace.o" - - -LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/snprintf.o" - -{ $as_echo "$as_me:$LINENO: checking for uid_t in sys/types.h" >&5 -$as_echo_n "checking for uid_t in sys/types.h... " >&6; } -if test "${ac_cv_type_uid_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "uid_t" >/dev/null 2>&1; then - ac_cv_type_uid_t=yes -else - ac_cv_type_uid_t=no -fi -rm -f conftest* - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_uid_t" >&5 -$as_echo "$ac_cv_type_uid_t" >&6; } -if test $ac_cv_type_uid_t = no; then - -cat >>confdefs.h <<\_ACEOF -#define uid_t int -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define gid_t int -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for mode_t" >&5 -$as_echo_n "checking for mode_t... " >&6; } -if test "${ac_cv_type_mode_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_mode_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (mode_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((mode_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_mode_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_mode_t" >&5 -$as_echo "$ac_cv_type_mode_t" >&6; } -if test "x$ac_cv_type_mode_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define mode_t int -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for off_t" >&5 -$as_echo_n "checking for off_t... " >&6; } -if test "${ac_cv_type_off_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_off_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (off_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((off_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_off_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_off_t" >&5 -$as_echo "$ac_cv_type_off_t" >&6; } -if test "x$ac_cv_type_off_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define off_t long int -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for size_t" >&5 -$as_echo_n "checking for size_t... " >&6; } -if test "${ac_cv_type_size_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_size_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (size_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((size_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_size_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_size_t" >&5 -$as_echo "$ac_cv_type_size_t" >&6; } -if test "x$ac_cv_type_size_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define size_t unsigned int -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for pid_t" >&5 -$as_echo_n "checking for pid_t... " >&6; } -if test "${ac_cv_type_pid_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_pid_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (pid_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((pid_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_pid_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_pid_t" >&5 -$as_echo "$ac_cv_type_pid_t" >&6; } -if test "x$ac_cv_type_pid_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define pid_t int -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for struct stat.st_rdev" >&5 -$as_echo_n "checking for struct stat.st_rdev... " >&6; } -if test "${ac_cv_member_struct_stat_st_rdev+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static struct stat ac_aggr; -if (ac_aggr.st_rdev) -return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_member_struct_stat_st_rdev=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -static struct stat ac_aggr; -if (sizeof ac_aggr.st_rdev) -return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_member_struct_stat_st_rdev=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_member_struct_stat_st_rdev=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_member_struct_stat_st_rdev" >&5 -$as_echo "$ac_cv_member_struct_stat_st_rdev" >&6; } -if test "x$ac_cv_member_struct_stat_st_rdev" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_STAT_ST_RDEV 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_ST_RDEV 1 -_ACEOF - -fi - - -{ $as_echo "$as_me:$LINENO: checking for ino_t" >&5 -$as_echo_n "checking for ino_t... " >&6; } -if test "${ac_cv_type_ino_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_ino_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (ino_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((ino_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_ino_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_ino_t" >&5 -$as_echo "$ac_cv_type_ino_t" >&6; } -if test "x$ac_cv_type_ino_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define ino_t unsigned -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for loff_t" >&5 -$as_echo_n "checking for loff_t... " >&6; } -if test "${ac_cv_type_loff_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_loff_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (loff_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((loff_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_loff_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_loff_t" >&5 -$as_echo "$ac_cv_type_loff_t" >&6; } -if test "x$ac_cv_type_loff_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define loff_t off_t -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for offset_t" >&5 -$as_echo_n "checking for offset_t... " >&6; } -if test "${ac_cv_type_offset_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_offset_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (offset_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((offset_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_offset_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_offset_t" >&5 -$as_echo "$ac_cv_type_offset_t" >&6; } -if test "x$ac_cv_type_offset_t" = x""yes; then - : -else - -cat >>confdefs.h <<_ACEOF -#define offset_t loff_t -_ACEOF - -fi - - -{ $as_echo "$as_me:$LINENO: checking for working memcmp" >&5 -$as_echo_n "checking for working memcmp... " >&6; } -if test "${ac_cv_func_memcmp_working+set}" = set; then - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then - ac_cv_func_memcmp_working=no -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ - - /* Some versions of memcmp are not 8-bit clean. */ - char c0 = '\100', c1 = '\200', c2 = '\201'; - if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0) - return 1; - - /* The Next x86 OpenStep bug shows up only when comparing 16 bytes - or more and with at least one buffer not starting on a 4-byte boundary. - William Lewis provided this test program. */ - { - char foo[21]; - char bar[21]; - int i; - for (i = 0; i < 4; i++) - { - char *a = foo + i; - char *b = bar + i; - strcpy (a, "--------01111111"); - strcpy (b, "--------10000000"); - if (memcmp (a, b, 16) >= 0) - return 1; - } - return 0; - } - - ; - return 0; -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_cv_func_memcmp_working=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -ac_cv_func_memcmp_working=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_func_memcmp_working" >&5 -$as_echo "$ac_cv_func_memcmp_working" >&6; } -test $ac_cv_func_memcmp_working = no && case " $LIBOBJS " in - *" memcmp.$ac_objext "* ) ;; - *) LIBOBJS="$LIBOBJS memcmp.$ac_objext" - ;; -esac - - - - - - - - - - - - - - - -for ac_func in pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp utime utimes -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - - - -for ac_header in stdbool.h stdint.h sys/select.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - -for ac_header in setjmp.h utime.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -if test "${ac_cv_header_stdint_h+set}" = set; then - { $as_echo "$as_me:$LINENO: checking for stdint.h" >&5 -$as_echo_n "checking for stdint.h... " >&6; } -if test "${ac_cv_header_stdint_h+set}" = set; then - $as_echo_n "(cached) " >&6 -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_stdint_h" >&5 -$as_echo "$ac_cv_header_stdint_h" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking stdint.h usability" >&5 -$as_echo_n "checking stdint.h usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking stdint.h presence" >&5 -$as_echo_n "checking stdint.h presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: stdint.h: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: stdint.h: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdint.h: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: stdint.h: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: stdint.h: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: stdint.h: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdint.h: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: stdint.h: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdint.h: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: stdint.h: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdint.h: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: stdint.h: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdint.h: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: stdint.h: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdint.h: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: stdint.h: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for stdint.h" >&5 -$as_echo_n "checking for stdint.h... " >&6; } -if test "${ac_cv_header_stdint_h+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_header_stdint_h=$ac_header_preproc -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_stdint_h" >&5 -$as_echo "$ac_cv_header_stdint_h" >&6; } - -fi -if test "x$ac_cv_header_stdint_h" = x""yes; then - ac_config_commands="$ac_config_commands rm-stdint.h" - -else - ac_config_commands="$ac_config_commands mk-stdint.h" - - -fi - - - -if test "${ac_cv_header_stdbool_h+set}" = set; then - { $as_echo "$as_me:$LINENO: checking for stdbool.h" >&5 -$as_echo_n "checking for stdbool.h... " >&6; } -if test "${ac_cv_header_stdbool_h+set}" = set; then - $as_echo_n "(cached) " >&6 -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_stdbool_h" >&5 -$as_echo "$ac_cv_header_stdbool_h" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking stdbool.h usability" >&5 -$as_echo_n "checking stdbool.h usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking stdbool.h presence" >&5 -$as_echo_n "checking stdbool.h presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: stdbool.h: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: stdbool.h: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdbool.h: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: stdbool.h: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: stdbool.h: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: stdbool.h: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdbool.h: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: stdbool.h: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdbool.h: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: stdbool.h: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdbool.h: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: stdbool.h: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdbool.h: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: stdbool.h: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: stdbool.h: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: stdbool.h: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for stdbool.h" >&5 -$as_echo_n "checking for stdbool.h... " >&6; } -if test "${ac_cv_header_stdbool_h+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_header_stdbool_h=$ac_header_preproc -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_stdbool_h" >&5 -$as_echo "$ac_cv_header_stdbool_h" >&6; } - -fi -if test "x$ac_cv_header_stdbool_h" = x""yes; then - ac_config_commands="$ac_config_commands rm-stdbool.h" - -else - ac_config_commands="$ac_config_commands mk-stdbool.h" - - -fi - - - - -{ $as_echo "$as_me:$LINENO: checking for bool" >&5 -$as_echo_n "checking for bool... " >&6; } -if test "${ac_cv_type_bool+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_bool=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -$ac_includes_default -#ifdef HAVE_STDBOOL_H -#include -#endif - - -int -main () -{ -if (sizeof (bool)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -$ac_includes_default -#ifdef HAVE_STDBOOL_H -#include -#endif - - -int -main () -{ -if (sizeof ((bool))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_bool=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_bool" >&5 -$as_echo "$ac_cv_type_bool" >&6; } -if test "x$ac_cv_type_bool" = x""yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_BOOL 1 -_ACEOF - -fi - - -{ $as_echo "$as_me:$LINENO: checking for _Bool" >&5 -$as_echo_n "checking for _Bool... " >&6; } -if test "${ac_cv_type__Bool+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type__Bool=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -$ac_includes_default -#ifdef HAVE_STDBOOL_H -#include -#endif - - -int -main () -{ -if (sizeof (_Bool)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -$ac_includes_default -#ifdef HAVE_STDBOOL_H -#include -#endif - - -int -main () -{ -if (sizeof ((_Bool))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type__Bool=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type__Bool" >&5 -$as_echo "$ac_cv_type__Bool" >&6; } -if test "x$ac_cv_type__Bool" = x""yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE__Bool 1 -_ACEOF - -fi - - -{ $as_echo "$as_me:$LINENO: checking for working mmap" >&5 -$as_echo_n "checking for working mmap... " >&6; } -if test "${libreplace_cv_HAVE_MMAP+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -if test "$cross_compiling" = yes; then - libreplace_cv_HAVE_MMAP=cross -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include "$libreplacedir/test/shared_mmap.c" -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_HAVE_MMAP=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_HAVE_MMAP=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_MMAP" >&5 -$as_echo "$libreplace_cv_HAVE_MMAP" >&6; } -if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_MMAP 1 -_ACEOF - -fi - - - - -for ac_header in sys/syslog.h syslog.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - -for ac_header in sys/time.h time.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - -for ac_header in stdarg.h vararg.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - -for ac_header in sys/mount.h mntent.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -for ac_header in stropts.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -for ac_header in unix.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - - - - - - - - -for ac_func in seteuid setresuid setegid setresgid chroot bzero strerror strerror_r -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - - - - - -for ac_func in vsyslog setlinebuf mktime ftruncate chsize rename -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - - - - - - -for ac_func in waitpid wait4 strlcpy strlcat initgroups memmove strdup -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - - - - - - - - -for ac_func in pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - - - - - - -for ac_func in isatty chown lchown link readlink symlink realpath -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - -for ac_func in fdatasync -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - - # if we didn't find it, look in librt (Solaris hides it there...) - { $as_echo "$as_me:$LINENO: checking for fdatasync in -lrt" >&5 -$as_echo_n "checking for fdatasync in -lrt... " >&6; } -if test "${ac_cv_lib_rt_fdatasync+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lrt $LIBS" -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char fdatasync (); -int -main () -{ -return fdatasync (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_lib_rt_fdatasync=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_lib_rt_fdatasync=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_rt_fdatasync" >&5 -$as_echo "$ac_cv_lib_rt_fdatasync" >&6; } -if test "x$ac_cv_lib_rt_fdatasync" = x""yes; then - libreplace_cv_HAVE_FDATASYNC_IN_LIBRT=yes - -cat >>confdefs.h <<\_ACEOF -#define HAVE_FDATASYNC 1 -_ACEOF - -fi - - -fi -done - - -for ac_func in get_current_dir_name -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - { $as_echo "$as_me:$LINENO: checking for setresuid declaration" >&5 -$as_echo_n "checking for setresuid declaration... " >&6; } -if test "${ac_cv_have_setresuid_decl+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ -int i = (int)setresuid - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_setresuid_decl=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_setresuid_decl=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_setresuid_decl" >&5 -$as_echo "$ac_cv_have_setresuid_decl" >&6; } - if test x"$ac_cv_have_setresuid_decl" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SETRESUID_DECL 1 -_ACEOF - - fi - - - { $as_echo "$as_me:$LINENO: checking for setresgid declaration" >&5 -$as_echo_n "checking for setresgid declaration... " >&6; } -if test "${ac_cv_have_setresgid_decl+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ -int i = (int)setresgid - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_setresgid_decl=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_setresgid_decl=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_setresgid_decl" >&5 -$as_echo "$ac_cv_have_setresgid_decl" >&6; } - if test x"$ac_cv_have_setresgid_decl" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SETRESGID_DECL 1 -_ACEOF - - fi - - - { $as_echo "$as_me:$LINENO: checking for errno declaration" >&5 -$as_echo_n "checking for errno declaration... " >&6; } -if test "${ac_cv_have_errno_decl+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ -int i = (int)errno - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_errno_decl=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_errno_decl=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_errno_decl" >&5 -$as_echo "$ac_cv_have_errno_decl" >&6; } - if test x"$ac_cv_have_errno_decl" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_ERRNO_DECL 1 -_ACEOF - - fi - - -{ $as_echo "$as_me:$LINENO: checking for secure mkstemp" >&5 -$as_echo_n "checking for secure mkstemp... " >&6; } -if test "${libreplace_cv_HAVE_SECURE_MKSTEMP+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -if test "$cross_compiling" = yes; then - libreplace_cv_HAVE_SECURE_MKSTEMP=cross -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#include -#include -main() { - struct stat st; - char tpl[20]="/tmp/test.XXXXXX"; - int fd = mkstemp(tpl); - if (fd == -1) exit(1); - unlink(tpl); - if (fstat(fd, &st) != 0) exit(1); - if ((st.st_mode & 0777) != 0600) exit(1); - exit(0); -} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_HAVE_SECURE_MKSTEMP=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_HAVE_SECURE_MKSTEMP=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_SECURE_MKSTEMP" >&5 -$as_echo "$libreplace_cv_HAVE_SECURE_MKSTEMP" >&6; } -if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SECURE_MKSTEMP 1 -_ACEOF - -fi - - - -for ac_header in stdio.h strings.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - -{ $as_echo "$as_me:$LINENO: checking whether snprintf is declared" >&5 -$as_echo_n "checking whether snprintf is declared... " >&6; } -if test "${ac_cv_have_decl_snprintf+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -#ifndef snprintf - (void) snprintf; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_decl_snprintf=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_decl_snprintf=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_snprintf" >&5 -$as_echo "$ac_cv_have_decl_snprintf" >&6; } -if test "x$ac_cv_have_decl_snprintf" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_SNPRINTF 1 -_ACEOF - - -else - cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_SNPRINTF 0 -_ACEOF - - -fi -{ $as_echo "$as_me:$LINENO: checking whether vsnprintf is declared" >&5 -$as_echo_n "checking whether vsnprintf is declared... " >&6; } -if test "${ac_cv_have_decl_vsnprintf+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -#ifndef vsnprintf - (void) vsnprintf; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_decl_vsnprintf=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_decl_vsnprintf=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_vsnprintf" >&5 -$as_echo "$ac_cv_have_decl_vsnprintf" >&6; } -if test "x$ac_cv_have_decl_vsnprintf" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_VSNPRINTF 1 -_ACEOF - - -else - cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_VSNPRINTF 0 -_ACEOF - - -fi -{ $as_echo "$as_me:$LINENO: checking whether asprintf is declared" >&5 -$as_echo_n "checking whether asprintf is declared... " >&6; } -if test "${ac_cv_have_decl_asprintf+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -#ifndef asprintf - (void) asprintf; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_decl_asprintf=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_decl_asprintf=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_asprintf" >&5 -$as_echo "$ac_cv_have_decl_asprintf" >&6; } -if test "x$ac_cv_have_decl_asprintf" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_ASPRINTF 1 -_ACEOF - - -else - cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_ASPRINTF 0 -_ACEOF - - -fi -{ $as_echo "$as_me:$LINENO: checking whether vasprintf is declared" >&5 -$as_echo_n "checking whether vasprintf is declared... " >&6; } -if test "${ac_cv_have_decl_vasprintf+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -#ifndef vasprintf - (void) vasprintf; -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_decl_vasprintf=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_decl_vasprintf=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_vasprintf" >&5 -$as_echo "$ac_cv_have_decl_vasprintf" >&6; } -if test "x$ac_cv_have_decl_vasprintf" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_VASPRINTF 1 -_ACEOF - - -else - cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_VASPRINTF 0 -_ACEOF - - -fi - - - - - - -for ac_func in snprintf vsnprintf asprintf vasprintf -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - -{ $as_echo "$as_me:$LINENO: checking for C99 vsnprintf" >&5 -$as_echo_n "checking for C99 vsnprintf... " >&6; } -if test "${libreplace_cv_HAVE_C99_VSNPRINTF+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -if test "$cross_compiling" = yes; then - libreplace_cv_HAVE_C99_VSNPRINTF=cross -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#include -#include -#include -void foo(const char *format, ...) { - va_list ap; - int len; - char buf[20]; - long long l = 1234567890; - l *= 100; - - va_start(ap, format); - len = vsnprintf(buf, 0, format, ap); - va_end(ap); - if (len != 5) exit(1); - - va_start(ap, format); - len = vsnprintf(0, 0, format, ap); - va_end(ap); - if (len != 5) exit(2); - - if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3); - - if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4); - if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5); - if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6); - if (snprintf(buf, 20, "%s", 0) < 3) exit(7); - - exit(0); -} -main() { foo("hello"); } - -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_HAVE_C99_VSNPRINTF=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_HAVE_C99_VSNPRINTF=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_C99_VSNPRINTF" >&5 -$as_echo "$libreplace_cv_HAVE_C99_VSNPRINTF" >&6; } -if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_C99_VSNPRINTF 1 -_ACEOF - -fi - - -{ $as_echo "$as_me:$LINENO: checking for va_copy" >&5 -$as_echo_n "checking for va_copy... " >&6; } -if test "${libreplace_cv_HAVE_VA_COPY+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -va_list ap1,ap2; -int -main () -{ -va_copy(ap1,ap2); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - libreplace_cv_HAVE_VA_COPY=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_HAVE_VA_COPY=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_VA_COPY" >&5 -$as_echo "$libreplace_cv_HAVE_VA_COPY" >&6; } -if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_VA_COPY 1 -_ACEOF - -fi - -if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then -{ $as_echo "$as_me:$LINENO: checking for __va_copy" >&5 -$as_echo_n "checking for __va_copy... " >&6; } -if test "${libreplace_cv_HAVE___VA_COPY+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -va_list ap1,ap2; -int -main () -{ -__va_copy(ap1,ap2); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - libreplace_cv_HAVE___VA_COPY=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_HAVE___VA_COPY=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE___VA_COPY" >&5 -$as_echo "$libreplace_cv_HAVE___VA_COPY" >&6; } -if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE___VA_COPY 1 -_ACEOF - -fi -fi - -{ $as_echo "$as_me:$LINENO: checking for __FUNCTION__ macro" >&5 -$as_echo_n "checking for __FUNCTION__ macro... " >&6; } -if test "${libreplace_cv_HAVE_FUNCTION_MACRO+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ -printf("%s\n", __FUNCTION__); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_HAVE_FUNCTION_MACRO=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_HAVE_FUNCTION_MACRO=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_FUNCTION_MACRO" >&5 -$as_echo "$libreplace_cv_HAVE_FUNCTION_MACRO" >&6; } -if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_FUNCTION_MACRO 1 -_ACEOF - -else - { $as_echo "$as_me:$LINENO: checking for __func__ macro" >&5 -$as_echo_n "checking for __func__ macro... " >&6; } -if test "${libreplace_cv_HAVE_func_MACRO+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ -printf("%s\n", __func__); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_HAVE_func_MACRO=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_HAVE_func_MACRO=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_func_MACRO" >&5 -$as_echo "$libreplace_cv_HAVE_func_MACRO" >&6; } - if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_func_MACRO 1 -_ACEOF - - fi -fi - - - -for ac_header in sys/param.h limits.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -{ $as_echo "$as_me:$LINENO: checking for comparison_fn_t" >&5 -$as_echo_n "checking for comparison_fn_t... " >&6; } -if test "${ac_cv_type_comparison_fn_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_comparison_fn_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (comparison_fn_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((comparison_fn_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_comparison_fn_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_comparison_fn_t" >&5 -$as_echo "$ac_cv_type_comparison_fn_t" >&6; } -if test "x$ac_cv_type_comparison_fn_t" = x""yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_COMPARISON_FN_T 1 -_ACEOF - -fi - - - - { $as_echo "$as_me:$LINENO: checking for setenv declaration" >&5 -$as_echo_n "checking for setenv declaration... " >&6; } -if test "${ac_cv_have_setenv_decl+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ -int i = (int)setenv - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_setenv_decl=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_setenv_decl=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_setenv_decl" >&5 -$as_echo "$ac_cv_have_setenv_decl" >&6; } - if test x"$ac_cv_have_setenv_decl" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SETENV_DECL 1 -_ACEOF - - fi - - - -for ac_func in setenv unsetenv -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - { $as_echo "$as_me:$LINENO: checking for environ declaration" >&5 -$as_echo_n "checking for environ declaration... " >&6; } -if test "${ac_cv_have_environ_decl+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ -int i = (int)environ - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_environ_decl=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_environ_decl=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_environ_decl" >&5 -$as_echo "$ac_cv_have_environ_decl" >&6; } - if test x"$ac_cv_have_environ_decl" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_ENVIRON_DECL 1 -_ACEOF - - fi - - - -for ac_func in strnlen -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - - - - - -for ac_func in strtoull __strtoull strtouq strtoll __strtoll strtoq -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - -for ac_func in memmem -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - -# this test disabled as we don't actually need __VA_ARGS__ yet -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#define eprintf(...) fprintf(stderr, __VA_ARGS__) -eprintf("bla", "bar"); - -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE__VA_ARGS__MACRO 1 -_ACEOF - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f conftest.err conftest.$ac_ext - - -{ $as_echo "$as_me:$LINENO: checking for sig_atomic_t type" >&5 -$as_echo_n "checking for sig_atomic_t type... " >&6; } -if test "${libreplace_cv_sig_atomic_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#if STDC_HEADERS -#include -#include -#endif -#include -int -main () -{ -sig_atomic_t i = 0 - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_sig_atomic_t=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_sig_atomic_t=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_sig_atomic_t" >&5 -$as_echo "$libreplace_cv_sig_atomic_t" >&6; } -if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SIG_ATOMIC_T_TYPE 1 -_ACEOF - -fi - - -{ $as_echo "$as_me:$LINENO: checking for O_DIRECT flag to open(2)" >&5 -$as_echo_n "checking for O_DIRECT flag to open(2)... " >&6; } -if test "${libreplace_cv_HAVE_OPEN_O_DIRECT+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#ifdef HAVE_FCNTL_H -#include -#endif -int -main () -{ -int fd = open("/dev/null", O_DIRECT); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_HAVE_OPEN_O_DIRECT=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_HAVE_OPEN_O_DIRECT=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_OPEN_O_DIRECT" >&5 -$as_echo "$libreplace_cv_HAVE_OPEN_O_DIRECT" >&6; } -if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_OPEN_O_DIRECT 1 -_ACEOF - -fi - - -{ $as_echo "$as_me:$LINENO: checking that the C compiler understands volatile" >&5 -$as_echo_n "checking that the C compiler understands volatile... " >&6; } -if test "${libreplace_cv_volatile+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ -volatile int i = 0 - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_volatile=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_volatile=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_volatile" >&5 -$as_echo "$libreplace_cv_volatile" >&6; } -if test x"$libreplace_cv_volatile" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_VOLATILE 1 -_ACEOF - -fi - -# filesys - - - - - -ac_header_dirent=no -for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h; do - as_ac_Header=`$as_echo "ac_cv_header_dirent_$ac_hdr" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_hdr that defines DIR" >&5 -$as_echo_n "checking for $ac_hdr that defines DIR... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include <$ac_hdr> - -int -main () -{ -if ((DIR *) 0) -return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - eval "$as_ac_Header=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_Header=no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_hdr" | $as_tr_cpp` 1 -_ACEOF - -ac_header_dirent=$ac_hdr; break -fi - -done -# Two versions of opendir et al. are in -ldir and -lx on SCO Xenix. -if test $ac_header_dirent = dirent.h; then - { $as_echo "$as_me:$LINENO: checking for library containing opendir" >&5 -$as_echo_n "checking for library containing opendir... " >&6; } -if test "${ac_cv_search_opendir+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char opendir (); -int -main () -{ -return opendir (); - ; - return 0; -} -_ACEOF -for ac_lib in '' dir; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_search_opendir=$ac_res -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext - if test "${ac_cv_search_opendir+set}" = set; then - break -fi -done -if test "${ac_cv_search_opendir+set}" = set; then - : -else - ac_cv_search_opendir=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_search_opendir" >&5 -$as_echo "$ac_cv_search_opendir" >&6; } -ac_res=$ac_cv_search_opendir -if test "$ac_res" != no; then - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -fi - -else - { $as_echo "$as_me:$LINENO: checking for library containing opendir" >&5 -$as_echo_n "checking for library containing opendir... " >&6; } -if test "${ac_cv_search_opendir+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char opendir (); -int -main () -{ -return opendir (); - ; - return 0; -} -_ACEOF -for ac_lib in '' x; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_search_opendir=$ac_res -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext - if test "${ac_cv_search_opendir+set}" = set; then - break -fi -done -if test "${ac_cv_search_opendir+set}" = set; then - : -else - ac_cv_search_opendir=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_search_opendir" >&5 -$as_echo "$ac_cv_search_opendir" >&6; } -ac_res=$ac_cv_search_opendir -if test "$ac_res" != no; then - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -fi - -fi - - - - - - - - - -for ac_header in fcntl.h sys/fcntl.h sys/resource.h sys/ioctl.h sys/mode.h sys/filio.h sys/fs/s5param.h sys/filsys.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - - -for ac_header in sys/acl.h acl/libacl.h sys/file.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -# select - -for ac_header in sys/select.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -# time - - -for ac_header in sys/time.h utime.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - -{ $as_echo "$as_me:$LINENO: checking whether time.h and sys/time.h may both be included" >&5 -$as_echo_n "checking whether time.h and sys/time.h may both be included... " >&6; } -if test "${ac_cv_header_time+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#include - -int -main () -{ -if ((struct tm *) 0) -return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_header_time=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_header_time=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_time" >&5 -$as_echo "$ac_cv_header_time" >&6; } -if test $ac_cv_header_time = yes; then - -cat >>confdefs.h <<\_ACEOF -#define TIME_WITH_SYS_TIME 1 -_ACEOF - -fi - - - -for ac_func in utime utimes -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - -# wait -{ $as_echo "$as_me:$LINENO: checking for sys/wait.h that is POSIX.1 compatible" >&5 -$as_echo_n "checking for sys/wait.h that is POSIX.1 compatible... " >&6; } -if test "${ac_cv_header_sys_wait_h+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -#include -#ifndef WEXITSTATUS -# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8) -#endif -#ifndef WIFEXITED -# define WIFEXITED(stat_val) (((stat_val) & 255) == 0) -#endif - -int -main () -{ - int s; - wait (&s); - s = WIFEXITED (s) ? WEXITSTATUS (s) : 1; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_header_sys_wait_h=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_header_sys_wait_h=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_sys_wait_h" >&5 -$as_echo "$ac_cv_header_sys_wait_h" >&6; } -if test $ac_cv_header_sys_wait_h = yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SYS_WAIT_H 1 -_ACEOF - -fi - - -# capability - -for ac_header in sys/capability.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -case "$host_os" in -*linux*) -{ $as_echo "$as_me:$LINENO: checking for broken RedHat 7.2 system header files" >&5 -$as_echo_n "checking for broken RedHat 7.2 system header files... " >&6; } -if test "${libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #ifdef HAVE_SYS_VFS_H - #include - #endif - #ifdef HAVE_SYS_CAPABILITY_H - #include - #endif - -int -main () -{ - - int i; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=no -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=yes - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" >&5 -$as_echo "$libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" >&6; } -if test x"$libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define BROKEN_REDHAT_7_SYSTEM_HEADERS 1 -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking for broken RHEL5 sys/capability.h" >&5 -$as_echo_n "checking for broken RHEL5 sys/capability.h... " >&6; } -if test "${libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #ifdef HAVE_SYS_CAPABILITY_H - #include - #endif - #include - -int -main () -{ - - __s8 i; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=no -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=yes - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER" >&5 -$as_echo "$libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER" >&6; } -if test x"$libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define BROKEN_RHEL5_SYS_CAP_HEADER 1 -_ACEOF - -fi -;; -esac - -# passwd - - - - - - - -for ac_header in grp.h sys/id.h compat.h shadow.h sys/priv.h pwd.h sys/security.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - - -for ac_func in getpwnam_r getpwuid_r getpwent_r -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - { $as_echo "$as_me:$LINENO: checking for getpwent_r declaration" >&5 -$as_echo_n "checking for getpwent_r declaration... " >&6; } -if test "${ac_cv_have_getpwent_r_decl+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #include - #include - -int -main () -{ -int i = (int)getpwent_r - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_getpwent_r_decl=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_getpwent_r_decl=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_getpwent_r_decl" >&5 -$as_echo "$ac_cv_have_getpwent_r_decl" >&6; } - if test x"$ac_cv_have_getpwent_r_decl" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_GETPWENT_R_DECL 1 -_ACEOF - - fi - -{ $as_echo "$as_me:$LINENO: checking for prototype struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)" >&5 -$as_echo_n "checking for prototype struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)... " >&6; } -if test "${ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__int_buflen_+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - $ac_includes_default - - #include - #include - - struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen) - { - - #ifndef HAVE_GETPWENT_R_DECL - #error missing getpwent_r prototype - #endif - return NULL; - - } - -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__int_buflen_=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__int_buflen_=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__int_buflen_" >&5 -$as_echo "$ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__int_buflen_" >&6; } -if test $ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__int_buflen_ = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define SOLARIS_GETPWENT_R 1 -_ACEOF - - -fi - - -{ $as_echo "$as_me:$LINENO: checking for prototype struct passwd *getpwent_r(struct passwd *src, char *buf, size_t buflen)" >&5 -$as_echo_n "checking for prototype struct passwd *getpwent_r(struct passwd *src, char *buf, size_t buflen)... " >&6; } -if test "${ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__size_t_buflen_+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - $ac_includes_default - - #include - #include - - struct passwd *getpwent_r(struct passwd *src, char *buf, size_t buflen) - { - - #ifndef HAVE_GETPWENT_R_DECL - #error missing getpwent_r prototype - #endif - return NULL; - - } - -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__size_t_buflen_=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__size_t_buflen_=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__size_t_buflen_" >&5 -$as_echo "$ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__size_t_buflen_" >&6; } -if test $ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__size_t_buflen_ = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define SOLARIS_GETPWENT_R 1 -_ACEOF - - -fi - - - - - -for ac_func in getgrnam_r getgrgid_r getgrent_r -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - { $as_echo "$as_me:$LINENO: checking for getgrent_r declaration" >&5 -$as_echo_n "checking for getgrent_r declaration... " >&6; } -if test "${ac_cv_have_getgrent_r_decl+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #include - #include - -int -main () -{ -int i = (int)getgrent_r - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_getgrent_r_decl=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_getgrent_r_decl=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_getgrent_r_decl" >&5 -$as_echo "$ac_cv_have_getgrent_r_decl" >&6; } - if test x"$ac_cv_have_getgrent_r_decl" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_GETGRENT_R_DECL 1 -_ACEOF - - fi - -{ $as_echo "$as_me:$LINENO: checking for prototype struct group *getgrent_r(struct group *src, char *buf, int buflen)" >&5 -$as_echo_n "checking for prototype struct group *getgrent_r(struct group *src, char *buf, int buflen)... " >&6; } -if test "${ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__int_buflen_+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - $ac_includes_default - - #include - #include - - struct group *getgrent_r(struct group *src, char *buf, int buflen) - { - - #ifndef HAVE_GETGRENT_R_DECL - #error missing getgrent_r prototype - #endif - return NULL; - - } - -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__int_buflen_=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__int_buflen_=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__int_buflen_" >&5 -$as_echo "$ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__int_buflen_" >&6; } -if test $ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__int_buflen_ = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define SOLARIS_GETGRENT_R 1 -_ACEOF - - -fi - - - -{ $as_echo "$as_me:$LINENO: checking for prototype struct group *getgrent_r(struct group *src, char *buf, size_t buflen)" >&5 -$as_echo_n "checking for prototype struct group *getgrent_r(struct group *src, char *buf, size_t buflen)... " >&6; } -if test "${ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__size_t_buflen_+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - $ac_includes_default - - #include - #include - - struct group *getgrent_r(struct group *src, char *buf, size_t buflen) - { - - #ifndef HAVE_GETGRENT_R_DECL - #error missing getgrent_r prototype - #endif - return NULL; - - } - -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__size_t_buflen_=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__size_t_buflen_=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__size_t_buflen_" >&5 -$as_echo "$ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__size_t_buflen_" >&6; } -if test $ac_cv_c_prototype_struct_group_pgetgrent_r_struct_group_psrc__char_pbuf__size_t_buflen_ = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define SOLARIS_GETGRENT_R 1 -_ACEOF - - -fi - - - -for ac_func in getgrouplist -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - -# locale - - - -for ac_header in ctype.h locale.h langinfo.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -# glob - -for ac_header in fnmatch.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -# shmem - - - -for ac_header in sys/ipc.h sys/mman.h sys/shm.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -# terminal - - - -for ac_header in termios.h termio.h sys/termio.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - -save_LIBS="$LIBS" -LIBS="" - -libreplace_cv_dlfcn=no -{ $as_echo "$as_me:$LINENO: checking for library containing dlopen" >&5 -$as_echo_n "checking for library containing dlopen... " >&6; } -if test "${ac_cv_search_dlopen+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char dlopen (); -int -main () -{ -return dlopen (); - ; - return 0; -} -_ACEOF -for ac_lib in '' dl; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_search_dlopen=$ac_res -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext - if test "${ac_cv_search_dlopen+set}" = set; then - break -fi -done -if test "${ac_cv_search_dlopen+set}" = set; then - : -else - ac_cv_search_dlopen=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_search_dlopen" >&5 -$as_echo "$ac_cv_search_dlopen" >&6; } -ac_res=$ac_cv_search_dlopen -if test "$ac_res" != no; then - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -fi - - - -for ac_header in dlfcn.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - - - -for ac_func in dlopen dlsym dlerror dlclose -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - libreplace_cv_dlfcn=yes -fi -done - - -libreplace_cv_shl=no -{ $as_echo "$as_me:$LINENO: checking for library containing shl_load" >&5 -$as_echo_n "checking for library containing shl_load... " >&6; } -if test "${ac_cv_search_shl_load+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_func_search_save_LIBS=$LIBS -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char shl_load (); -int -main () -{ -return shl_load (); - ; - return 0; -} -_ACEOF -for ac_lib in '' sl; do - if test -z "$ac_lib"; then - ac_res="none required" - else - ac_res=-l$ac_lib - LIBS="-l$ac_lib $ac_func_search_save_LIBS" - fi - rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_search_shl_load=$ac_res -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext - if test "${ac_cv_search_shl_load+set}" = set; then - break -fi -done -if test "${ac_cv_search_shl_load+set}" = set; then - : -else - ac_cv_search_shl_load=no -fi -rm conftest.$ac_ext -LIBS=$ac_func_search_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_search_shl_load" >&5 -$as_echo "$ac_cv_search_shl_load" >&6; } -ac_res=$ac_cv_search_shl_load -if test "$ac_res" != no; then - test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - -fi - - -for ac_header in dl.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - - -for ac_func in shl_load shl_unload shl_findsym -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - libreplace_cv_shl=yes -fi -done - - -{ $as_echo "$as_me:$LINENO: checking for prototype void *dlopen(const char* filename, unsigned int flags)" >&5 -$as_echo_n "checking for prototype void *dlopen(const char* filename, unsigned int flags)... " >&6; } -if test "${ac_cv_c_prototype_void_pdlopen_const_charp_filename__unsigned_int_flags_+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - $ac_includes_default - - #include - - void *dlopen(const char* filename, unsigned int flags) - { - - return 0; - - } - -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - ac_cv_c_prototype_void_pdlopen_const_charp_filename__unsigned_int_flags_=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - ac_cv_c_prototype_void_pdlopen_const_charp_filename__unsigned_int_flags_=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_prototype_void_pdlopen_const_charp_filename__unsigned_int_flags_" >&5 -$as_echo "$ac_cv_c_prototype_void_pdlopen_const_charp_filename__unsigned_int_flags_" >&6; } -if test $ac_cv_c_prototype_void_pdlopen_const_charp_filename__unsigned_int_flags_ = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define DLOPEN_TAKES_UNSIGNED_FLAGS 1 -_ACEOF - - -fi - - - -if test x"${libreplace_cv_dlfcn}" = x"yes";then - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/dlfcn.o" -fi - -LIBDL="$LIBS" - -LIBS="$save_LIBS" - -{ $as_echo "$as_me:$LINENO: checking for getpass" >&5 -$as_echo_n "checking for getpass... " >&6; } -if test "${ac_cv_func_getpass+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define getpass to an innocuous variant, in case declares getpass. - For example, HP-UX 11i declares gettimeofday. */ -#define getpass innocuous_getpass - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char getpass (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef getpass - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char getpass (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_getpass || defined __stub___getpass -choke me -#endif - -int -main () -{ -return getpass (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_func_getpass=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_func_getpass=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_func_getpass" >&5 -$as_echo "$ac_cv_func_getpass" >&6; } -if test "x$ac_cv_func_getpass" = x""yes; then - libreplace_cv_HAVE_GETPASS=yes -fi - -{ $as_echo "$as_me:$LINENO: checking for getpassphrase" >&5 -$as_echo_n "checking for getpassphrase... " >&6; } -if test "${ac_cv_func_getpassphrase+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define getpassphrase to an innocuous variant, in case declares getpassphrase. - For example, HP-UX 11i declares gettimeofday. */ -#define getpassphrase innocuous_getpassphrase - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char getpassphrase (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef getpassphrase - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char getpassphrase (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_getpassphrase || defined __stub___getpassphrase -choke me -#endif - -int -main () -{ -return getpassphrase (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_func_getpassphrase=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_func_getpassphrase=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_func_getpassphrase" >&5 -$as_echo "$ac_cv_func_getpassphrase" >&6; } -if test "x$ac_cv_func_getpassphrase" = x""yes; then - libreplace_cv_HAVE_GETPASSPHRASE=yes -fi - -if test x"$libreplace_cv_HAVE_GETPASS" = x"yes" -a x"$libreplace_cv_HAVE_GETPASSPHRASE" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define REPLACE_GETPASS_BY_GETPASSPHRASE 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define REPLACE_GETPASS 1 -_ACEOF - - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/getpass.o" -else - -{ $as_echo "$as_me:$LINENO: checking whether getpass should be replaced" >&5 -$as_echo_n "checking whether getpass should be replaced... " >&6; } -if test "${libreplace_cv_REPLACE_GETPASS+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -SAVE_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="$CPPFLAGS -I$libreplacedir/" -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include "confdefs.h" -#define NO_CONFIG_H -#include "$libreplacedir/getpass.c" - -int -main () -{ - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_REPLACE_GETPASS=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_REPLACE_GETPASS=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -CPPFLAGS="$SAVE_CPPFLAGS" - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_REPLACE_GETPASS" >&5 -$as_echo "$libreplace_cv_REPLACE_GETPASS" >&6; } -if test x"$libreplace_cv_REPLACE_GETPASS" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define REPLACE_GETPASS 1 -_ACEOF - - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/getpass.o" -fi - -fi - -{ $as_echo "$as_me:$LINENO: checking whether strptime is available and works" >&5 -$as_echo_n "checking whether strptime is available and works... " >&6; } -if test "${libreplace_cv_STRPTIME_OK+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - if test "$cross_compiling" = yes; then - libreplace_cv_STRPTIME_OK="assuming not" -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #define LIBREPLACE_CONFIGURE_TEST_STRPTIME - #include "$libreplacedir/test/strptime.c" - -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_STRPTIME_OK=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_STRPTIME_OK=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_STRPTIME_OK" >&5 -$as_echo "$libreplace_cv_STRPTIME_OK" >&6; } -if test x"$libreplace_cv_STRPTIME_OK" != x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define REPLACE_STRPTIME 1 -_ACEOF - - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/strptime.o" -fi - - - - - -for ac_header in direct.h windows.h winsock2.h ws2tcpip.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -####################################### -# Check for mkdir mode -{ $as_echo "$as_me:$LINENO: checking whether mkdir supports mode" >&5 -$as_echo_n "checking whether mkdir supports mode... " >&6; } -if test "${libreplace_cv_mkdir_has_mode+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #include - #ifdef HAVE_DIRECT_H - #include - #endif -int -main () -{ - - mkdir("foo",0777); - return 0; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_mkdir_has_mode="yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_mkdir_has_mode="no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_mkdir_has_mode" >&5 -$as_echo "$libreplace_cv_mkdir_has_mode" >&6; } - -if test "$libreplace_cv_mkdir_has_mode" = "yes" -then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_MKDIR_MODE 1 -_ACEOF - -fi - - -for ac_func in timegm -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/timegm.o" -fi -done - - -{ $as_echo "$as_me:$LINENO: checking for broken readdir" >&5 -$as_echo_n "checking for broken readdir... " >&6; } -if test "${libreplace_cv_READDIR_NEEDED+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - if test "$cross_compiling" = yes; then - libreplace_cv_READDIR_NEEDED="assuming not" -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#define test_readdir_os2_delete main -#include "$libreplacedir/test/os2_delete.c" -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_READDIR_NEEDED=no -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_READDIR_NEEDED=yes -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_READDIR_NEEDED" >&5 -$as_echo "$libreplace_cv_READDIR_NEEDED" >&6; } - - -for ac_func in dirfd -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - - - { $as_echo "$as_me:$LINENO: checking for dirfd declaration" >&5 -$as_echo_n "checking for dirfd declaration... " >&6; } -if test "${ac_cv_have_dirfd_decl+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -int -main () -{ -int i = (int)dirfd - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_have_dirfd_decl=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_have_dirfd_decl=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_dirfd_decl" >&5 -$as_echo "$ac_cv_have_dirfd_decl" >&6; } - if test x"$ac_cv_have_dirfd_decl" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_DIRFD_DECL 1 -_ACEOF - - fi - - -# -# try to replace with getdirentries() if needed -# -if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then - -for ac_func in getdirentries -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - -{ $as_echo "$as_me:$LINENO: checking for prototype long telldir(const DIR *dir)" >&5 -$as_echo_n "checking for prototype long telldir(const DIR *dir)... " >&6; } -if test "${ac_cv_c_prototype_long_telldir_const_DIR_pdir_+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - $ac_includes_default - - #include - - long telldir(const DIR *dir) - { - - return 0; - - } - -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - ac_cv_c_prototype_long_telldir_const_DIR_pdir_=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - ac_cv_c_prototype_long_telldir_const_DIR_pdir_=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_prototype_long_telldir_const_DIR_pdir_" >&5 -$as_echo "$ac_cv_c_prototype_long_telldir_const_DIR_pdir_" >&6; } -if test $ac_cv_c_prototype_long_telldir_const_DIR_pdir_ = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define TELLDIR_TAKES_CONST_DIR 1 -_ACEOF - - -fi - - - -{ $as_echo "$as_me:$LINENO: checking for prototype int seekdir(DIR *dir, long ofs)" >&5 -$as_echo_n "checking for prototype int seekdir(DIR *dir, long ofs)... " >&6; } -if test "${ac_cv_c_prototype_int_seekdir_DIR_pdir__long_ofs_+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - $ac_includes_default - - #include - - int seekdir(DIR *dir, long ofs) - { - - return 0; - - } - -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - ac_cv_c_prototype_int_seekdir_DIR_pdir__long_ofs_=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - ac_cv_c_prototype_int_seekdir_DIR_pdir__long_ofs_=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_prototype_int_seekdir_DIR_pdir__long_ofs_" >&5 -$as_echo "$ac_cv_c_prototype_int_seekdir_DIR_pdir__long_ofs_" >&6; } -if test $ac_cv_c_prototype_int_seekdir_DIR_pdir__long_ofs_ = yes; then - - -cat >>confdefs.h <<\_ACEOF -#define SEEKDIR_RETURNS_INT 1 -_ACEOF - - -fi - - -{ $as_echo "$as_me:$LINENO: checking for replacing readdir using getdirentries()" >&5 -$as_echo_n "checking for replacing readdir using getdirentries()... " >&6; } -if test "${libreplace_cv_READDIR_GETDIRENTRIES+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - if test "$cross_compiling" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#define _LIBREPLACE_REPLACE_H -#include "$libreplacedir/repdir_getdirentries.c" -#define test_readdir_os2_delete main -#include "$libreplacedir/test/os2_delete.c" -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_READDIR_GETDIRENTRIES=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_READDIR_GETDIRENTRIES=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_READDIR_GETDIRENTRIES" >&5 -$as_echo "$libreplace_cv_READDIR_GETDIRENTRIES" >&6; } -fi -if test x"$libreplace_cv_READDIR_GETDIRENTRIES" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define REPLACE_READDIR 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define REPLACE_READDIR_GETDIRENTRIES 1 -_ACEOF - - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/repdir_getdirentries.o" - libreplace_cv_READDIR_NEEDED=no -fi - -# -# try to replace with getdents() if needed -# -if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then - -for ac_func in getdents -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - -{ $as_echo "$as_me:$LINENO: checking for replacing readdir using getdents()" >&5 -$as_echo_n "checking for replacing readdir using getdents()... " >&6; } -if test "${libreplace_cv_READDIR_GETDENTS+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - if test "$cross_compiling" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#define _LIBREPLACE_REPLACE_H -#error _donot_use_getdents_replacement_anymore -#include "$libreplacedir/repdir_getdents.c" -#define test_readdir_os2_delete main -#include "$libreplacedir/test/os2_delete.c" -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_READDIR_GETDENTS=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_READDIR_GETDENTS=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_READDIR_GETDENTS" >&5 -$as_echo "$libreplace_cv_READDIR_GETDENTS" >&6; } -fi -if test x"$libreplace_cv_READDIR_GETDENTS" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define REPLACE_READDIR 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define REPLACE_READDIR_GETDENTS 1 -_ACEOF - - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/repdir_getdents.o" - libreplace_cv_READDIR_NEEDED=no -fi - -{ $as_echo "$as_me:$LINENO: checking a usable readdir()" >&5 -$as_echo_n "checking a usable readdir()... " >&6; } -if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then - { $as_echo "$as_me:$LINENO: result: no" >&5 -$as_echo "no" >&6; } - { $as_echo "$as_me:$LINENO: WARNING: the provided readdir() is broken" >&5 -$as_echo "$as_me: WARNING: the provided readdir() is broken" >&2;} -else - { $as_echo "$as_me:$LINENO: result: yes" >&5 -$as_echo "yes" >&6; } -fi - -############################################### -# test for where we get crypt() from - -for ac_header in crypt.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - -{ $as_echo "$as_me:$LINENO: checking for library containing crypt" >&5 -$as_echo_n "checking for library containing crypt... " >&6; } -if test "${ac_cv_search_ext_crypt+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -ac_func_search_ext_save_LIBS=$LIBS -ac_cv_search_ext_crypt=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char crypt (); -int -main () -{ -return crypt (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_search_ext_crypt="none required" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -if test "$ac_cv_search_ext_crypt" = no; then - for ac_lib in crypt; do - LIBS="-l$ac_lib $CRYPT_LIBS $ac_func_search_save_ext_LIBS" - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char crypt (); -int -main () -{ -return crypt (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_search_ext_crypt="-l$ac_lib" -break -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext - done -fi -LIBS=$ac_func_search_ext_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_search_ext_crypt" >&5 -$as_echo "$ac_cv_search_ext_crypt" >&6; } -if test "$ac_cv_search_ext_crypt" != no; then - test "$ac_cv_search_ext_crypt" = "none required" || CRYPT_LIBS="$ac_cv_search_ext_crypt $CRYPT_LIBS" - -cat >>confdefs.h <<\_ACEOF -#define HAVE_CRYPT 1 -_ACEOF - -else - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/crypt.o" -fi - - - - - - -for ac_func in printf memset memcpy -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - { { $as_echo "$as_me:$LINENO: error: Required function not found" >&5 -$as_echo "$as_me: error: Required function not found" >&2;} - { (exit 1); exit 1; }; } -fi -done - - -echo "LIBREPLACE_BROKEN_CHECKS: END" - - -#LIBREPLACE_ALL_CHECKS: END" - -CFLAGS="$CFLAGS -I$libreplacedir" - - -echo "LIBREPLACE_NETWORK_CHECKS: START" - - -cat >>confdefs.h <<\_ACEOF -#define LIBREPLACE_NETWORK_CHECKS 1 -_ACEOF - -LIBREPLACE_NETWORK_OBJS="" -LIBREPLACE_NETWORK_LIBS="" - - - - - -for ac_header in sys/socket.h netinet/in.h netdb.h arpa/inet.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -for ac_header in netinet/in_systm.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -for ac_header in netinet/ip.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #include - #ifdef HAVE_NETINET_IN_H - #include - #endif - #ifdef HAVE_NETINET_IN_SYSTM_H - #include - #endif - - -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - eval "$as_ac_Header=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_Header=no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - -for ac_header in netinet/tcp.h netinet/in_ip.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - - -for ac_header in sys/sockio.h sys/un.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -for ac_header in sys/uio.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -{ $as_echo "$as_me:$LINENO: checking for usable net/if.h" >&5 -$as_echo_n "checking for usable net/if.h... " >&6; } -if test "${libreplace_cv_USABLE_NET_IF_H+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - $ac_includes_default - #if HAVE_SYS_SOCKET_H - # include - #endif - #include - int main(void) {return 0;} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - libreplace_cv_USABLE_NET_IF_H=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_USABLE_NET_IF_H=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_USABLE_NET_IF_H" >&5 -$as_echo "$libreplace_cv_USABLE_NET_IF_H" >&6; } -if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_NET_IF_H 1 -_ACEOF - -fi - - - -cv=`echo "socklen_t" | sed 'y%./+- %__p__%'` -{ $as_echo "$as_me:$LINENO: checking for socklen_t" >&5 -$as_echo_n "checking for socklen_t... " >&6; } -if { as_var=ac_cv_type_$cv; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -$ac_includes_default -#include -int -main () -{ -socklen_t foo; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - eval "ac_cv_type_$cv=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "ac_cv_type_$cv=no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_foo=`eval echo \\$ac_cv_type_$cv` -{ $as_echo "$as_me:$LINENO: result: $ac_foo" >&5 -$as_echo "$ac_foo" >&6; } -if test "$ac_foo" = yes; then - ac_tr_hdr=HAVE_`echo socklen_t | sed 'y%abcdefghijklmnopqrstuvwxyz./- %ABCDEFGHIJKLMNOPQRSTUVWXYZ____%'` -if false; then - { $as_echo "$as_me:$LINENO: checking for socklen_t" >&5 -$as_echo_n "checking for socklen_t... " >&6; } -if test "${ac_cv_type_socklen_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_socklen_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (socklen_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((socklen_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_socklen_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_socklen_t" >&5 -$as_echo "$ac_cv_type_socklen_t" >&6; } -if test "x$ac_cv_type_socklen_t" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_SOCKLEN_T 1 -_ACEOF - - -fi - -fi - -cat >>confdefs.h <<_ACEOF -#define $ac_tr_hdr 1 -_ACEOF - -fi - - - -cv=`echo "sa_family_t" | sed 'y%./+- %__p__%'` -{ $as_echo "$as_me:$LINENO: checking for sa_family_t" >&5 -$as_echo_n "checking for sa_family_t... " >&6; } -if { as_var=ac_cv_type_$cv; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -$ac_includes_default -#include -int -main () -{ -sa_family_t foo; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - eval "ac_cv_type_$cv=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "ac_cv_type_$cv=no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_foo=`eval echo \\$ac_cv_type_$cv` -{ $as_echo "$as_me:$LINENO: result: $ac_foo" >&5 -$as_echo "$ac_foo" >&6; } -if test "$ac_foo" = yes; then - ac_tr_hdr=HAVE_`echo sa_family_t | sed 'y%abcdefghijklmnopqrstuvwxyz./- %ABCDEFGHIJKLMNOPQRSTUVWXYZ____%'` -if false; then - { $as_echo "$as_me:$LINENO: checking for sa_family_t" >&5 -$as_echo_n "checking for sa_family_t... " >&6; } -if test "${ac_cv_type_sa_family_t+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_sa_family_t=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (sa_family_t)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((sa_family_t))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_sa_family_t=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_sa_family_t" >&5 -$as_echo "$ac_cv_type_sa_family_t" >&6; } -if test "x$ac_cv_type_sa_family_t" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_SA_FAMILY_T 1 -_ACEOF - - -fi - -fi - -cat >>confdefs.h <<_ACEOF -#define $ac_tr_hdr 1 -_ACEOF - -fi - - - -cv=`echo "struct addrinfo" | sed 'y%./+- %__p__%'` -{ $as_echo "$as_me:$LINENO: checking for struct addrinfo" >&5 -$as_echo_n "checking for struct addrinfo... " >&6; } -if { as_var=ac_cv_type_$cv; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -$ac_includes_default -#include -int -main () -{ -struct addrinfo foo; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - eval "ac_cv_type_$cv=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "ac_cv_type_$cv=no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_foo=`eval echo \\$ac_cv_type_$cv` -{ $as_echo "$as_me:$LINENO: result: $ac_foo" >&5 -$as_echo "$ac_foo" >&6; } -if test "$ac_foo" = yes; then - ac_tr_hdr=HAVE_`echo struct addrinfo | sed 'y%abcdefghijklmnopqrstuvwxyz./- %ABCDEFGHIJKLMNOPQRSTUVWXYZ____%'` -if false; then - { $as_echo "$as_me:$LINENO: checking for struct addrinfo" >&5 -$as_echo_n "checking for struct addrinfo... " >&6; } -if test "${ac_cv_type_struct_addrinfo+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_struct_addrinfo=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (struct addrinfo)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((struct addrinfo))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_struct_addrinfo=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_struct_addrinfo" >&5 -$as_echo "$ac_cv_type_struct_addrinfo" >&6; } -if test "x$ac_cv_type_struct_addrinfo" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_ADDRINFO 1 -_ACEOF - - -fi - -fi - -cat >>confdefs.h <<_ACEOF -#define $ac_tr_hdr 1 -_ACEOF - -fi - - - -cv=`echo "struct sockaddr" | sed 'y%./+- %__p__%'` -{ $as_echo "$as_me:$LINENO: checking for struct sockaddr" >&5 -$as_echo_n "checking for struct sockaddr... " >&6; } -if { as_var=ac_cv_type_$cv; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -$ac_includes_default -#include -int -main () -{ -struct sockaddr foo; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - eval "ac_cv_type_$cv=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "ac_cv_type_$cv=no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_foo=`eval echo \\$ac_cv_type_$cv` -{ $as_echo "$as_me:$LINENO: result: $ac_foo" >&5 -$as_echo "$ac_foo" >&6; } -if test "$ac_foo" = yes; then - ac_tr_hdr=HAVE_`echo struct sockaddr | sed 'y%abcdefghijklmnopqrstuvwxyz./- %ABCDEFGHIJKLMNOPQRSTUVWXYZ____%'` -if false; then - { $as_echo "$as_me:$LINENO: checking for struct sockaddr" >&5 -$as_echo_n "checking for struct sockaddr... " >&6; } -if test "${ac_cv_type_struct_sockaddr+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_struct_sockaddr=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (struct sockaddr)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((struct sockaddr))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_struct_sockaddr=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_struct_sockaddr" >&5 -$as_echo "$ac_cv_type_struct_sockaddr" >&6; } -if test "x$ac_cv_type_struct_sockaddr" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_SOCKADDR 1 -_ACEOF - - -fi - -fi - -cat >>confdefs.h <<_ACEOF -#define $ac_tr_hdr 1 -_ACEOF - -fi - - - -cv=`echo "struct sockaddr_storage" | sed 'y%./+- %__p__%'` -{ $as_echo "$as_me:$LINENO: checking for struct sockaddr_storage" >&5 -$as_echo_n "checking for struct sockaddr_storage... " >&6; } -if { as_var=ac_cv_type_$cv; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -$ac_includes_default - -#include -#include -#include - -int -main () -{ -struct sockaddr_storage foo; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - eval "ac_cv_type_$cv=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "ac_cv_type_$cv=no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_foo=`eval echo \\$ac_cv_type_$cv` -{ $as_echo "$as_me:$LINENO: result: $ac_foo" >&5 -$as_echo "$ac_foo" >&6; } -if test "$ac_foo" = yes; then - ac_tr_hdr=HAVE_`echo struct sockaddr_storage | sed 'y%abcdefghijklmnopqrstuvwxyz./- %ABCDEFGHIJKLMNOPQRSTUVWXYZ____%'` -if false; then - { $as_echo "$as_me:$LINENO: checking for struct sockaddr_storage" >&5 -$as_echo_n "checking for struct sockaddr_storage... " >&6; } -if test "${ac_cv_type_struct_sockaddr_storage+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_struct_sockaddr_storage=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (struct sockaddr_storage)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((struct sockaddr_storage))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_struct_sockaddr_storage=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_struct_sockaddr_storage" >&5 -$as_echo "$ac_cv_type_struct_sockaddr_storage" >&6; } -if test "x$ac_cv_type_struct_sockaddr_storage" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_SOCKADDR_STORAGE 1 -_ACEOF - - -fi - -fi - -cat >>confdefs.h <<_ACEOF -#define $ac_tr_hdr 1 -_ACEOF - -fi - - - -cv=`echo "struct sockaddr_in6" | sed 'y%./+- %__p__%'` -{ $as_echo "$as_me:$LINENO: checking for struct sockaddr_in6" >&5 -$as_echo_n "checking for struct sockaddr_in6... " >&6; } -if { as_var=ac_cv_type_$cv; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -$ac_includes_default - -#include -#include -#include - -int -main () -{ -struct sockaddr_in6 foo; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - eval "ac_cv_type_$cv=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "ac_cv_type_$cv=no" -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -ac_foo=`eval echo \\$ac_cv_type_$cv` -{ $as_echo "$as_me:$LINENO: result: $ac_foo" >&5 -$as_echo "$ac_foo" >&6; } -if test "$ac_foo" = yes; then - ac_tr_hdr=HAVE_`echo struct sockaddr_in6 | sed 'y%abcdefghijklmnopqrstuvwxyz./- %ABCDEFGHIJKLMNOPQRSTUVWXYZ____%'` -if false; then - { $as_echo "$as_me:$LINENO: checking for struct sockaddr_in6" >&5 -$as_echo_n "checking for struct sockaddr_in6... " >&6; } -if test "${ac_cv_type_struct_sockaddr_in6+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_cv_type_struct_sockaddr_in6=no -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof (struct sockaddr_in6)) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -int -main () -{ -if (sizeof ((struct sockaddr_in6))) - return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - : -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_type_struct_sockaddr_in6=yes -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_type_struct_sockaddr_in6" >&5 -$as_echo "$ac_cv_type_struct_sockaddr_in6" >&6; } -if test "x$ac_cv_type_struct_sockaddr_in6" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_SOCKADDR_IN6 1 -_ACEOF - - -fi - -fi - -cat >>confdefs.h <<_ACEOF -#define $ac_tr_hdr 1 -_ACEOF - -fi - - -if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then -{ $as_echo "$as_me:$LINENO: checking for struct sockaddr_storage.ss_family" >&5 -$as_echo_n "checking for struct sockaddr_storage.ss_family... " >&6; } -if test "${ac_cv_member_struct_sockaddr_storage_ss_family+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#include -#include - - -int -main () -{ -static struct sockaddr_storage ac_aggr; -if (ac_aggr.ss_family) -return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_member_struct_sockaddr_storage_ss_family=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#include -#include - - -int -main () -{ -static struct sockaddr_storage ac_aggr; -if (sizeof ac_aggr.ss_family) -return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_member_struct_sockaddr_storage_ss_family=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_member_struct_sockaddr_storage_ss_family=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_member_struct_sockaddr_storage_ss_family" >&5 -$as_echo "$ac_cv_member_struct_sockaddr_storage_ss_family" >&6; } -if test "x$ac_cv_member_struct_sockaddr_storage_ss_family" = x""yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SS_FAMILY 1 -_ACEOF - -fi - - -if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then -{ $as_echo "$as_me:$LINENO: checking for struct sockaddr_storage.__ss_family" >&5 -$as_echo_n "checking for struct sockaddr_storage.__ss_family... " >&6; } -if test "${ac_cv_member_struct_sockaddr_storage___ss_family+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#include -#include - - -int -main () -{ -static struct sockaddr_storage ac_aggr; -if (ac_aggr.__ss_family) -return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_member_struct_sockaddr_storage___ss_family=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#include -#include - - -int -main () -{ -static struct sockaddr_storage ac_aggr; -if (sizeof ac_aggr.__ss_family) -return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_member_struct_sockaddr_storage___ss_family=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_member_struct_sockaddr_storage___ss_family=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_member_struct_sockaddr_storage___ss_family" >&5 -$as_echo "$ac_cv_member_struct_sockaddr_storage___ss_family" >&6; } -if test "x$ac_cv_member_struct_sockaddr_storage___ss_family" = x""yes; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE___SS_FAMILY 1 -_ACEOF - -fi - -fi -fi - -{ $as_echo "$as_me:$LINENO: checking for sin_len in sock" >&5 -$as_echo_n "checking for sin_len in sock... " >&6; } -if test "${libreplace_cv_HAVE_SOCK_SIN_LEN+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#include -#include - -int -main () -{ - -struct sockaddr_in sock; sock.sin_len = sizeof(sock); - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - libreplace_cv_HAVE_SOCK_SIN_LEN=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - libreplace_cv_HAVE_SOCK_SIN_LEN=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_SOCK_SIN_LEN" >&5 -$as_echo "$libreplace_cv_HAVE_SOCK_SIN_LEN" >&6; } -if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SOCK_SIN_LEN 1 -_ACEOF - -fi - -############################################ -# check for unix domain sockets -{ $as_echo "$as_me:$LINENO: checking for unix domain sockets" >&5 -$as_echo_n "checking for unix domain sockets... " >&6; } -if test "${libreplace_cv_HAVE_UNIXSOCKET+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#include -#include -#include -#include - -int -main () -{ - -struct sockaddr_un sunaddr; -sunaddr.sun_family = AF_UNIX; - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - libreplace_cv_HAVE_UNIXSOCKET=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - libreplace_cv_HAVE_UNIXSOCKET=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_UNIXSOCKET" >&5 -$as_echo "$libreplace_cv_HAVE_UNIXSOCKET" >&6; } -if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_UNIXSOCKET 1 -_ACEOF - -fi - - -for ac_func in connect -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - -if test x"$ac_cv_func_connect" = x"no"; then - - - -ac_check_lib_ext_save_LIBS=$LIBS -LIBS="-lnsl_s $LIBREPLACE_NETWORK_LIBS $LIBS" - - - - - { $as_echo "$as_me:$LINENO: checking for connect in -lnsl_s" >&5 -$as_echo_n "checking for connect in -lnsl_s... " >&6; } -if test "${ac_cv_lib_ext_nsl_s_connect+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char connect (); -int -main () -{ -return connect (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_lib_ext_nsl_s_connect=yes; - ac_cv_lib_ext_nsl_s=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_lib_ext_nsl_s_connect=no; - ac_cv_lib_ext_nsl_s=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_ext_nsl_s_connect" >&5 -$as_echo "$ac_cv_lib_ext_nsl_s_connect" >&6; } - if test $ac_cv_lib_ext_nsl_s_connect = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_CONNECT 1 -_ACEOF - -fi - -LIBS=$ac_check_lib_ext_save_LIBS - -if test $ac_cv_lib_ext_nsl_s = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBNSL_S 1 -_ACEOF - - case "$LIBREPLACE_NETWORK_LIBS" in - *-lnsl_s*) - ;; - *) - LIBREPLACE_NETWORK_LIBS="-lnsl_s $LIBREPLACE_NETWORK_LIBS" - ;; - esac - - -fi - - - - -ac_check_lib_ext_save_LIBS=$LIBS -LIBS="-lnsl $LIBREPLACE_NETWORK_LIBS $LIBS" - - - - - { $as_echo "$as_me:$LINENO: checking for connect in -lnsl" >&5 -$as_echo_n "checking for connect in -lnsl... " >&6; } -if test "${ac_cv_lib_ext_nsl_connect+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char connect (); -int -main () -{ -return connect (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_lib_ext_nsl_connect=yes; - ac_cv_lib_ext_nsl=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_lib_ext_nsl_connect=no; - ac_cv_lib_ext_nsl=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_ext_nsl_connect" >&5 -$as_echo "$ac_cv_lib_ext_nsl_connect" >&6; } - if test $ac_cv_lib_ext_nsl_connect = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_CONNECT 1 -_ACEOF - -fi - -LIBS=$ac_check_lib_ext_save_LIBS - -if test $ac_cv_lib_ext_nsl = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBNSL 1 -_ACEOF - - case "$LIBREPLACE_NETWORK_LIBS" in - *-lnsl*) - ;; - *) - LIBREPLACE_NETWORK_LIBS="-lnsl $LIBREPLACE_NETWORK_LIBS" - ;; - esac - - -fi - - - - -ac_check_lib_ext_save_LIBS=$LIBS -LIBS="-lsocket $LIBREPLACE_NETWORK_LIBS $LIBS" - - - - - { $as_echo "$as_me:$LINENO: checking for connect in -lsocket" >&5 -$as_echo_n "checking for connect in -lsocket... " >&6; } -if test "${ac_cv_lib_ext_socket_connect+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char connect (); -int -main () -{ -return connect (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_lib_ext_socket_connect=yes; - ac_cv_lib_ext_socket=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_lib_ext_socket_connect=no; - ac_cv_lib_ext_socket=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_ext_socket_connect" >&5 -$as_echo "$ac_cv_lib_ext_socket_connect" >&6; } - if test $ac_cv_lib_ext_socket_connect = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_CONNECT 1 -_ACEOF - -fi - -LIBS=$ac_check_lib_ext_save_LIBS - -if test $ac_cv_lib_ext_socket = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBSOCKET 1 -_ACEOF - - case "$LIBREPLACE_NETWORK_LIBS" in - *-lsocket*) - ;; - *) - LIBREPLACE_NETWORK_LIBS="-lsocket $LIBREPLACE_NETWORK_LIBS" - ;; - esac - - -fi - - - - -ac_check_lib_ext_save_LIBS=$LIBS -LIBS="-linet $LIBREPLACE_NETWORK_LIBS $LIBS" - - - - - { $as_echo "$as_me:$LINENO: checking for connect in -linet" >&5 -$as_echo_n "checking for connect in -linet... " >&6; } -if test "${ac_cv_lib_ext_inet_connect+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char connect (); -int -main () -{ -return connect (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_lib_ext_inet_connect=yes; - ac_cv_lib_ext_inet=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_lib_ext_inet_connect=no; - ac_cv_lib_ext_inet=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_ext_inet_connect" >&5 -$as_echo "$ac_cv_lib_ext_inet_connect" >&6; } - if test $ac_cv_lib_ext_inet_connect = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_CONNECT 1 -_ACEOF - -fi - -LIBS=$ac_check_lib_ext_save_LIBS - -if test $ac_cv_lib_ext_inet = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBINET 1 -_ACEOF - - case "$LIBREPLACE_NETWORK_LIBS" in - *-linet*) - ;; - *) - LIBREPLACE_NETWORK_LIBS="-linet $LIBREPLACE_NETWORK_LIBS" - ;; - esac - - -fi - - if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" || - test x"$ac_cv_lib_ext_nsl_connect" = x"yes" || - test x"$ac_cv_lib_ext_socket_connect" = x"yes" || - test x"$ac_cv_lib_ext_inet_connect" = x"yes" - then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_CONNECT 1 -_ACEOF - - fi -fi - - -for ac_func in gethostbyname -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - -if test x"$ac_cv_func_gethostbyname" = x"no"; then - - - -ac_check_lib_ext_save_LIBS=$LIBS -LIBS="-lnsl_s $LIBREPLACE_NETWORK_LIBS $LIBS" - - - - - { $as_echo "$as_me:$LINENO: checking for gethostbyname in -lnsl_s" >&5 -$as_echo_n "checking for gethostbyname in -lnsl_s... " >&6; } -if test "${ac_cv_lib_ext_nsl_s_gethostbyname+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char gethostbyname (); -int -main () -{ -return gethostbyname (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_lib_ext_nsl_s_gethostbyname=yes; - ac_cv_lib_ext_nsl_s=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_lib_ext_nsl_s_gethostbyname=no; - ac_cv_lib_ext_nsl_s=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_ext_nsl_s_gethostbyname" >&5 -$as_echo "$ac_cv_lib_ext_nsl_s_gethostbyname" >&6; } - if test $ac_cv_lib_ext_nsl_s_gethostbyname = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_GETHOSTBYNAME 1 -_ACEOF - -fi - -LIBS=$ac_check_lib_ext_save_LIBS - -if test $ac_cv_lib_ext_nsl_s = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBNSL_S 1 -_ACEOF - - case "$LIBREPLACE_NETWORK_LIBS" in - *-lnsl_s*) - ;; - *) - LIBREPLACE_NETWORK_LIBS="-lnsl_s $LIBREPLACE_NETWORK_LIBS" - ;; - esac - - -fi - - - - -ac_check_lib_ext_save_LIBS=$LIBS -LIBS="-lnsl $LIBREPLACE_NETWORK_LIBS $LIBS" - - - - - { $as_echo "$as_me:$LINENO: checking for gethostbyname in -lnsl" >&5 -$as_echo_n "checking for gethostbyname in -lnsl... " >&6; } -if test "${ac_cv_lib_ext_nsl_gethostbyname+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char gethostbyname (); -int -main () -{ -return gethostbyname (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_lib_ext_nsl_gethostbyname=yes; - ac_cv_lib_ext_nsl=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_lib_ext_nsl_gethostbyname=no; - ac_cv_lib_ext_nsl=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_ext_nsl_gethostbyname" >&5 -$as_echo "$ac_cv_lib_ext_nsl_gethostbyname" >&6; } - if test $ac_cv_lib_ext_nsl_gethostbyname = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_GETHOSTBYNAME 1 -_ACEOF - -fi - -LIBS=$ac_check_lib_ext_save_LIBS - -if test $ac_cv_lib_ext_nsl = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBNSL 1 -_ACEOF - - case "$LIBREPLACE_NETWORK_LIBS" in - *-lnsl*) - ;; - *) - LIBREPLACE_NETWORK_LIBS="-lnsl $LIBREPLACE_NETWORK_LIBS" - ;; - esac - - -fi - - - - -ac_check_lib_ext_save_LIBS=$LIBS -LIBS="-lsocket $LIBREPLACE_NETWORK_LIBS $LIBS" - - - - - { $as_echo "$as_me:$LINENO: checking for gethostbyname in -lsocket" >&5 -$as_echo_n "checking for gethostbyname in -lsocket... " >&6; } -if test "${ac_cv_lib_ext_socket_gethostbyname+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char gethostbyname (); -int -main () -{ -return gethostbyname (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_lib_ext_socket_gethostbyname=yes; - ac_cv_lib_ext_socket=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_lib_ext_socket_gethostbyname=no; - ac_cv_lib_ext_socket=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_ext_socket_gethostbyname" >&5 -$as_echo "$ac_cv_lib_ext_socket_gethostbyname" >&6; } - if test $ac_cv_lib_ext_socket_gethostbyname = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_GETHOSTBYNAME 1 -_ACEOF - -fi - -LIBS=$ac_check_lib_ext_save_LIBS - -if test $ac_cv_lib_ext_socket = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBSOCKET 1 -_ACEOF - - case "$LIBREPLACE_NETWORK_LIBS" in - *-lsocket*) - ;; - *) - LIBREPLACE_NETWORK_LIBS="-lsocket $LIBREPLACE_NETWORK_LIBS" - ;; - esac - - -fi - - if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" || - test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" || - test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes" - then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_GETHOSTBYNAME 1 -_ACEOF - - fi -fi - - -for ac_func in if_nametoindex -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -fi -done - -if test x"$ac_cv_func_if_nametoindex" = x"no"; then - - - -ac_check_lib_ext_save_LIBS=$LIBS -LIBS="-lipv6 $LIBREPLACE_NETWORK_LIBS $LIBS" - - - - - { $as_echo "$as_me:$LINENO: checking for if_nametoindex in -lipv6" >&5 -$as_echo_n "checking for if_nametoindex in -lipv6... " >&6; } -if test "${ac_cv_lib_ext_ipv6_if_nametoindex+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char if_nametoindex (); -int -main () -{ -return if_nametoindex (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - ac_cv_lib_ext_ipv6_if_nametoindex=yes; - ac_cv_lib_ext_ipv6=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_lib_ext_ipv6_if_nametoindex=no; - ac_cv_lib_ext_ipv6=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_ext_ipv6_if_nametoindex" >&5 -$as_echo "$ac_cv_lib_ext_ipv6_if_nametoindex" >&6; } - if test $ac_cv_lib_ext_ipv6_if_nametoindex = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_IF_NAMETOINDEX 1 -_ACEOF - -fi - -LIBS=$ac_check_lib_ext_save_LIBS - -if test $ac_cv_lib_ext_ipv6 = yes; then - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBIPV6 1 -_ACEOF - - case "$LIBREPLACE_NETWORK_LIBS" in - *-lipv6*) - ;; - *) - LIBREPLACE_NETWORK_LIBS="-lipv6 $LIBREPLACE_NETWORK_LIBS" - ;; - esac - - -fi - - if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes" - then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_IF_NAMETOINDEX 1 -_ACEOF - - fi -fi - -# The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}" -old_LIBS=$LIBS -LIBS="${LIBREPLACE_NETWORK_LIBS}" -libreplace_SAVE_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="$CPPFLAGS -I$libreplacedir" - - -for ac_func in socketpair -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/socketpair.o" -fi -done - - -{ $as_echo "$as_me:$LINENO: checking for broken inet_ntoa" >&5 -$as_echo_n "checking for broken inet_ntoa... " >&6; } -if test "${libreplace_cv_REPLACE_INET_NTOA+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -if test "$cross_compiling" = yes; then - libreplace_cv_REPLACE_INET_NTOA=cross -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#include -#include -#include -#ifdef HAVE_ARPA_INET_H -#include -#endif -main() { struct in_addr ip; ip.s_addr = 0x12345678; -if (strcmp(inet_ntoa(ip),"18.52.86.120") && - strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } -exit(1);} -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_REPLACE_INET_NTOA=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_REPLACE_INET_NTOA=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_REPLACE_INET_NTOA" >&5 -$as_echo "$libreplace_cv_REPLACE_INET_NTOA" >&6; } - - -for ac_func in inet_ntoa -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - libreplace_cv_REPLACE_INET_NTOA=yes -fi -done - -if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define REPLACE_INET_NTOA 1 -_ACEOF - - LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntoa.o" -fi - - -for ac_func in inet_aton -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_aton.o" -fi -done - - - -for ac_func in inet_ntop -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntop.o" -fi -done - - - -for ac_func in inet_pton -do -as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` -{ $as_echo "$as_me:$LINENO: checking for $ac_func" >&5 -$as_echo_n "checking for $ac_func... " >&6; } -if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined __stub_$ac_func || defined __stub___$ac_func -choke me -#endif - -int -main () -{ -return $ac_func (); - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - eval "$as_ac_var=yes" -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - eval "$as_ac_var=no" -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -ac_res=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -as_val=`eval 'as_val=${'$as_ac_var'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_pton.o" -fi -done - - -{ $as_echo "$as_me:$LINENO: checking for getaddrinfo" >&5 -$as_echo_n "checking for getaddrinfo... " >&6; } -if test "${libreplace_cv_HAVE_GETADDRINFO+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#if STDC_HEADERS -#include -#include -#endif -#include -#include -int -main () -{ - -struct sockaddr sa; -struct addrinfo *ai = NULL; -int ret = getaddrinfo(NULL, NULL, NULL, &ai); -if (ret != 0) { - const char *es = gai_strerror(ret); -} -freeaddrinfo(ai); -ret = getnameinfo(&sa, sizeof(sa), - NULL, 0, - NULL, 0, 0); - - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - libreplace_cv_HAVE_GETADDRINFO=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_HAVE_GETADDRINFO=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_GETADDRINFO" >&5 -$as_echo "$libreplace_cv_HAVE_GETADDRINFO" >&6; } - -if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then - # getaddrinfo is broken on some AIX systems - # see bug 5910, use our replacements if we detect - # a broken system. - if test "$cross_compiling" = yes; then - { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling -See \`config.log' for more details." >&5 -$as_echo "$as_me: error: cannot run test program while cross compiling -See \`config.log' for more details." >&2;} - { (exit 1); exit 1; }; }; } -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #include - #include - #include - #include - int main(int argc, const char *argv[]) - { - struct addrinfo hints = {0,}; - struct addrinfo *ppres; - const char hostname[] = "0.0.0.0"; - hints.ai_socktype = SOCK_STREAM; - hints.ai_family = AF_INET; - hints.ai_flags = - AI_NUMERICHOST|AI_PASSIVE|AI_ADDRCONFIG; - return getaddrinfo(hostname, NULL, &hints, &ppres) != 0 ? 1 : 0; - } -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_HAVE_GETADDRINFO=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_HAVE_GETADDRINFO=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi - -if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_GETADDRINFO 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_GETNAMEINFO 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_FREEADDRINFO 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_GAI_STRERROR 1 -_ACEOF - -else - LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getaddrinfo.o" -fi - - -for ac_header in ifaddrs.h -do -as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - { $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5 -$as_echo_n "checking $ac_header usability... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_header_compiler=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_compiler=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } - -# Is the header present? -{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5 -$as_echo_n "checking $ac_header presence... " >&6; } -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then - ac_header_preproc=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi - -rm -f conftest.err conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in - yes:no: ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - - ;; -esac -{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5 -$as_echo_n "checking for $ac_header... " >&6; } -if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then - $as_echo_n "(cached) " >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -ac_res=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - { $as_echo "$as_me:$LINENO: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } - -fi -as_val=`eval 'as_val=${'$as_ac_Header'} - $as_echo "$as_val"'` - if test "x$as_val" = x""yes; then - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -{ $as_echo "$as_me:$LINENO: checking for struct sockaddr.sa_len" >&5 -$as_echo_n "checking for struct sockaddr.sa_len... " >&6; } -if test "${ac_cv_member_struct_sockaddr_sa_len+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -int -main () -{ -static struct sockaddr ac_aggr; -if (ac_aggr.sa_len) -return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_member_struct_sockaddr_sa_len=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include - -int -main () -{ -static struct sockaddr ac_aggr; -if (sizeof ac_aggr.sa_len) -return 0; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_member_struct_sockaddr_sa_len=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_member_struct_sockaddr_sa_len=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_member_struct_sockaddr_sa_len" >&5 -$as_echo "$ac_cv_member_struct_sockaddr_sa_len" >&6; } -if test "x$ac_cv_member_struct_sockaddr_sa_len" = x""yes; then - -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_SOCKADDR_SA_LEN 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_SOCKADDR_SA_LEN 1 -_ACEOF - -fi - - -{ $as_echo "$as_me:$LINENO: checking for getifaddrs and freeifaddrs" >&5 -$as_echo_n "checking for getifaddrs and freeifaddrs... " >&6; } -if test "${libreplace_cv_HAVE_GETIFADDRS+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include -#if STDC_HEADERS -#include -#include -#endif -#include -#include -#include -#include -#include -int -main () -{ - -struct ifaddrs *ifp = NULL; -int ret = getifaddrs (&ifp); -freeifaddrs(ifp); - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - libreplace_cv_HAVE_GETIFADDRS=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - libreplace_cv_HAVE_GETIFADDRS=no -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_GETIFADDRS" >&5 -$as_echo "$libreplace_cv_HAVE_GETIFADDRS" >&6; } -if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_GETIFADDRS 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_FREEIFADDRS 1 -_ACEOF - - -cat >>confdefs.h <<\_ACEOF -#define HAVE_STRUCT_IFADDRS 1 -_ACEOF - -fi - -################## -# look for a method of finding the list of network interfaces -iface=no; -{ $as_echo "$as_me:$LINENO: checking for iface getifaddrs" >&5 -$as_echo_n "checking for iface getifaddrs... " >&6; } -if test "${libreplace_cv_HAVE_IFACE_GETIFADDRS+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -if test "$cross_compiling" = yes; then - libreplace_cv_HAVE_IFACE_GETIFADDRS=cross -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#define HAVE_IFACE_GETIFADDRS 1 -#define NO_CONFIG_H 1 -#define AUTOCONF_TEST 1 -#define SOCKET_WRAPPER_NOT_REPLACE -#include "$libreplacedir/replace.c" -#include "$libreplacedir/inet_ntop.c" -#include "$libreplacedir/snprintf.c" -#include "$libreplacedir/getifaddrs.c" -#define getifaddrs_test main -#include "$libreplacedir/test/getifaddrs.c" -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_HAVE_IFACE_GETIFADDRS=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_HAVE_IFACE_GETIFADDRS=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_IFACE_GETIFADDRS" >&5 -$as_echo "$libreplace_cv_HAVE_IFACE_GETIFADDRS" >&6; } -if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then - iface=yes; -cat >>confdefs.h <<\_ACEOF -#define HAVE_IFACE_GETIFADDRS 1 -_ACEOF - -else - LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getifaddrs.o" -fi - - -if test $iface = no; then -{ $as_echo "$as_me:$LINENO: checking for iface AIX" >&5 -$as_echo_n "checking for iface AIX... " >&6; } -if test "${libreplace_cv_HAVE_IFACE_AIX+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -if test "$cross_compiling" = yes; then - libreplace_cv_HAVE_IFACE_AIX=cross -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#define HAVE_IFACE_AIX 1 -#define NO_CONFIG_H 1 -#define AUTOCONF_TEST 1 -#undef _XOPEN_SOURCE_EXTENDED -#define SOCKET_WRAPPER_NOT_REPLACE -#include "$libreplacedir/replace.c" -#include "$libreplacedir/inet_ntop.c" -#include "$libreplacedir/snprintf.c" -#include "$libreplacedir/getifaddrs.c" -#define getifaddrs_test main -#include "$libreplacedir/test/getifaddrs.c" -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_HAVE_IFACE_AIX=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_HAVE_IFACE_AIX=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_IFACE_AIX" >&5 -$as_echo "$libreplace_cv_HAVE_IFACE_AIX" >&6; } -if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then - iface=yes; -cat >>confdefs.h <<\_ACEOF -#define HAVE_IFACE_AIX 1 -_ACEOF - -fi -fi - - -if test $iface = no; then -{ $as_echo "$as_me:$LINENO: checking for iface ifconf" >&5 -$as_echo_n "checking for iface ifconf... " >&6; } -if test "${libreplace_cv_HAVE_IFACE_IFCONF+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -if test "$cross_compiling" = yes; then - libreplace_cv_HAVE_IFACE_IFCONF=cross -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#define HAVE_IFACE_IFCONF 1 -#define NO_CONFIG_H 1 -#define AUTOCONF_TEST 1 -#define SOCKET_WRAPPER_NOT_REPLACE -#include "$libreplacedir/replace.c" -#include "$libreplacedir/inet_ntop.c" -#include "$libreplacedir/snprintf.c" -#include "$libreplacedir/getifaddrs.c" -#define getifaddrs_test main -#include "$libreplacedir/test/getifaddrs.c" -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_HAVE_IFACE_IFCONF=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_HAVE_IFACE_IFCONF=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_IFACE_IFCONF" >&5 -$as_echo "$libreplace_cv_HAVE_IFACE_IFCONF" >&6; } -if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then - iface=yes; -cat >>confdefs.h <<\_ACEOF -#define HAVE_IFACE_IFCONF 1 -_ACEOF - -fi -fi - -if test $iface = no; then -{ $as_echo "$as_me:$LINENO: checking for iface ifreq" >&5 -$as_echo_n "checking for iface ifreq... " >&6; } -if test "${libreplace_cv_HAVE_IFACE_IFREQ+set}" = set; then - $as_echo_n "(cached) " >&6 -else - -if test "$cross_compiling" = yes; then - libreplace_cv_HAVE_IFACE_IFREQ=cross -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#define HAVE_IFACE_IFREQ 1 -#define NO_CONFIG_H 1 -#define AUTOCONF_TEST 1 -#define SOCKET_WRAPPER_NOT_REPLACE -#include "$libreplacedir/replace.c" -#include "$libreplacedir/inet_ntop.c" -#include "$libreplacedir/snprintf.c" -#include "$libreplacedir/getifaddrs.c" -#define getifaddrs_test main -#include "$libreplacedir/test/getifaddrs.c" -_ACEOF -rm -f conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { ac_try='./conftest$ac_exeext' - { (case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - libreplace_cv_HAVE_IFACE_IFREQ=yes -else - $as_echo "$as_me: program exited with status $ac_status" >&5 -$as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -( exit $ac_status ) -libreplace_cv_HAVE_IFACE_IFREQ=no -fi -rm -rf conftest.dSYM -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext -fi - - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_IFACE_IFREQ" >&5 -$as_echo "$libreplace_cv_HAVE_IFACE_IFREQ" >&6; } -if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then - iface=yes; -cat >>confdefs.h <<\_ACEOF -#define HAVE_IFACE_IFREQ 1 -_ACEOF - -fi -fi - -{ $as_echo "$as_me:$LINENO: checking for IPV6_V6ONLY support" >&5 -$as_echo_n "checking for IPV6_V6ONLY support... " >&6; } -if test "${libreplace_cv_HAVE_IPV6_V6ONLY+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include /* for NULL */ -#include -#include -#include -#include - -int -main () -{ - -#ifndef IPV6_V6ONLY -#error no IPV6_V6ONLY -#endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - libreplace_cv_HAVE_IPV6_V6ONLY=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - libreplace_cv_HAVE_IPV6_V6ONLY=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_IPV6_V6ONLY" >&5 -$as_echo "$libreplace_cv_HAVE_IPV6_V6ONLY" >&6; } -if test x"$libreplace_cv_HAVE_IPV6_V6ONLY" != x"yes"; then - { $as_echo "$as_me:$LINENO: checking for IPV6_V6ONLY in linux/in6.h" >&5 -$as_echo_n "checking for IPV6_V6ONLY in linux/in6.h... " >&6; } -if test "${libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #include - -int -main () -{ - - #if (IPV6_V6ONLY != 26) - #error no linux IPV6_V6ONLY - #endif - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - - libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26=no - -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26" >&5 -$as_echo "$libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26" >&6; } - if test x"$libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_LINUX_IPV6_V6ONLY_26 1 -_ACEOF - - fi -fi - -{ $as_echo "$as_me:$LINENO: checking for ipv6 support" >&5 -$as_echo_n "checking for ipv6 support... " >&6; } -if test "${libreplace_cv_HAVE_IPV6+set}" = set; then - $as_echo_n "(cached) " >&6 -else - - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - -#include /* for NULL */ -#include -#include -#include -#include - -int -main () -{ - -struct sockaddr_storage sa_store; -struct addrinfo *ai = NULL; -struct in6_addr in6addr; -int idx = if_nametoindex("iface1"); -int s = socket(AF_INET6, SOCK_STREAM, 0); -int ret = getaddrinfo(NULL, NULL, NULL, &ai); -if (ret != 0) { - const char *es = gai_strerror(ret); -} -freeaddrinfo(ai); -{ - int val = 1; - #ifdef HAVE_LINUX_IPV6_V6ONLY_26 - #define IPV6_V6ONLY 26 - #endif - ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, - (const void *)&val, sizeof(val)); -} - - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_link") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest$ac_exeext && { - test "$cross_compiling" = yes || - $as_test_x conftest$ac_exeext - }; then - - libreplace_cv_HAVE_IPV6=yes - -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - - libreplace_cv_HAVE_IPV6=no - -fi - -rm -rf conftest.dSYM -rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ - conftest$ac_exeext conftest.$ac_ext - -fi -{ $as_echo "$as_me:$LINENO: result: $libreplace_cv_HAVE_IPV6" >&5 -$as_echo "$libreplace_cv_HAVE_IPV6" >&6; } -if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then - -cat >>confdefs.h <<\_ACEOF -#define HAVE_IPV6 1 -_ACEOF - -fi - -LIBS=$old_LIBS -CPPFLAGS="$libreplace_SAVE_CPPFLAGS" - -LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}" - -echo "LIBREPLACE_NETWORK_CHECKS: END" - - -if test "$ac_cv_c_compiler_gnu" = yes; then - CFLAGS="$CFLAGS -Wall" - CFLAGS="$CFLAGS -W" - CFLAGS="$CFLAGS -Wshadow" - CFLAGS="$CFLAGS -Wstrict-prototypes" - CFLAGS="$CFLAGS -Wpointer-arith" - CFLAGS="$CFLAGS -Wcast-qual" - CFLAGS="$CFLAGS -Wcast-align" - CFLAGS="$CFLAGS -Wwrite-strings" - CFLAGS="$CFLAGS -Werror-implicit-function-declaration" - CFLAGS="$CFLAGS -Wformat=2" - CFLAGS="$CFLAGS -Wno-format-y2k" -fi - - - - - -# Check whether --with-shared-build-dir was given. -if test "${with_shared_build_dir+set}" = set; then - withval=$with_shared_build_dir; -fi - - - sharedbuilddir="$srcdir/sharedbuild" - if test x"$with_shared_build_dir" != x; then - sharedbuilddir=$with_shared_build_dir - CFLAGS="$CFLAGS -I$with_shared_build_dir/include" - LDFLAGS="$LDFLAGS -L$with_shared_build_dir/lib" - fi - - - -LIBS="${LIBREPLACE_NETWORK_LIBS}" - - - - -ac_config_files="$ac_config_files Makefile" - -cat >confcache <<\_ACEOF -# This file is a shell script that caches the results of configure -# tests run on this system so they can be shared between configure -# scripts and configure runs, see configure's option --config-cache. -# It is not useful on other systems. If it contains results you don't -# want to keep, you may remove or edit it. -# -# config.status only pays attention to the cache file if you give it -# the --recheck option to rerun configure. -# -# `ac_cv_env_foo' variables (set or unset) will be overridden when -# loading this file, other *unset* `ac_cv_foo' will be assigned the -# following values. - -_ACEOF - -# The following way of writing the cache mishandles newlines in values, -# but we know of no workaround that is simple, portable, and efficient. -# So, we kill variables containing newlines. -# Ultrix sh set writes to stderr and can't be redirected directly, -# and sets the high bit in the cache file unless we assign to the vars. -( - for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do - eval ac_val=\$$ac_var - case $ac_val in #( - *${as_nl}*) - case $ac_var in #( - *_cv_*) { $as_echo "$as_me:$LINENO: WARNING: cache variable $ac_var contains a newline" >&5 -$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; - esac - case $ac_var in #( - _ | IFS | as_nl) ;; #( - BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( - *) $as_unset $ac_var ;; - esac ;; - esac - done - - (set) 2>&1 | - case $as_nl`(ac_space=' '; set) 2>&1` in #( - *${as_nl}ac_space=\ *) - # `set' does not quote correctly, so add quotes (double-quote - # substitution turns \\\\ into \\, and sed turns \\ into \). - sed -n \ - "s/'/'\\\\''/g; - s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" - ;; #( - *) - # `set' quotes correctly as required by POSIX, so do not add quotes. - sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" - ;; - esac | - sort -) | - sed ' - /^ac_cv_env_/b end - t clear - :clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ - t end - s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ - :end' >>confcache -if diff "$cache_file" confcache >/dev/null 2>&1; then :; else - if test -w "$cache_file"; then - test "x$cache_file" != "x/dev/null" && - { $as_echo "$as_me:$LINENO: updating cache $cache_file" >&5 -$as_echo "$as_me: updating cache $cache_file" >&6;} - cat confcache >$cache_file - else - { $as_echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5 -$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} - fi -fi -rm -f confcache - -test "x$prefix" = xNONE && prefix=$ac_default_prefix -# Let make expand exec_prefix. -test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' - -DEFS=-DHAVE_CONFIG_H - -ac_libobjs= -ac_ltlibobjs= -for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue - # 1. Remove the extension, and $U if already installed. - ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' - ac_i=`$as_echo "$ac_i" | sed "$ac_script"` - # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR - # will be set to the directory where LIBOBJS objects are built. - ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext" - ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo' -done -LIBOBJS=$ac_libobjs - -LTLIBOBJS=$ac_ltlibobjs - - - - -: ${CONFIG_STATUS=./config.status} -ac_write_fail=0 -ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files $CONFIG_STATUS" -{ $as_echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5 -$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} -cat >$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -#! $SHELL -# Generated by $as_me. -# Run this file to recreate the current configuration. -# Compiler output produced by configure, useful for debugging -# configure, is in config.log if it exists. - -debug=false -ac_cs_recheck=false -ac_cs_silent=false -SHELL=\${CONFIG_SHELL-$SHELL} -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -## --------------------- ## -## M4sh Initialization. ## -## --------------------- ## - -# Be more Bourne compatible -DUALCASE=1; export DUALCASE # for MKS sh -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then - emulate sh - NULLCMD=: - # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which - # is contrary to our usage. Disable this feature. - alias -g '${1+"$@"}'='"$@"' - setopt NO_GLOB_SUBST -else - case `(set -o) 2>/dev/null` in - *posix*) set -o posix ;; -esac - -fi - - - - -# PATH needs CR -# Avoid depending upon Character Ranges. -as_cr_letters='abcdefghijklmnopqrstuvwxyz' -as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' -as_cr_Letters=$as_cr_letters$as_cr_LETTERS -as_cr_digits='0123456789' -as_cr_alnum=$as_cr_Letters$as_cr_digits - -as_nl=' -' -export as_nl -# Printing a long string crashes Solaris 7 /usr/bin/printf. -as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo -if (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then - as_echo='printf %s\n' - as_echo_n='printf %s' -else - if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then - as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' - as_echo_n='/usr/ucb/echo -n' - else - as_echo_body='eval expr "X$1" : "X\\(.*\\)"' - as_echo_n_body='eval - arg=$1; - case $arg in - *"$as_nl"*) - expr "X$arg" : "X\\(.*\\)$as_nl"; - arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; - esac; - expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" - ' - export as_echo_n_body - as_echo_n='sh -c $as_echo_n_body as_echo' - fi - export as_echo_body - as_echo='sh -c $as_echo_body as_echo' -fi - -# The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then - PATH_SEPARATOR=: - (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { - (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || - PATH_SEPARATOR=';' - } -fi - -# Support unset when possible. -if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then - as_unset=unset -else - as_unset=false -fi - - -# IFS -# We need space, tab and new line, in precisely that order. Quoting is -# there to prevent editors from complaining about space-tab. -# (If _AS_PATH_WALK were called with IFS unset, it would disable word -# splitting by setting IFS to empty value.) -IFS=" "" $as_nl" - -# Find who we are. Look in the path if we contain no directory separator. -case $0 in - *[\\/]* ) as_myself=$0 ;; - *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break -done -IFS=$as_save_IFS - - ;; -esac -# We did not find ourselves, most probably we were run as `sh COMMAND' -# in which case we are not to be found in the path. -if test "x$as_myself" = x; then - as_myself=$0 -fi -if test ! -f "$as_myself"; then - $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 - { (exit 1); exit 1; } -fi - -# Work around bugs in pre-3.0 UWIN ksh. -for as_var in ENV MAIL MAILPATH -do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var -done -PS1='$ ' -PS2='> ' -PS4='+ ' - -# NLS nuisances. -LC_ALL=C -export LC_ALL -LANGUAGE=C -export LANGUAGE - -# Required to use basename. -if expr a : '\(a\)' >/dev/null 2>&1 && - test "X`expr 00001 : '.*\(...\)'`" = X001; then - as_expr=expr -else - as_expr=false -fi - -if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then - as_basename=basename -else - as_basename=false -fi - - -# Name of the executable. -as_me=`$as_basename -- "$0" || -$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ - X"$0" : 'X\(//\)$' \| \ - X"$0" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$0" | - sed '/^.*\/\([^/][^/]*\)\/*$/{ - s//\1/ - q - } - /^X\/\(\/\/\)$/{ - s//\1/ - q - } - /^X\/\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - -# CDPATH. -$as_unset CDPATH - - - - as_lineno_1=$LINENO - as_lineno_2=$LINENO - test "x$as_lineno_1" != "x$as_lineno_2" && - test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { - - # Create $as_me.lineno as a copy of $as_myself, but with $LINENO - # uniformly replaced by the line number. The first 'sed' inserts a - # line-number line after each line using $LINENO; the second 'sed' - # does the real work. The second script uses 'N' to pair each - # line-number line with the line containing $LINENO, and appends - # trailing '-' during substitution so that $LINENO is not a special - # case at line end. - # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the - # scripts with optimization help from Paolo Bonzini. Blame Lee - # E. McMahon (1931-1989) for sed's syntax. :-) - sed -n ' - p - /[$]LINENO/= - ' <$as_myself | - sed ' - s/[$]LINENO.*/&-/ - t lineno - b - :lineno - N - :loop - s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ - t loop - s/-\n.*// - ' >$as_me.lineno && - chmod +x "$as_me.lineno" || - { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 - { (exit 1); exit 1; }; } - - # Don't try to exec as it changes $[0], causing all sort of problems - # (the dirname of $[0] is not the place where we might find the - # original and so on. Autoconf is especially sensitive to this). - . "./$as_me.lineno" - # Exit status is that of the last command. - exit -} - - -if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then - as_dirname=dirname -else - as_dirname=false -fi - -ECHO_C= ECHO_N= ECHO_T= -case `echo -n x` in --n*) - case `echo 'x\c'` in - *c*) ECHO_T=' ';; # ECHO_T is single tab character. - *) ECHO_C='\c';; - esac;; -*) - ECHO_N='-n';; -esac -if expr a : '\(a\)' >/dev/null 2>&1 && - test "X`expr 00001 : '.*\(...\)'`" = X001; then - as_expr=expr -else - as_expr=false -fi - -rm -f conf$$ conf$$.exe conf$$.file -if test -d conf$$.dir; then - rm -f conf$$.dir/conf$$.file -else - rm -f conf$$.dir - mkdir conf$$.dir 2>/dev/null -fi -if (echo >conf$$.file) 2>/dev/null; then - if ln -s conf$$.file conf$$ 2>/dev/null; then - as_ln_s='ln -s' - # ... but there are two gotchas: - # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. - # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -p'. - ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -p' - elif ln conf$$.file conf$$ 2>/dev/null; then - as_ln_s=ln - else - as_ln_s='cp -p' - fi -else - as_ln_s='cp -p' -fi -rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file -rmdir conf$$.dir 2>/dev/null - -if mkdir -p . 2>/dev/null; then - as_mkdir_p=: -else - test -d ./-p && rmdir ./-p - as_mkdir_p=false -fi - -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' -else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' -fi -as_executable_p=$as_test_x - -# Sed expression to map a string onto a valid CPP name. -as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" - -# Sed expression to map a string onto a valid variable name. -as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" - - -exec 6>&1 - -# Save the log message, to keep $[0] and so on meaningful, and to -# report actual input values of CONFIG_FILES etc. instead of their -# values after options handling. -ac_log=" -This file was extended by $as_me, which was -generated by GNU Autoconf 2.63. Invocation command line was - - CONFIG_FILES = $CONFIG_FILES - CONFIG_HEADERS = $CONFIG_HEADERS - CONFIG_LINKS = $CONFIG_LINKS - CONFIG_COMMANDS = $CONFIG_COMMANDS - $ $0 $@ - -on `(hostname || uname -n) 2>/dev/null | sed 1q` -" - -_ACEOF - -case $ac_config_files in *" -"*) set x $ac_config_files; shift; ac_config_files=$*;; -esac - -case $ac_config_headers in *" -"*) set x $ac_config_headers; shift; ac_config_headers=$*;; -esac - - -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -# Files that config.status was made for. -config_files="$ac_config_files" -config_headers="$ac_config_headers" -config_commands="$ac_config_commands" - -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -ac_cs_usage="\ -\`$as_me' instantiates files from templates according to the -current configuration. - -Usage: $0 [OPTION]... [FILE]... - - -h, --help print this help, then exit - -V, --version print version number and configuration settings, then exit - -q, --quiet, --silent - do not print progress messages - -d, --debug don't remove temporary files - --recheck update $as_me by reconfiguring in the same conditions - --file=FILE[:TEMPLATE] - instantiate the configuration file FILE - --header=FILE[:TEMPLATE] - instantiate the configuration header FILE - -Configuration files: -$config_files - -Configuration headers: -$config_headers - -Configuration commands: -$config_commands - -Report bugs to ." - -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -ac_cs_version="\\ -config.status -configured by $0, generated by GNU Autoconf 2.63, - with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" - -Copyright (C) 2008 Free Software Foundation, Inc. -This config.status script is free software; the Free Software Foundation -gives unlimited permission to copy, distribute and modify it." - -ac_pwd='$ac_pwd' -srcdir='$srcdir' -INSTALL='$INSTALL' -test -n "\$AWK" || AWK=awk -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -# The default lists apply if the user does not specify any file. -ac_need_defaults=: -while test $# != 0 -do - case $1 in - --*=*) - ac_option=`expr "X$1" : 'X\([^=]*\)='` - ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` - ac_shift=: - ;; - *) - ac_option=$1 - ac_optarg=$2 - ac_shift=shift - ;; - esac - - case $ac_option in - # Handling of the options. - -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - ac_cs_recheck=: ;; - --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) - $as_echo "$ac_cs_version"; exit ;; - --debug | --debu | --deb | --de | --d | -d ) - debug=: ;; - --file | --fil | --fi | --f ) - $ac_shift - case $ac_optarg in - *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; - esac - CONFIG_FILES="$CONFIG_FILES '$ac_optarg'" - ac_need_defaults=false;; - --header | --heade | --head | --hea ) - $ac_shift - case $ac_optarg in - *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; - esac - CONFIG_HEADERS="$CONFIG_HEADERS '$ac_optarg'" - ac_need_defaults=false;; - --he | --h) - # Conflict between --help and --header - { $as_echo "$as_me: error: ambiguous option: $1 -Try \`$0 --help' for more information." >&2 - { (exit 1); exit 1; }; };; - --help | --hel | -h ) - $as_echo "$ac_cs_usage"; exit ;; - -q | -quiet | --quiet | --quie | --qui | --qu | --q \ - | -silent | --silent | --silen | --sile | --sil | --si | --s) - ac_cs_silent=: ;; - - # This is an error. - -*) { $as_echo "$as_me: error: unrecognized option: $1 -Try \`$0 --help' for more information." >&2 - { (exit 1); exit 1; }; } ;; - - *) ac_config_targets="$ac_config_targets $1" - ac_need_defaults=false ;; - - esac - shift -done - -ac_configure_extra_args= - -if $ac_cs_silent; then - exec 6>/dev/null - ac_configure_extra_args="$ac_configure_extra_args --silent" -fi - -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -if \$ac_cs_recheck; then - set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion - shift - \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 - CONFIG_SHELL='$SHELL' - export CONFIG_SHELL - exec "\$@" -fi - -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -exec 5>>config.log -{ - echo - sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX -## Running $as_me. ## -_ASBOX - $as_echo "$ac_log" -} >&5 - -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -# -# INIT-COMMANDS -# -libreplacedir=$libreplacedir -libreplacedir=$libreplacedir -libreplacedir=$libreplacedir -libreplacedir=$libreplacedir - -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 - -# Handling of arguments. -for ac_config_target in $ac_config_targets -do - case $ac_config_target in - "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; - "rm-stdint.h") CONFIG_COMMANDS="$CONFIG_COMMANDS rm-stdint.h" ;; - "mk-stdint.h") CONFIG_COMMANDS="$CONFIG_COMMANDS mk-stdint.h" ;; - "rm-stdbool.h") CONFIG_COMMANDS="$CONFIG_COMMANDS rm-stdbool.h" ;; - "mk-stdbool.h") CONFIG_COMMANDS="$CONFIG_COMMANDS mk-stdbool.h" ;; - "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; - - *) { { $as_echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 -$as_echo "$as_me: error: invalid argument: $ac_config_target" >&2;} - { (exit 1); exit 1; }; };; - esac -done - - -# If the user did not use the arguments to specify the items to instantiate, -# then the envvar interface is used. Set only those that are not. -# We use the long form for the default assignment because of an extremely -# bizarre bug on SunOS 4.1.3. -if $ac_need_defaults; then - test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files - test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers - test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands -fi - -# Have a temporary directory for convenience. Make it in the build tree -# simply because there is no reason against having it here, and in addition, -# creating and moving files from /tmp can sometimes cause problems. -# Hook for its removal unless debugging. -# Note that there is a small window in which the directory will not be cleaned: -# after its creation but before its name has been assigned to `$tmp'. -$debug || -{ - tmp= - trap 'exit_status=$? - { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status -' 0 - trap '{ (exit 1); exit 1; }' 1 2 13 15 -} -# Create a (secure) tmp directory for tmp files. - -{ - tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && - test -n "$tmp" && test -d "$tmp" -} || -{ - tmp=./conf$$-$RANDOM - (umask 077 && mkdir "$tmp") -} || -{ - $as_echo "$as_me: cannot create a temporary directory in ." >&2 - { (exit 1); exit 1; } -} - -# Set up the scripts for CONFIG_FILES section. -# No need to generate them if there are no CONFIG_FILES. -# This happens for instance with `./config.status config.h'. -if test -n "$CONFIG_FILES"; then - - -ac_cr=' ' -ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` -if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then - ac_cs_awk_cr='\\r' -else - ac_cs_awk_cr=$ac_cr -fi - -echo 'BEGIN {' >"$tmp/subs1.awk" && -_ACEOF - - -{ - echo "cat >conf$$subs.awk <<_ACEOF" && - echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && - echo "_ACEOF" -} >conf$$subs.sh || - { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 -$as_echo "$as_me: error: could not make $CONFIG_STATUS" >&2;} - { (exit 1); exit 1; }; } -ac_delim_num=`echo "$ac_subst_vars" | grep -c '$'` -ac_delim='%!_!# ' -for ac_last_try in false false false false false :; do - . ./conf$$subs.sh || - { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 -$as_echo "$as_me: error: could not make $CONFIG_STATUS" >&2;} - { (exit 1); exit 1; }; } - - ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` - if test $ac_delim_n = $ac_delim_num; then - break - elif $ac_last_try; then - { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 -$as_echo "$as_me: error: could not make $CONFIG_STATUS" >&2;} - { (exit 1); exit 1; }; } - else - ac_delim="$ac_delim!$ac_delim _$ac_delim!! " - fi -done -rm -f conf$$subs.sh - -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -cat >>"\$tmp/subs1.awk" <<\\_ACAWK && -_ACEOF -sed -n ' -h -s/^/S["/; s/!.*/"]=/ -p -g -s/^[^!]*!// -:repl -t repl -s/'"$ac_delim"'$// -t delim -:nl -h -s/\(.\{148\}\).*/\1/ -t more1 -s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ -p -n -b repl -:more1 -s/["\\]/\\&/g; s/^/"/; s/$/"\\/ -p -g -s/.\{148\}// -t nl -:delim -h -s/\(.\{148\}\).*/\1/ -t more2 -s/["\\]/\\&/g; s/^/"/; s/$/"/ -p -b -:more2 -s/["\\]/\\&/g; s/^/"/; s/$/"\\/ -p -g -s/.\{148\}// -t delim -' >$CONFIG_STATUS || ac_write_fail=1 -rm -f conf$$subs.awk -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -_ACAWK -cat >>"\$tmp/subs1.awk" <<_ACAWK && - for (key in S) S_is_set[key] = 1 - FS = "" - -} -{ - line = $ 0 - nfields = split(line, field, "@") - substed = 0 - len = length(field[1]) - for (i = 2; i < nfields; i++) { - key = field[i] - keylen = length(key) - if (S_is_set[key]) { - value = S[key] - line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) - len += length(value) + length(field[++i]) - substed = 1 - } else - len += 1 + keylen - } - - print line -} - -_ACAWK -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then - sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" -else - cat -fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \ - || { { $as_echo "$as_me:$LINENO: error: could not setup config files machinery" >&5 -$as_echo "$as_me: error: could not setup config files machinery" >&2;} - { (exit 1); exit 1; }; } -_ACEOF - -# VPATH may cause trouble with some makes, so we remove $(srcdir), -# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and -# trailing colons and then remove the whole line if VPATH becomes empty -# (actually we leave an empty line to preserve line numbers). -if test "x$srcdir" = x.; then - ac_vpsub='/^[ ]*VPATH[ ]*=/{ -s/:*\$(srcdir):*/:/ -s/:*\${srcdir}:*/:/ -s/:*@srcdir@:*/:/ -s/^\([^=]*=[ ]*\):*/\1/ -s/:*$// -s/^[^=]*=[ ]*$// -}' -fi - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -fi # test -n "$CONFIG_FILES" - -# Set up the scripts for CONFIG_HEADERS section. -# No need to generate them if there are no CONFIG_HEADERS. -# This happens for instance with `./config.status Makefile'. -if test -n "$CONFIG_HEADERS"; then -cat >"$tmp/defines.awk" <<\_ACAWK || -BEGIN { -_ACEOF - -# Transform confdefs.h into an awk script `defines.awk', embedded as -# here-document in config.status, that substitutes the proper values into -# config.h.in to produce config.h. - -# Create a delimiter string that does not exist in confdefs.h, to ease -# handling of long lines. -ac_delim='%!_!# ' -for ac_last_try in false false :; do - ac_t=`sed -n "/$ac_delim/p" confdefs.h` - if test -z "$ac_t"; then - break - elif $ac_last_try; then - { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_HEADERS" >&5 -$as_echo "$as_me: error: could not make $CONFIG_HEADERS" >&2;} - { (exit 1); exit 1; }; } - else - ac_delim="$ac_delim!$ac_delim _$ac_delim!! " - fi -done - -# For the awk script, D is an array of macro values keyed by name, -# likewise P contains macro parameters if any. Preserve backslash -# newline sequences. - -ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* -sed -n ' -s/.\{148\}/&'"$ac_delim"'/g -t rset -:rset -s/^[ ]*#[ ]*define[ ][ ]*/ / -t def -d -:def -s/\\$// -t bsnl -s/["\\]/\\&/g -s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ -D["\1"]=" \3"/p -s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2"/p -d -:bsnl -s/["\\]/\\&/g -s/^ \('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/P["\1"]="\2"\ -D["\1"]=" \3\\\\\\n"\\/p -t cont -s/^ \('"$ac_word_re"'\)[ ]*\(.*\)/D["\1"]=" \2\\\\\\n"\\/p -t cont -d -:cont -n -s/.\{148\}/&'"$ac_delim"'/g -t clear -:clear -s/\\$// -t bsnlc -s/["\\]/\\&/g; s/^/"/; s/$/"/p -d -:bsnlc -s/["\\]/\\&/g; s/^/"/; s/$/\\\\\\n"\\/p -b cont -' >$CONFIG_STATUS || ac_write_fail=1 - -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 - for (key in D) D_is_set[key] = 1 - FS = "" -} -/^[\t ]*#[\t ]*(define|undef)[\t ]+$ac_word_re([\t (]|\$)/ { - line = \$ 0 - split(line, arg, " ") - if (arg[1] == "#") { - defundef = arg[2] - mac1 = arg[3] - } else { - defundef = substr(arg[1], 2) - mac1 = arg[2] - } - split(mac1, mac2, "(") #) - macro = mac2[1] - prefix = substr(line, 1, index(line, defundef) - 1) - if (D_is_set[macro]) { - # Preserve the white space surrounding the "#". - print prefix "define", macro P[macro] D[macro] - next - } else { - # Replace #undef with comments. This is necessary, for example, - # in the case of _POSIX_SOURCE, which is predefined and required - # on some systems where configure will not decide to define it. - if (defundef == "undef") { - print "/*", prefix defundef, macro, "*/" - next - } - } -} -{ print } -_ACAWK -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 - { { $as_echo "$as_me:$LINENO: error: could not setup config headers machinery" >&5 -$as_echo "$as_me: error: could not setup config headers machinery" >&2;} - { (exit 1); exit 1; }; } -fi # test -n "$CONFIG_HEADERS" - - -eval set X " :F $CONFIG_FILES :H $CONFIG_HEADERS :C $CONFIG_COMMANDS" -shift -for ac_tag -do - case $ac_tag in - :[FHLC]) ac_mode=$ac_tag; continue;; - esac - case $ac_mode$ac_tag in - :[FHL]*:*);; - :L* | :C*:*) { { $as_echo "$as_me:$LINENO: error: invalid tag $ac_tag" >&5 -$as_echo "$as_me: error: invalid tag $ac_tag" >&2;} - { (exit 1); exit 1; }; };; - :[FH]-) ac_tag=-:-;; - :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; - esac - ac_save_IFS=$IFS - IFS=: - set x $ac_tag - IFS=$ac_save_IFS - shift - ac_file=$1 - shift - - case $ac_mode in - :L) ac_source=$1;; - :[FH]) - ac_file_inputs= - for ac_f - do - case $ac_f in - -) ac_f="$tmp/stdin";; - *) # Look for the file first in the build tree, then in the source tree - # (if the path is not absolute). The absolute path cannot be DOS-style, - # because $ac_f cannot contain `:'. - test -f "$ac_f" || - case $ac_f in - [\\/$]*) false;; - *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; - esac || - { { $as_echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5 -$as_echo "$as_me: error: cannot find input file: $ac_f" >&2;} - { (exit 1); exit 1; }; };; - esac - case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac - ac_file_inputs="$ac_file_inputs '$ac_f'" - done - - # Let's still pretend it is `configure' which instantiates (i.e., don't - # use $as_me), people would be surprised to read: - # /* config.h. Generated by config.status. */ - configure_input='Generated from '` - $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' - `' by configure.' - if test x"$ac_file" != x-; then - configure_input="$ac_file. $configure_input" - { $as_echo "$as_me:$LINENO: creating $ac_file" >&5 -$as_echo "$as_me: creating $ac_file" >&6;} - fi - # Neutralize special characters interpreted by sed in replacement strings. - case $configure_input in #( - *\&* | *\|* | *\\* ) - ac_sed_conf_input=`$as_echo "$configure_input" | - sed 's/[\\\\&|]/\\\\&/g'`;; #( - *) ac_sed_conf_input=$configure_input;; - esac - - case $ac_tag in - *:-:* | *:-) cat >"$tmp/stdin" \ - || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5 -$as_echo "$as_me: error: could not create $ac_file" >&2;} - { (exit 1); exit 1; }; } ;; - esac - ;; - esac - - ac_dir=`$as_dirname -- "$ac_file" || -$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$ac_file" : 'X\(//\)[^/]' \| \ - X"$ac_file" : 'X\(//\)$' \| \ - X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$ac_file" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - { as_dir="$ac_dir" - case $as_dir in #( - -*) as_dir=./$as_dir;; - esac - test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || { - as_dirs= - while :; do - case $as_dir in #( - *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( - *) as_qdir=$as_dir;; - esac - as_dirs="'$as_qdir' $as_dirs" - as_dir=`$as_dirname -- "$as_dir" || -$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ - X"$as_dir" : 'X\(//\)[^/]' \| \ - X"$as_dir" : 'X\(//\)$' \| \ - X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_dir" | - sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ - s//\1/ - q - } - /^X\(\/\/\)[^/].*/{ - s//\1/ - q - } - /^X\(\/\/\)$/{ - s//\1/ - q - } - /^X\(\/\).*/{ - s//\1/ - q - } - s/.*/./; q'` - test -d "$as_dir" && break - done - test -z "$as_dirs" || eval "mkdir $as_dirs" - } || test -d "$as_dir" || { { $as_echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5 -$as_echo "$as_me: error: cannot create directory $as_dir" >&2;} - { (exit 1); exit 1; }; }; } - ac_builddir=. - -case "$ac_dir" in -.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; -*) - ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` - # A ".." for each directory in $ac_dir_suffix. - ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` - case $ac_top_builddir_sub in - "") ac_top_builddir_sub=. ac_top_build_prefix= ;; - *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; - esac ;; -esac -ac_abs_top_builddir=$ac_pwd -ac_abs_builddir=$ac_pwd$ac_dir_suffix -# for backward compatibility: -ac_top_builddir=$ac_top_build_prefix - -case $srcdir in - .) # We are building in place. - ac_srcdir=. - ac_top_srcdir=$ac_top_builddir_sub - ac_abs_top_srcdir=$ac_pwd ;; - [\\/]* | ?:[\\/]* ) # Absolute name. - ac_srcdir=$srcdir$ac_dir_suffix; - ac_top_srcdir=$srcdir - ac_abs_top_srcdir=$srcdir ;; - *) # Relative name. - ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix - ac_top_srcdir=$ac_top_build_prefix$srcdir - ac_abs_top_srcdir=$ac_pwd/$srcdir ;; -esac -ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix - - - case $ac_mode in - :F) - # - # CONFIG_FILE - # - - case $INSTALL in - [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; - *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; - esac -_ACEOF - -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -# If the template does not know about datarootdir, expand it. -# FIXME: This hack should be removed a few years after 2.60. -ac_datarootdir_hack=; ac_datarootdir_seen= - -ac_sed_dataroot=' -/datarootdir/ { - p - q -} -/@datadir@/p -/@docdir@/p -/@infodir@/p -/@localedir@/p -/@mandir@/p -' -case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in -*datarootdir*) ac_datarootdir_seen=yes;; -*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) - { $as_echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 -$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} -_ACEOF -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 - ac_datarootdir_hack=' - s&@datadir@&$datadir&g - s&@docdir@&$docdir&g - s&@infodir@&$infodir&g - s&@localedir@&$localedir&g - s&@mandir@&$mandir&g - s&\\\${datarootdir}&$datarootdir&g' ;; -esac -_ACEOF - -# Neutralize VPATH when `$srcdir' = `.'. -# Shell code in configure.ac might set extrasub. -# FIXME: do we really want to maintain this feature? -cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -ac_sed_extra="$ac_vpsub -$extrasub -_ACEOF -cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 -:t -/@[a-zA-Z_][a-zA-Z_0-9]*@/!b -s|@configure_input@|$ac_sed_conf_input|;t t -s&@top_builddir@&$ac_top_builddir_sub&;t t -s&@top_build_prefix@&$ac_top_build_prefix&;t t -s&@srcdir@&$ac_srcdir&;t t -s&@abs_srcdir@&$ac_abs_srcdir&;t t -s&@top_srcdir@&$ac_top_srcdir&;t t -s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t -s&@builddir@&$ac_builddir&;t t -s&@abs_builddir@&$ac_abs_builddir&;t t -s&@abs_top_builddir@&$ac_abs_top_builddir&;t t -s&@INSTALL@&$ac_INSTALL&;t t -$ac_datarootdir_hack -" -eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \ - || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5 -$as_echo "$as_me: error: could not create $ac_file" >&2;} - { (exit 1); exit 1; }; } - -test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && - { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && - { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && - { $as_echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir' -which seems to be undefined. Please make sure it is defined." >&5 -$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' -which seems to be undefined. Please make sure it is defined." >&2;} - - rm -f "$tmp/stdin" - case $ac_file in - -) cat "$tmp/out" && rm -f "$tmp/out";; - *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";; - esac \ - || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5 -$as_echo "$as_me: error: could not create $ac_file" >&2;} - { (exit 1); exit 1; }; } - ;; - :H) - # - # CONFIG_HEADER - # - if test x"$ac_file" != x-; then - { - $as_echo "/* $configure_input */" \ - && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" - } >"$tmp/config.h" \ - || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5 -$as_echo "$as_me: error: could not create $ac_file" >&2;} - { (exit 1); exit 1; }; } - if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then - { $as_echo "$as_me:$LINENO: $ac_file is unchanged" >&5 -$as_echo "$as_me: $ac_file is unchanged" >&6;} - else - rm -f "$ac_file" - mv "$tmp/config.h" "$ac_file" \ - || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5 -$as_echo "$as_me: error: could not create $ac_file" >&2;} - { (exit 1); exit 1; }; } - fi - else - $as_echo "/* $configure_input */" \ - && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \ - || { { $as_echo "$as_me:$LINENO: error: could not create -" >&5 -$as_echo "$as_me: error: could not create -" >&2;} - { (exit 1); exit 1; }; } - fi - ;; - - :C) { $as_echo "$as_me:$LINENO: executing $ac_file commands" >&5 -$as_echo "$as_me: executing $ac_file commands" >&6;} - ;; - esac - - - case $ac_file$ac_mode in - "rm-stdint.h":C) rm -f $libreplacedir/stdint.h ;; - "mk-stdint.h":C) echo "#include \"replace.h\"" > $libreplacedir/stdint.h ;; - "rm-stdbool.h":C) rm -f $libreplacedir/stdbool.h ;; - "mk-stdbool.h":C) echo "#include \"replace.h\"" > $libreplacedir/stdbool.h ;; - - esac -done # for ac_tag - - -{ (exit 0); exit 0; } -_ACEOF -chmod +x $CONFIG_STATUS -ac_clean_files=$ac_clean_files_save - -test $ac_write_fail = 0 || - { { $as_echo "$as_me:$LINENO: error: write failure creating $CONFIG_STATUS" >&5 -$as_echo "$as_me: error: write failure creating $CONFIG_STATUS" >&2;} - { (exit 1); exit 1; }; } - - -# configure is writing to config.log, and then calls config.status. -# config.status does its own redirection, appending to config.log. -# Unfortunately, on DOS this fails, as config.log is still kept open -# by configure, so config.status won't be able to write to it; its -# output is simply discarded. So we exec the FD to /dev/null, -# effectively closing config.log, so it can be properly (re)opened and -# appended to by config.status. When coming back to configure, we -# need to make the FD available again. -if test "$no_create" != yes; then - ac_cs_success=: - ac_config_status_args= - test "$silent" = yes && - ac_config_status_args="$ac_config_status_args --quiet" - exec 5>/dev/null - $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false - exec 5>>config.log - # Use ||, not &&, to avoid exiting from the if with $? = 1, which - # would make configure fail if this is the last instruction. - $ac_cs_success || { (exit 1); exit 1; } -fi -if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then - { $as_echo "$as_me:$LINENO: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 -$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} -fi - diff --git a/bundled/replace/configure.ac b/bundled/replace/configure.ac deleted file mode 100644 index 0361825a..00000000 --- a/bundled/replace/configure.ac +++ /dev/null @@ -1,33 +0,0 @@ -AC_PREREQ(2.50) -AC_INIT(replace.c) -AC_CONFIG_SRCDIR([replace.c]) -AC_CONFIG_HEADER(config.h) - -CFLAGS="$CFLAGS -I$srcdir" - -AC_LIBREPLACE_ALL_CHECKS -AC_LIBREPLACE_NETWORK_CHECKS - -if test "$ac_cv_prog_gcc" = yes; then - CFLAGS="$CFLAGS -Wall" - CFLAGS="$CFLAGS -W" - CFLAGS="$CFLAGS -Wshadow" - CFLAGS="$CFLAGS -Wstrict-prototypes" - CFLAGS="$CFLAGS -Wpointer-arith" - CFLAGS="$CFLAGS -Wcast-qual" - CFLAGS="$CFLAGS -Wcast-align" - CFLAGS="$CFLAGS -Wwrite-strings" - CFLAGS="$CFLAGS -Werror-implicit-function-declaration" - CFLAGS="$CFLAGS -Wformat=2" - CFLAGS="$CFLAGS -Wno-format-y2k" -fi - -m4_include(build_macros.m4) -BUILD_WITH_SHARED_BUILD_DIR - -LIBS="${LIBREPLACE_NETWORK_LIBS}" -AC_SUBST(LIBS) - -AC_SUBST(LDFLAGS) - -AC_OUTPUT(Makefile) diff --git a/bundled/replace/crypt.c b/bundled/replace/crypt.c deleted file mode 100644 index 3a067bcc..00000000 --- a/bundled/replace/crypt.c +++ /dev/null @@ -1,770 +0,0 @@ -/* - This bit of code was derived from the UFC-crypt package which - carries the following copyright - - Modified for use by Samba by Andrew Tridgell, October 1994 - - Note that this routine is only faster on some machines. Under Linux 1.1.51 - libc 4.5.26 I actually found this routine to be slightly slower. - - Under SunOS I found a huge speedup by using these routines - (a factor of 20 or so) - - Warning: I've had a report from Steve Kennedy - that this crypt routine may sometimes get the wrong answer. Only - use UFC_CRYT if you really need it. - -*/ - -#include "replace.h" - -#ifndef HAVE_CRYPT - -/* - * UFC-crypt: ultra fast crypt(3) implementation - * - * Copyright (C) 1991-1998, Free Software Foundation, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see . - * - * @(#)crypt_util.c 2.31 02/08/92 - * - * Support routines - * - */ - - -#ifndef long32 -#define long32 int32_t -#endif - -#ifndef long64 -#define long64 int64_t -#endif - -#ifndef ufc_long -#define ufc_long unsigned -#endif - -#ifndef _UFC_64_ -#define _UFC_32_ -#endif - -/* - * Permutation done once on the 56 bit - * key derived from the original 8 byte ASCII key. - */ -static int pc1[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 -}; - -/* - * How much to rotate each 28 bit half of the pc1 permutated - * 56 bit key before using pc2 to give the i' key - */ -static int rots[16] = { - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 -}; - -/* - * Permutation giving the key - * of the i' DES round - */ -static int pc2[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, - 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, - 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 -}; - -/* - * The E expansion table which selects - * bits from the 32 bit intermediate result. - */ -static int esel[48] = { - 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, - 8, 9, 10, 11, 12, 13, 12, 13, 14, 15, 16, 17, - 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25, - 24, 25, 26, 27, 28, 29, 28, 29, 30, 31, 32, 1 -}; -static int e_inverse[64]; - -/* - * Permutation done on the - * result of sbox lookups - */ -static int perm32[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 -}; - -/* - * The sboxes - */ -static int sbox[8][4][16]= { - { { 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 }, - { 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8 }, - { 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0 }, - { 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 } - }, - - { { 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 }, - { 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5 }, - { 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15 }, - { 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 } - }, - - { { 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 }, - { 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1 }, - { 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7 }, - { 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 } - }, - - { { 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 }, - { 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9 }, - { 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4 }, - { 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 } - }, - - { { 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9 }, - { 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6 }, - { 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14 }, - { 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 } - }, - - { { 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11 }, - { 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8 }, - { 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6 }, - { 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 } - }, - - { { 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1 }, - { 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6 }, - { 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2 }, - { 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 } - }, - - { { 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7 }, - { 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2 }, - { 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8 }, - { 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 } - } -}; - -/* - * This is the final - * permutation matrix - */ -static int final_perm[64] = { - 40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31, - 38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29, - 36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27, - 34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9, 49, 17, 57, 25 -}; - -/* - * The 16 DES keys in BITMASK format - */ -#ifdef _UFC_32_ -long32 _ufc_keytab[16][2]; -#endif - -#ifdef _UFC_64_ -long64 _ufc_keytab[16]; -#endif - - -#define ascii_to_bin(c) ((c)>='a'?(c-59):(c)>='A'?((c)-53):(c)-'.') -#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.') - -/* Macro to set a bit (0..23) */ -#define BITMASK(i) ( (1<<(11-(i)%12+3)) << ((i)<12?16:0) ) - -/* - * sb arrays: - * - * Workhorses of the inner loop of the DES implementation. - * They do sbox lookup, shifting of this value, 32 bit - * permutation and E permutation for the next round. - * - * Kept in 'BITMASK' format. - */ - -#ifdef _UFC_32_ -long32 _ufc_sb0[8192], _ufc_sb1[8192], _ufc_sb2[8192], _ufc_sb3[8192]; -static long32 *sb[4] = {_ufc_sb0, _ufc_sb1, _ufc_sb2, _ufc_sb3}; -#endif - -#ifdef _UFC_64_ -long64 _ufc_sb0[4096], _ufc_sb1[4096], _ufc_sb2[4096], _ufc_sb3[4096]; -static long64 *sb[4] = {_ufc_sb0, _ufc_sb1, _ufc_sb2, _ufc_sb3}; -#endif - -/* - * eperm32tab: do 32 bit permutation and E selection - * - * The first index is the byte number in the 32 bit value to be permuted - * - second - is the value of this byte - * - third - selects the two 32 bit values - * - * The table is used and generated internally in init_des to speed it up - */ -static ufc_long eperm32tab[4][256][2]; - -/* - * do_pc1: permform pc1 permutation in the key schedule generation. - * - * The first index is the byte number in the 8 byte ASCII key - * - second - - the two 28 bits halfs of the result - * - third - selects the 7 bits actually used of each byte - * - * The result is kept with 28 bit per 32 bit with the 4 most significant - * bits zero. - */ -static ufc_long do_pc1[8][2][128]; - -/* - * do_pc2: permform pc2 permutation in the key schedule generation. - * - * The first index is the septet number in the two 28 bit intermediate values - * - second - - - septet values - * - * Knowledge of the structure of the pc2 permutation is used. - * - * The result is kept with 28 bit per 32 bit with the 4 most significant - * bits zero. - */ -static ufc_long do_pc2[8][128]; - -/* - * efp: undo an extra e selection and do final - * permutation giving the DES result. - * - * Invoked 6 bit a time on two 48 bit values - * giving two 32 bit longs. - */ -static ufc_long efp[16][64][2]; - -static unsigned char bytemask[8] = { - 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 -}; - -static ufc_long longmask[32] = { - 0x80000000, 0x40000000, 0x20000000, 0x10000000, - 0x08000000, 0x04000000, 0x02000000, 0x01000000, - 0x00800000, 0x00400000, 0x00200000, 0x00100000, - 0x00080000, 0x00040000, 0x00020000, 0x00010000, - 0x00008000, 0x00004000, 0x00002000, 0x00001000, - 0x00000800, 0x00000400, 0x00000200, 0x00000100, - 0x00000080, 0x00000040, 0x00000020, 0x00000010, - 0x00000008, 0x00000004, 0x00000002, 0x00000001 -}; - - -/* - * Silly rewrite of 'bzero'. I do so - * because some machines don't have - * bzero and some don't have memset. - */ - -static void clearmem(char *start, int cnt) - { while(cnt--) - *start++ = '\0'; - } - -static int initialized = 0; - -/* lookup a 6 bit value in sbox */ - -#define s_lookup(i,s) sbox[(i)][(((s)>>4) & 0x2)|((s) & 0x1)][((s)>>1) & 0xf]; - -/* - * Initialize unit - may be invoked directly - * by fcrypt users. - */ - -static void ufc_init_des(void) - { int comes_from_bit; - int bit, sg; - ufc_long j; - ufc_long mask1, mask2; - - /* - * Create the do_pc1 table used - * to affect pc1 permutation - * when generating keys - */ - for(bit = 0; bit < 56; bit++) { - comes_from_bit = pc1[bit] - 1; - mask1 = bytemask[comes_from_bit % 8 + 1]; - mask2 = longmask[bit % 28 + 4]; - for(j = 0; j < 128; j++) { - if(j & mask1) - do_pc1[comes_from_bit / 8][bit / 28][j] |= mask2; - } - } - - /* - * Create the do_pc2 table used - * to affect pc2 permutation when - * generating keys - */ - for(bit = 0; bit < 48; bit++) { - comes_from_bit = pc2[bit] - 1; - mask1 = bytemask[comes_from_bit % 7 + 1]; - mask2 = BITMASK(bit % 24); - for(j = 0; j < 128; j++) { - if(j & mask1) - do_pc2[comes_from_bit / 7][j] |= mask2; - } - } - - /* - * Now generate the table used to do combined - * 32 bit permutation and e expansion - * - * We use it because we have to permute 16384 32 bit - * longs into 48 bit in order to initialize sb. - * - * Looping 48 rounds per permutation becomes - * just too slow... - * - */ - - clearmem((char*)eperm32tab, sizeof(eperm32tab)); - - for(bit = 0; bit < 48; bit++) { - ufc_long inner_mask1,comes_from; - - comes_from = perm32[esel[bit]-1]-1; - inner_mask1 = bytemask[comes_from % 8]; - - for(j = 256; j--;) { - if(j & inner_mask1) - eperm32tab[comes_from / 8][j][bit / 24] |= BITMASK(bit % 24); - } - } - - /* - * Create the sb tables: - * - * For each 12 bit segment of an 48 bit intermediate - * result, the sb table precomputes the two 4 bit - * values of the sbox lookups done with the two 6 - * bit halves, shifts them to their proper place, - * sends them through perm32 and finally E expands - * them so that they are ready for the next - * DES round. - * - */ - for(sg = 0; sg < 4; sg++) { - int j1, j2; - int s1, s2; - - for(j1 = 0; j1 < 64; j1++) { - s1 = s_lookup(2 * sg, j1); - for(j2 = 0; j2 < 64; j2++) { - ufc_long to_permute, inx; - - s2 = s_lookup(2 * sg + 1, j2); - to_permute = ((s1 << 4) | s2) << (24 - 8 * sg); - -#ifdef _UFC_32_ - inx = ((j1 << 6) | j2) << 1; - sb[sg][inx ] = eperm32tab[0][(to_permute >> 24) & 0xff][0]; - sb[sg][inx+1] = eperm32tab[0][(to_permute >> 24) & 0xff][1]; - sb[sg][inx ] |= eperm32tab[1][(to_permute >> 16) & 0xff][0]; - sb[sg][inx+1] |= eperm32tab[1][(to_permute >> 16) & 0xff][1]; - sb[sg][inx ] |= eperm32tab[2][(to_permute >> 8) & 0xff][0]; - sb[sg][inx+1] |= eperm32tab[2][(to_permute >> 8) & 0xff][1]; - sb[sg][inx ] |= eperm32tab[3][(to_permute) & 0xff][0]; - sb[sg][inx+1] |= eperm32tab[3][(to_permute) & 0xff][1]; -#endif -#ifdef _UFC_64_ - inx = ((j1 << 6) | j2); - sb[sg][inx] = - ((long64)eperm32tab[0][(to_permute >> 24) & 0xff][0] << 32) | - (long64)eperm32tab[0][(to_permute >> 24) & 0xff][1]; - sb[sg][inx] |= - ((long64)eperm32tab[1][(to_permute >> 16) & 0xff][0] << 32) | - (long64)eperm32tab[1][(to_permute >> 16) & 0xff][1]; - sb[sg][inx] |= - ((long64)eperm32tab[2][(to_permute >> 8) & 0xff][0] << 32) | - (long64)eperm32tab[2][(to_permute >> 8) & 0xff][1]; - sb[sg][inx] |= - ((long64)eperm32tab[3][(to_permute) & 0xff][0] << 32) | - (long64)eperm32tab[3][(to_permute) & 0xff][1]; -#endif - } - } - } - - /* - * Create an inverse matrix for esel telling - * where to plug out bits if undoing it - */ - for(bit=48; bit--;) { - e_inverse[esel[bit] - 1 ] = bit; - e_inverse[esel[bit] - 1 + 32] = bit + 48; - } - - /* - * create efp: the matrix used to - * undo the E expansion and effect final permutation - */ - clearmem((char*)efp, sizeof efp); - for(bit = 0; bit < 64; bit++) { - int o_bit, o_long; - ufc_long word_value, inner_mask1, inner_mask2; - int comes_from_f_bit, comes_from_e_bit; - int comes_from_word, bit_within_word; - - /* See where bit i belongs in the two 32 bit long's */ - o_long = bit / 32; /* 0..1 */ - o_bit = bit % 32; /* 0..31 */ - - /* - * And find a bit in the e permutated value setting this bit. - * - * Note: the e selection may have selected the same bit several - * times. By the initialization of e_inverse, we only look - * for one specific instance. - */ - comes_from_f_bit = final_perm[bit] - 1; /* 0..63 */ - comes_from_e_bit = e_inverse[comes_from_f_bit]; /* 0..95 */ - comes_from_word = comes_from_e_bit / 6; /* 0..15 */ - bit_within_word = comes_from_e_bit % 6; /* 0..5 */ - - inner_mask1 = longmask[bit_within_word + 26]; - inner_mask2 = longmask[o_bit]; - - for(word_value = 64; word_value--;) { - if(word_value & inner_mask1) - efp[comes_from_word][word_value][o_long] |= inner_mask2; - } - } - initialized++; - } - -/* - * Process the elements of the sb table permuting the - * bits swapped in the expansion by the current salt. - */ - -#ifdef _UFC_32_ -static void shuffle_sb(long32 *k, ufc_long saltbits) - { ufc_long j; - long32 x; - for(j=4096; j--;) { - x = (k[0] ^ k[1]) & (long32)saltbits; - *k++ ^= x; - *k++ ^= x; - } - } -#endif - -#ifdef _UFC_64_ -static void shuffle_sb(long64 *k, ufc_long saltbits) - { ufc_long j; - long64 x; - for(j=4096; j--;) { - x = ((*k >> 32) ^ *k) & (long64)saltbits; - *k++ ^= (x << 32) | x; - } - } -#endif - -/* - * Setup the unit for a new salt - * Hopefully we'll not see a new salt in each crypt call. - */ - -static unsigned char current_salt[3] = "&&"; /* invalid value */ -static ufc_long current_saltbits = 0; -static int direction = 0; - -static void setup_salt(const char *s1) - { ufc_long i, j, saltbits; - const unsigned char *s2 = (const unsigned char *)s1; - - if(!initialized) - ufc_init_des(); - - if(s2[0] == current_salt[0] && s2[1] == current_salt[1]) - return; - current_salt[0] = s2[0]; current_salt[1] = s2[1]; - - /* - * This is the only crypt change to DES: - * entries are swapped in the expansion table - * according to the bits set in the salt. - */ - saltbits = 0; - for(i = 0; i < 2; i++) { - long c=ascii_to_bin(s2[i]); - if(c < 0 || c > 63) - c = 0; - for(j = 0; j < 6; j++) { - if((c >> j) & 0x1) - saltbits |= BITMASK(6 * i + j); - } - } - - /* - * Permute the sb table values - * to reflect the changed e - * selection table - */ - shuffle_sb(_ufc_sb0, current_saltbits ^ saltbits); - shuffle_sb(_ufc_sb1, current_saltbits ^ saltbits); - shuffle_sb(_ufc_sb2, current_saltbits ^ saltbits); - shuffle_sb(_ufc_sb3, current_saltbits ^ saltbits); - - current_saltbits = saltbits; - } - -static void ufc_mk_keytab(char *key) - { ufc_long v1, v2, *k1; - int i; -#ifdef _UFC_32_ - long32 v, *k2 = &_ufc_keytab[0][0]; -#endif -#ifdef _UFC_64_ - long64 v, *k2 = &_ufc_keytab[0]; -#endif - - v1 = v2 = 0; k1 = &do_pc1[0][0][0]; - for(i = 8; i--;) { - v1 |= k1[*key & 0x7f]; k1 += 128; - v2 |= k1[*key++ & 0x7f]; k1 += 128; - } - - for(i = 0; i < 16; i++) { - k1 = &do_pc2[0][0]; - - v1 = (v1 << rots[i]) | (v1 >> (28 - rots[i])); - v = k1[(v1 >> 21) & 0x7f]; k1 += 128; - v |= k1[(v1 >> 14) & 0x7f]; k1 += 128; - v |= k1[(v1 >> 7) & 0x7f]; k1 += 128; - v |= k1[(v1 ) & 0x7f]; k1 += 128; - -#ifdef _UFC_32_ - *k2++ = v; - v = 0; -#endif -#ifdef _UFC_64_ - v <<= 32; -#endif - - v2 = (v2 << rots[i]) | (v2 >> (28 - rots[i])); - v |= k1[(v2 >> 21) & 0x7f]; k1 += 128; - v |= k1[(v2 >> 14) & 0x7f]; k1 += 128; - v |= k1[(v2 >> 7) & 0x7f]; k1 += 128; - v |= k1[(v2 ) & 0x7f]; - - *k2++ = v; - } - - direction = 0; - } - -/* - * Undo an extra E selection and do final permutations - */ - -ufc_long *_ufc_dofinalperm(ufc_long l1, ufc_long l2, ufc_long r1, ufc_long r2) - { ufc_long v1, v2, x; - static ufc_long ary[2]; - - x = (l1 ^ l2) & current_saltbits; l1 ^= x; l2 ^= x; - x = (r1 ^ r2) & current_saltbits; r1 ^= x; r2 ^= x; - - v1=v2=0; l1 >>= 3; l2 >>= 3; r1 >>= 3; r2 >>= 3; - - v1 |= efp[15][ r2 & 0x3f][0]; v2 |= efp[15][ r2 & 0x3f][1]; - v1 |= efp[14][(r2 >>= 6) & 0x3f][0]; v2 |= efp[14][ r2 & 0x3f][1]; - v1 |= efp[13][(r2 >>= 10) & 0x3f][0]; v2 |= efp[13][ r2 & 0x3f][1]; - v1 |= efp[12][(r2 >>= 6) & 0x3f][0]; v2 |= efp[12][ r2 & 0x3f][1]; - - v1 |= efp[11][ r1 & 0x3f][0]; v2 |= efp[11][ r1 & 0x3f][1]; - v1 |= efp[10][(r1 >>= 6) & 0x3f][0]; v2 |= efp[10][ r1 & 0x3f][1]; - v1 |= efp[ 9][(r1 >>= 10) & 0x3f][0]; v2 |= efp[ 9][ r1 & 0x3f][1]; - v1 |= efp[ 8][(r1 >>= 6) & 0x3f][0]; v2 |= efp[ 8][ r1 & 0x3f][1]; - - v1 |= efp[ 7][ l2 & 0x3f][0]; v2 |= efp[ 7][ l2 & 0x3f][1]; - v1 |= efp[ 6][(l2 >>= 6) & 0x3f][0]; v2 |= efp[ 6][ l2 & 0x3f][1]; - v1 |= efp[ 5][(l2 >>= 10) & 0x3f][0]; v2 |= efp[ 5][ l2 & 0x3f][1]; - v1 |= efp[ 4][(l2 >>= 6) & 0x3f][0]; v2 |= efp[ 4][ l2 & 0x3f][1]; - - v1 |= efp[ 3][ l1 & 0x3f][0]; v2 |= efp[ 3][ l1 & 0x3f][1]; - v1 |= efp[ 2][(l1 >>= 6) & 0x3f][0]; v2 |= efp[ 2][ l1 & 0x3f][1]; - v1 |= efp[ 1][(l1 >>= 10) & 0x3f][0]; v2 |= efp[ 1][ l1 & 0x3f][1]; - v1 |= efp[ 0][(l1 >>= 6) & 0x3f][0]; v2 |= efp[ 0][ l1 & 0x3f][1]; - - ary[0] = v1; ary[1] = v2; - return ary; - } - -/* - * crypt only: convert from 64 bit to 11 bit ASCII - * prefixing with the salt - */ - -static char *output_conversion(ufc_long v1, ufc_long v2, const char *salt) - { static char outbuf[14]; - int i, s; - - outbuf[0] = salt[0]; - outbuf[1] = salt[1] ? salt[1] : salt[0]; - - for(i = 0; i < 5; i++) - outbuf[i + 2] = bin_to_ascii((v1 >> (26 - 6 * i)) & 0x3f); - - s = (v2 & 0xf) << 2; - v2 = (v2 >> 2) | ((v1 & 0x3) << 30); - - for(i = 5; i < 10; i++) - outbuf[i + 2] = bin_to_ascii((v2 >> (56 - 6 * i)) & 0x3f); - - outbuf[12] = bin_to_ascii(s); - outbuf[13] = 0; - - return outbuf; - } - -/* - * UNIX crypt function - */ - -static ufc_long *_ufc_doit(ufc_long , ufc_long, ufc_long, ufc_long, ufc_long); - -char *ufc_crypt(const char *key,const char *salt) - { ufc_long *s; - char ktab[9]; - - /* - * Hack DES tables according to salt - */ - setup_salt(salt); - - /* - * Setup key schedule - */ - clearmem(ktab, sizeof ktab); - strncpy(ktab, key, 8); - ufc_mk_keytab(ktab); - - /* - * Go for the 25 DES encryptions - */ - s = _ufc_doit((ufc_long)0, (ufc_long)0, - (ufc_long)0, (ufc_long)0, (ufc_long)25); - - /* - * And convert back to 6 bit ASCII - */ - return output_conversion(s[0], s[1], salt); - } - - -#ifdef _UFC_32_ - -/* - * 32 bit version - */ - -extern long32 _ufc_keytab[16][2]; -extern long32 _ufc_sb0[], _ufc_sb1[], _ufc_sb2[], _ufc_sb3[]; - -#define SBA(sb, v) (*(long32*)((char*)(sb)+(v))) - -static ufc_long *_ufc_doit(ufc_long l1, ufc_long l2, ufc_long r1, ufc_long r2, ufc_long itr) - { int i; - long32 s, *k; - - while(itr--) { - k = &_ufc_keytab[0][0]; - for(i=8; i--; ) { - s = *k++ ^ r1; - l1 ^= SBA(_ufc_sb1, s & 0xffff); l2 ^= SBA(_ufc_sb1, (s & 0xffff)+4); - l1 ^= SBA(_ufc_sb0, s >>= 16); l2 ^= SBA(_ufc_sb0, (s) +4); - s = *k++ ^ r2; - l1 ^= SBA(_ufc_sb3, s & 0xffff); l2 ^= SBA(_ufc_sb3, (s & 0xffff)+4); - l1 ^= SBA(_ufc_sb2, s >>= 16); l2 ^= SBA(_ufc_sb2, (s) +4); - - s = *k++ ^ l1; - r1 ^= SBA(_ufc_sb1, s & 0xffff); r2 ^= SBA(_ufc_sb1, (s & 0xffff)+4); - r1 ^= SBA(_ufc_sb0, s >>= 16); r2 ^= SBA(_ufc_sb0, (s) +4); - s = *k++ ^ l2; - r1 ^= SBA(_ufc_sb3, s & 0xffff); r2 ^= SBA(_ufc_sb3, (s & 0xffff)+4); - r1 ^= SBA(_ufc_sb2, s >>= 16); r2 ^= SBA(_ufc_sb2, (s) +4); - } - s=l1; l1=r1; r1=s; s=l2; l2=r2; r2=s; - } - return _ufc_dofinalperm(l1, l2, r1, r2); - } - -#endif - -#ifdef _UFC_64_ - -/* - * 64 bit version - */ - -extern long64 _ufc_keytab[16]; -extern long64 _ufc_sb0[], _ufc_sb1[], _ufc_sb2[], _ufc_sb3[]; - -#define SBA(sb, v) (*(long64*)((char*)(sb)+(v))) - -static ufc_long *_ufc_doit(ufc_long l1, ufc_long l2, ufc_long r1, ufc_long r2, ufc_long itr) - { int i; - long64 l, r, s, *k; - - l = (((long64)l1) << 32) | ((long64)l2); - r = (((long64)r1) << 32) | ((long64)r2); - - while(itr--) { - k = &_ufc_keytab[0]; - for(i=8; i--; ) { - s = *k++ ^ r; - l ^= SBA(_ufc_sb3, (s >> 0) & 0xffff); - l ^= SBA(_ufc_sb2, (s >> 16) & 0xffff); - l ^= SBA(_ufc_sb1, (s >> 32) & 0xffff); - l ^= SBA(_ufc_sb0, (s >> 48) & 0xffff); - - s = *k++ ^ l; - r ^= SBA(_ufc_sb3, (s >> 0) & 0xffff); - r ^= SBA(_ufc_sb2, (s >> 16) & 0xffff); - r ^= SBA(_ufc_sb1, (s >> 32) & 0xffff); - r ^= SBA(_ufc_sb0, (s >> 48) & 0xffff); - } - s=l; l=r; r=s; - } - - l1 = l >> 32; l2 = l & 0xffffffff; - r1 = r >> 32; r2 = r & 0xffffffff; - return _ufc_dofinalperm(l1, l2, r1, r2); - } - -#endif - - -#else - int ufc_dummy_procedure(void); - int ufc_dummy_procedure(void) {return 0;} -#endif diff --git a/bundled/replace/crypt.m4 b/bundled/replace/crypt.m4 deleted file mode 100644 index fae2a586..00000000 --- a/bundled/replace/crypt.m4 +++ /dev/null @@ -1,6 +0,0 @@ -############################################### -# test for where we get crypt() from -AC_CHECK_HEADERS(crypt.h) -AC_SEARCH_LIBS_EXT(crypt, [crypt], CRYPT_LIBS, - [ AC_DEFINE(HAVE_CRYPT,1,[Whether the system has the crypt() function]) ], - [ LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/crypt.o" ]) diff --git a/bundled/replace/dlfcn.c b/bundled/replace/dlfcn.c deleted file mode 100644 index 88431ed5..00000000 --- a/bundled/replace/dlfcn.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba system utilities - Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) Jeremy Allison 1998-2002 - Copyright (C) Jelmer Vernooij 2006 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "replace.h" -#ifdef HAVE_DL_H -#include -#endif - -#ifndef HAVE_DLOPEN -#ifdef DLOPEN_TAKES_UNSIGNED_FLAGS -void *rep_dlopen(const char *name, unsigned int flags) -#else -void *rep_dlopen(const char *name, int flags) -#endif -{ -#ifdef HAVE_SHL_LOAD - if (name == NULL) - return PROG_HANDLE; - return (void *)shl_load(name, flags, 0); -#else - return NULL; -#endif -} -#endif - -#ifndef HAVE_DLSYM -void *rep_dlsym(void *handle, const char *symbol) -{ -#ifdef HAVE_SHL_FINDSYM - void *sym_addr; - if (!shl_findsym((shl_t *)&handle, symbol, TYPE_UNDEFINED, &sym_addr)) - return sym_addr; -#endif - return NULL; -} -#endif - -#ifndef HAVE_DLERROR -char *rep_dlerror(void) -{ - return "dynamic loading of objects not supported on this platform"; -} -#endif - -#ifndef HAVE_DLCLOSE -int rep_dlclose(void *handle) -{ -#ifdef HAVE_SHL_CLOSE - return shl_unload((shl_t)handle); -#else - return 0; -#endif -} -#endif diff --git a/bundled/replace/dlfcn.m4 b/bundled/replace/dlfcn.m4 deleted file mode 100644 index 722e0246..00000000 --- a/bundled/replace/dlfcn.m4 +++ /dev/null @@ -1,31 +0,0 @@ -dnl dummies provided by dlfcn.c if not available -save_LIBS="$LIBS" -LIBS="" - -libreplace_cv_dlfcn=no -AC_SEARCH_LIBS(dlopen, dl) - -AC_CHECK_HEADERS(dlfcn.h) -AC_CHECK_FUNCS([dlopen dlsym dlerror dlclose],[],[libreplace_cv_dlfcn=yes]) - -libreplace_cv_shl=no -AC_SEARCH_LIBS(shl_load, sl) -AC_CHECK_HEADERS(dl.h) -AC_CHECK_FUNCS([shl_load shl_unload shl_findsym],[],[libreplace_cv_shl=yes]) - -AC_VERIFY_C_PROTOTYPE([void *dlopen(const char* filename, unsigned int flags)], - [ - return 0; - ],[ - AC_DEFINE(DLOPEN_TAKES_UNSIGNED_FLAGS, 1, [Whether dlopen takes unsigned int flags]) - ],[],[ - #include - ]) - -if test x"${libreplace_cv_dlfcn}" = x"yes";then - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/dlfcn.o" -fi - -LIBDL="$LIBS" -AC_SUBST(LIBDL) -LIBS="$save_LIBS" diff --git a/bundled/replace/getaddrinfo.c b/bundled/replace/getaddrinfo.c deleted file mode 100644 index c5cd52be..00000000 --- a/bundled/replace/getaddrinfo.c +++ /dev/null @@ -1,497 +0,0 @@ -/* -PostgreSQL Database Management System -(formerly known as Postgres, then as Postgres95) - -Portions Copyright (c) 1996-2005, The PostgreSQL Global Development Group - -Portions Copyright (c) 1994, The Regents of the University of California - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose, without fee, and without a written agreement -is hereby granted, provided that the above copyright notice and this paragraph -and the following two paragraphs appear in all copies. - -IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR -DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING -LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, -EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. - -THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS -TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - -*/ - -/*------------------------------------------------------------------------- - * - * getaddrinfo.c - * Support getaddrinfo() on platforms that don't have it. - * - * We also supply getnameinfo() here, assuming that the platform will have - * it if and only if it has getaddrinfo(). If this proves false on some - * platform, we'll need to split this file and provide a separate configure - * test for getnameinfo(). - * - * Copyright (c) 2003-2007, PostgreSQL Global Development Group - * - * Copyright (C) 2007 Jeremy Allison. - * Modified to return multiple IPv4 addresses for Samba. - * - *------------------------------------------------------------------------- - */ - -#include "replace.h" -#include "system/network.h" - -#ifndef SMB_MALLOC -#define SMB_MALLOC(s) malloc(s) -#endif - -#ifndef SMB_STRDUP -#define SMB_STRDUP(s) strdup(s) -#endif - -static int check_hostent_err(struct hostent *hp) -{ - if (!hp) { - switch (h_errno) { - case HOST_NOT_FOUND: - case NO_DATA: - return EAI_NONAME; - case TRY_AGAIN: - return EAI_AGAIN; - case NO_RECOVERY: - default: - return EAI_FAIL; - } - } - if (!hp->h_name || hp->h_addrtype != AF_INET) { - return EAI_FAIL; - } - return 0; -} - -static char *canon_name_from_hostent(struct hostent *hp, - int *perr) -{ - char *ret = NULL; - - *perr = check_hostent_err(hp); - if (*perr) { - return NULL; - } - ret = SMB_STRDUP(hp->h_name); - if (!ret) { - *perr = EAI_MEMORY; - } - return ret; -} - -static char *get_my_canon_name(int *perr) -{ - char name[HOST_NAME_MAX+1]; - - if (gethostname(name, HOST_NAME_MAX) == -1) { - *perr = EAI_FAIL; - return NULL; - } - /* Ensure null termination. */ - name[HOST_NAME_MAX] = '\0'; - return canon_name_from_hostent(gethostbyname(name), perr); -} - -static char *get_canon_name_from_addr(struct in_addr ip, - int *perr) -{ - return canon_name_from_hostent( - gethostbyaddr(&ip, sizeof(ip), AF_INET), - perr); -} - -static struct addrinfo *alloc_entry(const struct addrinfo *hints, - struct in_addr ip, - unsigned short port) -{ - struct sockaddr_in *psin = NULL; - struct addrinfo *ai = SMB_MALLOC(sizeof(*ai)); - - if (!ai) { - return NULL; - } - memset(ai, '\0', sizeof(*ai)); - - psin = SMB_MALLOC(sizeof(*psin)); - if (!psin) { - free(ai); - return NULL; - } - - memset(psin, '\0', sizeof(*psin)); - - psin->sin_family = AF_INET; - psin->sin_port = htons(port); - psin->sin_addr = ip; - - ai->ai_flags = 0; - ai->ai_family = AF_INET; - ai->ai_socktype = hints->ai_socktype; - ai->ai_protocol = hints->ai_protocol; - ai->ai_addrlen = sizeof(*psin); - ai->ai_addr = (struct sockaddr *) psin; - ai->ai_canonname = NULL; - ai->ai_next = NULL; - - return ai; -} - -/* - * get address info for a single ipv4 address. - * - * Bugs: - servname can only be a number, not text. - */ - -static int getaddr_info_single_addr(const char *service, - uint32_t addr, - const struct addrinfo *hints, - struct addrinfo **res) -{ - - struct addrinfo *ai = NULL; - struct in_addr ip; - unsigned short port = 0; - - if (service) { - port = (unsigned short)atoi(service); - } - ip.s_addr = htonl(addr); - - ai = alloc_entry(hints, ip, port); - if (!ai) { - return EAI_MEMORY; - } - - /* If we're asked for the canonical name, - * make sure it returns correctly. */ - if (!(hints->ai_flags & AI_NUMERICSERV) && - hints->ai_flags & AI_CANONNAME) { - int err; - if (addr == INADDR_LOOPBACK || addr == INADDR_ANY) { - ai->ai_canonname = get_my_canon_name(&err); - } else { - ai->ai_canonname = - get_canon_name_from_addr(ip,&err); - } - if (ai->ai_canonname == NULL) { - freeaddrinfo(ai); - return err; - } - } - - *res = ai; - return 0; -} - -/* - * get address info for multiple ipv4 addresses. - * - * Bugs: - servname can only be a number, not text. - */ - -static int getaddr_info_name(const char *node, - const char *service, - const struct addrinfo *hints, - struct addrinfo **res) -{ - struct addrinfo *listp = NULL, *prevp = NULL; - char **pptr = NULL; - int err; - struct hostent *hp = NULL; - unsigned short port = 0; - - if (service) { - port = (unsigned short)atoi(service); - } - - hp = gethostbyname(node); - err = check_hostent_err(hp); - if (err) { - return err; - } - - for(pptr = hp->h_addr_list; *pptr; pptr++) { - struct in_addr ip = *(struct in_addr *)*pptr; - struct addrinfo *ai = alloc_entry(hints, ip, port); - - if (!ai) { - freeaddrinfo(listp); - return EAI_MEMORY; - } - - if (!listp) { - listp = ai; - prevp = ai; - ai->ai_canonname = SMB_STRDUP(hp->h_name); - if (!ai->ai_canonname) { - freeaddrinfo(listp); - return EAI_MEMORY; - } - } else { - prevp->ai_next = ai; - prevp = ai; - } - } - *res = listp; - return 0; -} - -/* - * get address info for ipv4 sockets. - * - * Bugs: - servname can only be a number, not text. - */ - -int rep_getaddrinfo(const char *node, - const char *service, - const struct addrinfo * hintp, - struct addrinfo ** res) -{ - struct addrinfo hints; - - /* Setup the hints struct. */ - if (hintp == NULL) { - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - } else { - memcpy(&hints, hintp, sizeof(hints)); - } - - if (hints.ai_family != AF_INET && hints.ai_family != AF_UNSPEC) { - return EAI_FAMILY; - } - - if (hints.ai_socktype == 0) { - hints.ai_socktype = SOCK_STREAM; - } - - if (!node && !service) { - return EAI_NONAME; - } - - if (node) { - if (node[0] == '\0') { - return getaddr_info_single_addr(service, - INADDR_ANY, - &hints, - res); - } else if (hints.ai_flags & AI_NUMERICHOST) { - struct in_addr ip; - if (!inet_aton(node, &ip)) { - return EAI_FAIL; - } - return getaddr_info_single_addr(service, - ntohl(ip.s_addr), - &hints, - res); - } else { - return getaddr_info_name(node, - service, - &hints, - res); - } - } else if (hints.ai_flags & AI_PASSIVE) { - return getaddr_info_single_addr(service, - INADDR_ANY, - &hints, - res); - } - return getaddr_info_single_addr(service, - INADDR_LOOPBACK, - &hints, - res); -} - - -void rep_freeaddrinfo(struct addrinfo *res) -{ - struct addrinfo *next = NULL; - - for (;res; res = next) { - next = res->ai_next; - if (res->ai_canonname) { - free(res->ai_canonname); - } - if (res->ai_addr) { - free(res->ai_addr); - } - free(res); - } -} - - -const char *rep_gai_strerror(int errcode) -{ -#ifdef HAVE_HSTRERROR - int hcode; - - switch (errcode) - { - case EAI_NONAME: - hcode = HOST_NOT_FOUND; - break; - case EAI_AGAIN: - hcode = TRY_AGAIN; - break; - case EAI_FAIL: - default: - hcode = NO_RECOVERY; - break; - } - - return hstrerror(hcode); -#else /* !HAVE_HSTRERROR */ - - switch (errcode) - { - case EAI_NONAME: - return "Unknown host"; - case EAI_AGAIN: - return "Host name lookup failure"; -#ifdef EAI_BADFLAGS - case EAI_BADFLAGS: - return "Invalid argument"; -#endif -#ifdef EAI_FAMILY - case EAI_FAMILY: - return "Address family not supported"; -#endif -#ifdef EAI_MEMORY - case EAI_MEMORY: - return "Not enough memory"; -#endif -#ifdef EAI_NODATA - case EAI_NODATA: - return "No host data of that type was found"; -#endif -#ifdef EAI_SERVICE - case EAI_SERVICE: - return "Class type not found"; -#endif -#ifdef EAI_SOCKTYPE - case EAI_SOCKTYPE: - return "Socket type not supported"; -#endif - default: - return "Unknown server error"; - } -#endif /* HAVE_HSTRERROR */ -} - -static int gethostnameinfo(const struct sockaddr *sa, - char *node, - size_t nodelen, - int flags) -{ - int ret = -1; - char *p = NULL; - - if (!(flags & NI_NUMERICHOST)) { - struct hostent *hp = gethostbyaddr( - &((struct sockaddr_in *)sa)->sin_addr, - sizeof(struct in_addr), - sa->sa_family); - ret = check_hostent_err(hp); - if (ret == 0) { - /* Name looked up successfully. */ - ret = snprintf(node, nodelen, "%s", hp->h_name); - if (ret < 0 || (size_t)ret >= nodelen) { - return EAI_MEMORY; - } - if (flags & NI_NOFQDN) { - p = strchr(node,'.'); - if (p) { - *p = '\0'; - } - } - return 0; - } - - if (flags & NI_NAMEREQD) { - /* If we require a name and didn't get one, - * automatically fail. */ - return ret; - } - /* Otherwise just fall into the numeric host code... */ - } - p = inet_ntoa(((struct sockaddr_in *)sa)->sin_addr); - ret = snprintf(node, nodelen, "%s", p); - if (ret < 0 || (size_t)ret >= nodelen) { - return EAI_MEMORY; - } - return 0; -} - -static int getservicenameinfo(const struct sockaddr *sa, - char *service, - size_t servicelen, - int flags) -{ - int ret = -1; - int port = ntohs(((struct sockaddr_in *)sa)->sin_port); - - if (!(flags & NI_NUMERICSERV)) { - struct servent *se = getservbyport( - port, - (flags & NI_DGRAM) ? "udp" : "tcp"); - if (se && se->s_name) { - /* Service name looked up successfully. */ - ret = snprintf(service, servicelen, "%s", se->s_name); - if (ret < 0 || (size_t)ret >= servicelen) { - return EAI_MEMORY; - } - return 0; - } - /* Otherwise just fall into the numeric service code... */ - } - ret = snprintf(service, servicelen, "%d", port); - if (ret < 0 || (size_t)ret >= servicelen) { - return EAI_MEMORY; - } - return 0; -} - -/* - * Convert an ipv4 address to a hostname. - * - * Bugs: - No IPv6 support. - */ -int rep_getnameinfo(const struct sockaddr *sa, socklen_t salen, - char *node, size_t nodelen, - char *service, size_t servicelen, int flags) -{ - - /* Invalid arguments. */ - if (sa == NULL || (node == NULL && service == NULL)) { - return EAI_FAIL; - } - - if (sa->sa_family != AF_INET) { - return EAI_FAIL; - } - - if (salen < sizeof(struct sockaddr_in)) { - return EAI_FAIL; - } - - if (node) { - return gethostnameinfo(sa, node, nodelen, flags); - } - - if (service) { - return getservicenameinfo(sa, service, servicelen, flags); - } - return 0; -} diff --git a/bundled/replace/getaddrinfo.h b/bundled/replace/getaddrinfo.h deleted file mode 100644 index cf040da2..00000000 --- a/bundled/replace/getaddrinfo.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -PostgreSQL Database Management System -(formerly known as Postgres, then as Postgres95) - -Portions Copyright (c) 1996-2005, The PostgreSQL Global Development Group - -Portions Copyright (c) 1994, The Regents of the University of California - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose, without fee, and without a written agreement -is hereby granted, provided that the above copyright notice and this paragraph -and the following two paragraphs appear in all copies. - -IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR -DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING -LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, -EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. - -THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS -TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - -*/ - -/*------------------------------------------------------------------------- - * - * getaddrinfo.h - * Support getaddrinfo() on platforms that don't have it. - * - * Note: we use our own routines on platforms that don't HAVE_STRUCT_ADDRINFO, - * whether or not the library routine getaddrinfo() can be found. This - * policy is needed because on some platforms a manually installed libbind.a - * may provide getaddrinfo(), yet the system headers may not provide the - * struct definitions needed to call it. To avoid conflict with the libbind - * definition in such cases, we rename our routines to pg_xxx() via macros. - * - -in lib/replace we use rep_xxx() - - * This code will also work on platforms where struct addrinfo is defined - * in the system headers but no getaddrinfo() can be located. - * - * Copyright (c) 2003-2007, PostgreSQL Global Development Group - * - *------------------------------------------------------------------------- - */ -#ifndef GETADDRINFO_H -#define GETADDRINFO_H - -#ifndef HAVE_GETADDRINFO - -/* Rename private copies per comments above */ -#ifdef getaddrinfo -#undef getaddrinfo -#endif -#define getaddrinfo rep_getaddrinfo -#define HAVE_GETADDRINFO - -#ifdef freeaddrinfo -#undef freeaddrinfo -#endif -#define freeaddrinfo rep_freeaddrinfo -#define HAVE_FREEADDRINFO - -#ifdef gai_strerror -#undef gai_strerror -#endif -#define gai_strerror rep_gai_strerror -#define HAVE_GAI_STRERROR - -#ifdef getnameinfo -#undef getnameinfo -#endif -#define getnameinfo rep_getnameinfo -#ifndef HAVE_GETNAMEINFO -#define HAVE_GETNAMEINFO -#endif - -extern int rep_getaddrinfo(const char *node, const char *service, - const struct addrinfo * hints, struct addrinfo ** res); -extern void rep_freeaddrinfo(struct addrinfo * res); -extern const char *rep_gai_strerror(int errcode); -extern int rep_getnameinfo(const struct sockaddr * sa, socklen_t salen, - char *node, size_t nodelen, - char *service, size_t servicelen, int flags); -#endif /* HAVE_GETADDRINFO */ - -#endif /* GETADDRINFO_H */ diff --git a/bundled/replace/getifaddrs.c b/bundled/replace/getifaddrs.c deleted file mode 100644 index 84d79068..00000000 --- a/bundled/replace/getifaddrs.c +++ /dev/null @@ -1,352 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - Copyright (C) Andrew Tridgell 1998 - Copyright (C) Jeremy Allison 2007 - Copyright (C) Jelmer Vernooij 2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#define SOCKET_WRAPPER_NOT_REPLACE - -#include "replace.h" -#include "system/network.h" - -#include -#include -#include - -#ifdef HAVE_SYS_TIME_H -#include -#endif - -#ifndef SIOCGIFCONF -#ifdef HAVE_SYS_SOCKIO_H -#include -#endif -#endif - -#ifdef HAVE_IFACE_GETIFADDRS -#define _FOUND_IFACE_ANY -#else - -void rep_freeifaddrs(struct ifaddrs *ifp) -{ - if (ifp != NULL) { - free(ifp->ifa_name); - free(ifp->ifa_addr); - free(ifp->ifa_netmask); - free(ifp->ifa_dstaddr); - freeifaddrs(ifp->ifa_next); - free(ifp); - } -} - -static struct sockaddr *sockaddr_dup(struct sockaddr *sa) -{ - struct sockaddr *ret; - socklen_t socklen; -#ifdef HAVE_SOCKADDR_SA_LEN - socklen = sa->sa_len; -#else - socklen = sizeof(struct sockaddr_storage); -#endif - ret = calloc(1, socklen); - if (ret == NULL) - return NULL; - memcpy(ret, sa, socklen); - return ret; -} -#endif - -#if HAVE_IFACE_IFCONF - -/* this works for Linux 2.2, Solaris 2.5, SunOS4, HPUX 10.20, OSF1 - V4.0, Ultrix 4.4, SCO Unix 3.2, IRIX 6.4 and FreeBSD 3.2. - - It probably also works on any BSD style system. */ - -int rep_getifaddrs(struct ifaddrs **ifap) -{ - struct ifconf ifc; - char buff[8192]; - int fd, i, n; - struct ifreq *ifr=NULL; - struct ifaddrs *curif; - struct ifaddrs *lastif = NULL; - - *ifap = NULL; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - return -1; - } - - ifc.ifc_len = sizeof(buff); - ifc.ifc_buf = buff; - - if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { - close(fd); - return -1; - } - - ifr = ifc.ifc_req; - - n = ifc.ifc_len / sizeof(struct ifreq); - - /* Loop through interfaces, looking for given IP address */ - for (i=n-1; i>=0; i--) { - if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) == -1) { - freeifaddrs(*ifap); - return -1; - } - - curif = calloc(1, sizeof(struct ifaddrs)); - curif->ifa_name = strdup(ifr[i].ifr_name); - curif->ifa_flags = ifr[i].ifr_flags; - curif->ifa_dstaddr = NULL; - curif->ifa_data = NULL; - curif->ifa_next = NULL; - - curif->ifa_addr = NULL; - if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != -1) { - curif->ifa_addr = sockaddr_dup(&ifr[i].ifr_addr); - } - - curif->ifa_netmask = NULL; - if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != -1) { - curif->ifa_netmask = sockaddr_dup(&ifr[i].ifr_addr); - } - - if (lastif == NULL) { - *ifap = curif; - } else { - lastif->ifa_next = curif; - } - lastif = curif; - } - - close(fd); - - return 0; -} - -#define _FOUND_IFACE_ANY -#endif /* HAVE_IFACE_IFCONF */ -#ifdef HAVE_IFACE_IFREQ - -#ifndef I_STR -#include -#endif - -/**************************************************************************** -this should cover most of the streams based systems -Thanks to Andrej.Borsenkow@mow.siemens.ru for several ideas in this code -****************************************************************************/ -int rep_getifaddrs(struct ifaddrs **ifap) -{ - struct ifreq ifreq; - struct strioctl strioctl; - char buff[8192]; - int fd, i, n; - struct ifreq *ifr=NULL; - struct ifaddrs *curif; - struct ifaddrs *lastif = NULL; - - *ifap = NULL; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - return -1; - } - - strioctl.ic_cmd = SIOCGIFCONF; - strioctl.ic_dp = buff; - strioctl.ic_len = sizeof(buff); - if (ioctl(fd, I_STR, &strioctl) < 0) { - close(fd); - return -1; - } - - /* we can ignore the possible sizeof(int) here as the resulting - number of interface structures won't change */ - n = strioctl.ic_len / sizeof(struct ifreq); - - /* we will assume that the kernel returns the length as an int - at the start of the buffer if the offered size is a - multiple of the structure size plus an int */ - if (n*sizeof(struct ifreq) + sizeof(int) == strioctl.ic_len) { - ifr = (struct ifreq *)(buff + sizeof(int)); - } else { - ifr = (struct ifreq *)buff; - } - - /* Loop through interfaces */ - - for (i = 0; iifa_next = curif; - } - - strioctl.ic_cmd = SIOCGIFFLAGS; - strioctl.ic_dp = (char *)&ifreq; - strioctl.ic_len = sizeof(struct ifreq); - if (ioctl(fd, I_STR, &strioctl) != 0) { - freeifaddrs(*ifap); - return -1; - } - - curif->ifa_flags = ifreq.ifr_flags; - - strioctl.ic_cmd = SIOCGIFADDR; - strioctl.ic_dp = (char *)&ifreq; - strioctl.ic_len = sizeof(struct ifreq); - if (ioctl(fd, I_STR, &strioctl) != 0) { - freeifaddrs(*ifap); - return -1; - } - - curif->ifa_name = strdup(ifreq.ifr_name); - curif->ifa_addr = sockaddr_dup(&ifreq.ifr_addr); - curif->ifa_dstaddr = NULL; - curif->ifa_data = NULL; - curif->ifa_next = NULL; - curif->ifa_netmask = NULL; - - strioctl.ic_cmd = SIOCGIFNETMASK; - strioctl.ic_dp = (char *)&ifreq; - strioctl.ic_len = sizeof(struct ifreq); - if (ioctl(fd, I_STR, &strioctl) != 0) { - freeifaddrs(*ifap); - return -1; - } - - curif->ifa_netmask = sockaddr_dup(&ifreq.ifr_addr); - - lastif = curif; - } - - close(fd); - - return 0; -} - -#define _FOUND_IFACE_ANY -#endif /* HAVE_IFACE_IFREQ */ -#ifdef HAVE_IFACE_AIX - -/**************************************************************************** -this one is for AIX (tested on 4.2) -****************************************************************************/ -int rep_getifaddrs(struct ifaddrs **ifap) -{ - char buff[8192]; - int fd, i; - struct ifconf ifc; - struct ifreq *ifr=NULL; - struct ifaddrs *curif; - struct ifaddrs *lastif = NULL; - - *ifap = NULL; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - return -1; - } - - ifc.ifc_len = sizeof(buff); - ifc.ifc_buf = buff; - - if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { - close(fd); - return -1; - } - - ifr = ifc.ifc_req; - - /* Loop through interfaces */ - i = ifc.ifc_len; - - while (i > 0) { - unsigned int inc; - - inc = ifr->ifr_addr.sa_len; - - if (ioctl(fd, SIOCGIFADDR, ifr) != 0) { - freeaddrinfo(*ifap); - return -1; - } - - curif = calloc(1, sizeof(struct ifaddrs)); - if (lastif == NULL) { - *ifap = curif; - } else { - lastif->ifa_next = curif; - } - - curif->ifa_name = strdup(ifr->ifr_name); - curif->ifa_addr = sockaddr_dup(&ifr->ifr_addr); - curif->ifa_dstaddr = NULL; - curif->ifa_data = NULL; - curif->ifa_netmask = NULL; - curif->ifa_next = NULL; - - if (ioctl(fd, SIOCGIFFLAGS, ifr) != 0) { - freeaddrinfo(*ifap); - return -1; - } - - curif->ifa_flags = ifr->ifr_flags; - - if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) { - freeaddrinfo(*ifap); - return -1; - } - - curif->ifa_netmask = sockaddr_dup(&ifr->ifr_addr); - - lastif = curif; - - next: - /* - * Patch from Archie Cobbs (archie@whistle.com). The - * addresses in the SIOCGIFCONF interface list have a - * minimum size. Usually this doesn't matter, but if - * your machine has tunnel interfaces, etc. that have - * a zero length "link address", this does matter. */ - - if (inc < sizeof(ifr->ifr_addr)) - inc = sizeof(ifr->ifr_addr); - inc += IFNAMSIZ; - - ifr = (struct ifreq*) (((char*) ifr) + inc); - i -= inc; - } - - close(fd); - return 0; -} - -#define _FOUND_IFACE_ANY -#endif /* HAVE_IFACE_AIX */ -#ifndef _FOUND_IFACE_ANY -int rep_getifaddrs(struct ifaddrs **ifap) -{ - errno = ENOSYS; - return -1; -} -#endif diff --git a/bundled/replace/getpass.c b/bundled/replace/getpass.c deleted file mode 100644 index f95109f2..00000000 --- a/bundled/replace/getpass.c +++ /dev/null @@ -1,218 +0,0 @@ -/* Copyright (C) 1992-1998 Free Software Foundation, Inc. -This file is part of the GNU C Library. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public License as -published by the Free Software Foundation; either version 3 of the -License, or (at your option) any later version. - -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, see . */ - -/* Modified to use with samba by Jeremy Allison, 8th July 1995. */ - -#include "replace.h" -#include "system/filesys.h" -#include "system/wait.h" -#include "system/terminal.h" -#include "system/passwd.h" - -/* - * Define additional missing types - */ -#ifndef HAVE_SIG_ATOMIC_T_TYPE -typedef int sig_atomic_t; -#endif - -#ifndef SIGCLD -#define SIGCLD SIGCHLD -#endif - -#ifdef SYSV_TERMIO - -/* SYSTEM V TERMIO HANDLING */ - -static struct termio t; - -#define ECHO_IS_ON(t) ((t).c_lflag & ECHO) -#define TURN_ECHO_OFF(t) ((t).c_lflag &= ~ECHO) -#define TURN_ECHO_ON(t) ((t).c_lflag |= ECHO) - -#ifndef TCSAFLUSH -#define TCSAFLUSH 1 -#endif - -#ifndef TCSANOW -#define TCSANOW 0 -#endif - -static int tcgetattr(int fd, struct termio *_t) -{ - return ioctl(fd, TCGETA, _t); -} - -static int tcsetattr(int fd, int flags, struct termio *_t) -{ - if(flags & TCSAFLUSH) - ioctl(fd, TCFLSH, TCIOFLUSH); - return ioctl(fd, TCSETS, _t); -} - -#elif !defined(TCSAFLUSH) - -/* BSD TERMIO HANDLING */ - -static struct sgttyb t; - -#define ECHO_IS_ON(t) ((t).sg_flags & ECHO) -#define TURN_ECHO_OFF(t) ((t).sg_flags &= ~ECHO) -#define TURN_ECHO_ON(t) ((t).sg_flags |= ECHO) - -#define TCSAFLUSH 1 -#define TCSANOW 0 - -static int tcgetattr(int fd, struct sgttyb *_t) -{ - return ioctl(fd, TIOCGETP, (char *)_t); -} - -static int tcsetattr(int fd, int flags, struct sgttyb *_t) -{ - return ioctl(fd, TIOCSETP, (char *)_t); -} - -#else /* POSIX TERMIO HANDLING */ -#define ECHO_IS_ON(t) ((t).c_lflag & ECHO) -#define TURN_ECHO_OFF(t) ((t).c_lflag &= ~ECHO) -#define TURN_ECHO_ON(t) ((t).c_lflag |= ECHO) - -static struct termios t; -#endif /* SYSV_TERMIO */ - -static void catch_signal(int signum, void (*handler)(int )) -{ -#ifdef HAVE_SIGACTION - struct sigaction act; - struct sigaction oldact; - - memset(&act, 0, sizeof(act)); - - act.sa_handler = handler; -#ifdef SA_RESTART - /* - * We *want* SIGALRM to interrupt a system call. - */ - if(signum != SIGALRM) - act.sa_flags = SA_RESTART; -#endif - sigemptyset(&act.sa_mask); - sigaddset(&act.sa_mask,signum); - sigaction(signum,&act,&oldact); -#else /* !HAVE_SIGACTION */ - /* FIXME: need to handle sigvec and systems with broken signal() */ - signal(signum, handler); -#endif -} - -static sig_atomic_t gotintr; -static int in_fd = -1; - -/*************************************************************** - Signal function to tell us were ^C'ed. -****************************************************************/ - -static void gotintr_sig(int signum) -{ - gotintr = 1; - if (in_fd != -1) - close(in_fd); /* Safe way to force a return. */ - in_fd = -1; -} - -char *rep_getpass(const char *prompt) -{ - FILE *in, *out; - int echo_off; - static char buf[256]; - static size_t bufsize = sizeof(buf); - size_t nread; - - /* Catch problematic signals */ - catch_signal(SIGINT, gotintr_sig); - - /* Try to write to and read from the terminal if we can. - If we can't open the terminal, use stderr and stdin. */ - - in = fopen ("/dev/tty", "w+"); - if (in == NULL) { - in = stdin; - out = stderr; - } else { - out = in; - } - - setvbuf(in, NULL, _IONBF, 0); - - /* Turn echoing off if it is on now. */ - - if (tcgetattr (fileno (in), &t) == 0) { - if (ECHO_IS_ON(t)) { - TURN_ECHO_OFF(t); - echo_off = tcsetattr (fileno (in), TCSAFLUSH, &t) == 0; - TURN_ECHO_ON(t); - } else { - echo_off = 0; - } - } else { - echo_off = 0; - } - - /* Write the prompt. */ - fputs(prompt, out); - fflush(out); - - /* Read the password. */ - buf[0] = 0; - if (!gotintr) { - in_fd = fileno(in); - if (fgets(buf, bufsize, in) == NULL) { - buf[0] = 0; - } - } - nread = strlen(buf); - if (nread) { - if (buf[nread - 1] == '\n') - buf[nread - 1] = '\0'; - } - - /* Restore echoing. */ - if (echo_off) { - if (gotintr && in_fd == -1) { - in = fopen ("/dev/tty", "w+"); - } - if (in != NULL) - tcsetattr (fileno (in), TCSANOW, &t); - } - - fprintf(out, "\n"); - fflush(out); - - if (in && in != stdin) /* We opened the terminal; now close it. */ - fclose(in); - - /* Catch problematic signals */ - catch_signal(SIGINT, SIG_DFL); - - if (gotintr) { - printf("Interrupted by signal.\n"); - fflush(stdout); - exit(1); - } - return buf; -} diff --git a/bundled/replace/getpass.m4 b/bundled/replace/getpass.m4 deleted file mode 100644 index 78a0afe4..00000000 --- a/bundled/replace/getpass.m4 +++ /dev/null @@ -1,24 +0,0 @@ -AC_CHECK_FUNC(getpass, libreplace_cv_HAVE_GETPASS=yes) -AC_CHECK_FUNC(getpassphrase, libreplace_cv_HAVE_GETPASSPHRASE=yes) -if test x"$libreplace_cv_HAVE_GETPASS" = x"yes" -a x"$libreplace_cv_HAVE_GETPASSPHRASE" = x"yes"; then - AC_DEFINE(REPLACE_GETPASS_BY_GETPASSPHRASE, 1, [getpass returns <9 chars where getpassphrase returns <265 chars]) - AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced]) - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/getpass.o" -else - -AC_CACHE_CHECK([whether getpass should be replaced],libreplace_cv_REPLACE_GETPASS,[ -SAVE_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="$CPPFLAGS -I$libreplacedir/" -AC_TRY_COMPILE([ -#include "confdefs.h" -#define NO_CONFIG_H -#include "$libreplacedir/getpass.c" -],[],libreplace_cv_REPLACE_GETPASS=yes,libreplace_cv_REPLACE_GETPASS=no) -CPPFLAGS="$SAVE_CPPFLAGS" -]) -if test x"$libreplace_cv_REPLACE_GETPASS" = x"yes"; then - AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced]) - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/getpass.o" -fi - -fi diff --git a/bundled/replace/hdr_replace.h b/bundled/replace/hdr_replace.h deleted file mode 100644 index 6cfa50f8..00000000 --- a/bundled/replace/hdr_replace.h +++ /dev/null @@ -1,2 +0,0 @@ -/* this is a replacement header for a missing system header */ -#include "replace.h" diff --git a/bundled/replace/inet_aton.c b/bundled/replace/inet_aton.c deleted file mode 100644 index c6b3bb11..00000000 --- a/bundled/replace/inet_aton.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * replacement functions - * Copyright (C) Michael Adam 2008 - * - * ** NOTE! The following LGPL license applies to the replace - * ** library. This does NOT imply that all of Samba is released - * ** under the LGPL - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see . - */ - -#include "replace.h" -#include "system/network.h" - -/** - * We know that we have inet_pton from earlier libreplace checks. - */ -int rep_inet_aton(const char *src, struct in_addr *dst) -{ - return (inet_pton(AF_INET, src, dst) > 0) ? 1 : 0; -} diff --git a/bundled/replace/inet_ntoa.c b/bundled/replace/inet_ntoa.c deleted file mode 100644 index e3b80ebe..00000000 --- a/bundled/replace/inet_ntoa.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * replacement routines for broken systems - * Copyright (C) Andrew Tridgell 2003 - * Copyright (C) Michael Adam 2008 - * - * ** NOTE! The following LGPL license applies to the replace - * ** library. This does NOT imply that all of Samba is released - * ** under the LGPL - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see . - */ - -#include "replace.h" -#include "system/network.h" - -/** - * NOTE: this is not thread safe, but it can't be, either - * since it returns a pointer to static memory. - */ -char *rep_inet_ntoa(struct in_addr ip) -{ - uint8_t *p = (uint8_t *)&ip.s_addr; - static char buf[18]; - slprintf(buf, 17, "%d.%d.%d.%d", - (int)p[0], (int)p[1], (int)p[2], (int)p[3]); - return buf; -} diff --git a/bundled/replace/inet_ntop.c b/bundled/replace/inet_ntop.c deleted file mode 100644 index fb3d8e90..00000000 --- a/bundled/replace/inet_ntop.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (C) 1996-2001 Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - - -#include "replace.h" -#include "system/network.h" - -#define NS_INT16SZ 2 -#define NS_IN6ADDRSZ 16 - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -static const char *inet_ntop4(const unsigned char *src, char *dst, - socklen_t size); - -#ifdef AF_INET6 -static const char *inet_ntop6(const unsigned char *src, char *dst, - socklen_t size); -#endif - -/* char * - * isc_net_ntop(af, src, dst, size) - * convert a network format address to presentation format. - * return: - * pointer to presentation format address (`dst'), or NULL (see errno). - * author: - * Paul Vixie, 1996. - */ -const char * -rep_inet_ntop(int af, const void *src, char *dst, socklen_t size) -{ - switch (af) { - case AF_INET: - return (inet_ntop4(src, dst, size)); -#ifdef AF_INET6 - case AF_INET6: - return (inet_ntop6(src, dst, size)); -#endif - default: - errno = EAFNOSUPPORT; - return (NULL); - } - /* NOTREACHED */ -} - -/* const char * - * inet_ntop4(src, dst, size) - * format an IPv4 address - * return: - * `dst' (as a const) - * notes: - * (1) uses no statics - * (2) takes a unsigned char* not an in_addr as input - * author: - * Paul Vixie, 1996. - */ -static const char * -inet_ntop4(const unsigned char *src, char *dst, socklen_t size) -{ - static const char *fmt = "%u.%u.%u.%u"; - char tmp[sizeof "255.255.255.255"]; - size_t len; - - len = snprintf(tmp, sizeof tmp, fmt, src[0], src[1], src[2], src[3]); - if (len >= size) { - errno = ENOSPC; - return (NULL); - } - memcpy(dst, tmp, len + 1); - - return (dst); -} - -/* const char * - * isc_inet_ntop6(src, dst, size) - * convert IPv6 binary address into presentation (printable) format - * author: - * Paul Vixie, 1996. - */ -#ifdef AF_INET6 -static const char * -inet_ntop6(const unsigned char *src, char *dst, socklen_t size) -{ - /* - * Note that int32_t and int16_t need only be "at least" large enough - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; - struct { int base, len; } best, cur; - unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ]; - int i, inc; - - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset(words, '\0', sizeof words); - for (i = 0; i < NS_IN6ADDRSZ; i++) - words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); - best.base = -1; - best.len = 0; - cur.base = -1; - cur.len = 0; - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { - if (words[i] == 0) { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } else { - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - } - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - } - if (best.base != -1 && best.len < 2) - best.base = -1; - - /* - * Format the result. - */ - tp = tmp; - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { - /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && - i < (best.base + best.len)) { - if (i == best.base) - *tp++ = ':'; - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) - *tp++ = ':'; - /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { - if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) - return (NULL); - tp += strlen(tp); - break; - } - inc = snprintf(tp, 5, "%x", words[i]); - if (inc >= 5) { - abort(); - } - tp += inc; - } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == - (NS_IN6ADDRSZ / NS_INT16SZ)) - *tp++ = ':'; - *tp++ = '\0'; - - /* - * Check for overflow, copy, and we're done. - */ - if ((size_t)(tp - tmp) > size) { - errno = ENOSPC; - return (NULL); - } - memcpy(dst, tmp, tp - tmp); - return (dst); -} -#endif /* AF_INET6 */ diff --git a/bundled/replace/inet_pton.c b/bundled/replace/inet_pton.c deleted file mode 100644 index 80e4865e..00000000 --- a/bundled/replace/inet_pton.c +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (C) 1996-2001 Internet Software Consortium. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM - * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL - * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "replace.h" -#include "system/network.h" - -#define NS_INT16SZ 2 -#define NS_INADDRSZ 4 -#define NS_IN6ADDRSZ 16 - -/* - * WARNING: Don't even consider trying to compile this on a system where - * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. - */ - -static int inet_pton4(const char *src, unsigned char *dst); -#ifdef AF_INET6 -static int inet_pton6(const char *src, unsigned char *dst); -#endif - -/* int - * inet_pton(af, src, dst) - * convert from presentation format (which usually means ASCII printable) - * to network format (which is usually some kind of binary format). - * return: - * 1 if the address was valid for the specified address family - * 0 if the address wasn't valid (`dst' is untouched in this case) - * -1 if some other error occurred (`dst' is untouched in this case, too) - * author: - * Paul Vixie, 1996. - */ -int -rep_inet_pton(int af, - const char *src, - void *dst) -{ - switch (af) { - case AF_INET: - return (inet_pton4(src, dst)); -#ifdef AF_INET6 - case AF_INET6: - return (inet_pton6(src, dst)); -#endif - default: - errno = EAFNOSUPPORT; - return (-1); - } - /* NOTREACHED */ -} - -/* int - * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. - * return: - * 1 if `src' is a valid dotted quad, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton4(src, dst) - const char *src; - unsigned char *dst; -{ - static const char digits[] = "0123456789"; - int saw_digit, octets, ch; - unsigned char tmp[NS_INADDRSZ], *tp; - - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr(digits, ch)) != NULL) { - unsigned int new = *tp * 10 + (pch - digits); - - if (new > 255) - return (0); - *tp = new; - if (! saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; - } - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } else - return (0); - } - if (octets < 4) - return (0); - memcpy(dst, tmp, NS_INADDRSZ); - return (1); -} - -/* int - * inet_pton6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ -#ifdef AF_INET6 -static int -inet_pton6(src, dst) - const char *src; - unsigned char *dst; -{ - static const char xdigits_l[] = "0123456789abcdef", - xdigits_u[] = "0123456789ABCDEF"; - unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp; - const char *xdigits, *curtok; - int ch, saw_xdigit; - unsigned int val; - - memset((tp = tmp), '\0', NS_IN6ADDRSZ); - endp = tp + NS_IN6ADDRSZ; - colonp = NULL; - /* Leading :: requires some special handling. */ - if (*src == ':') - if (*++src != ':') - return (0); - curtok = src; - saw_xdigit = 0; - val = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) - pch = strchr((xdigits = xdigits_u), ch); - if (pch != NULL) { - val <<= 4; - val |= (pch - xdigits); - if (val > 0xffff) - return (0); - saw_xdigit = 1; - continue; - } - if (ch == ':') { - curtok = src; - if (!saw_xdigit) { - if (colonp) - return (0); - colonp = tp; - continue; - } - if (tp + NS_INT16SZ > endp) - return (0); - *tp++ = (unsigned char) (val >> 8) & 0xff; - *tp++ = (unsigned char) val & 0xff; - saw_xdigit = 0; - val = 0; - continue; - } - if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) && - inet_pton4(curtok, tp) > 0) { - tp += NS_INADDRSZ; - saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ - } - return (0); - } - if (saw_xdigit) { - if (tp + NS_INT16SZ > endp) - return (0); - *tp++ = (unsigned char) (val >> 8) & 0xff; - *tp++ = (unsigned char) val & 0xff; - } - if (colonp != NULL) { - /* - * Since some memmove()'s erroneously fail to handle - * overlapping regions, we'll do the shift by hand. - */ - const int n = tp - colonp; - int i; - - for (i = 1; i <= n; i++) { - endp[- i] = colonp[n - i]; - colonp[n - i] = 0; - } - tp = endp; - } - if (tp != endp) - return (0); - memcpy(dst, tmp, NS_IN6ADDRSZ); - return (1); -} -#endif diff --git a/bundled/replace/install-sh b/bundled/replace/install-sh deleted file mode 100755 index 58719246..00000000 --- a/bundled/replace/install-sh +++ /dev/null @@ -1,238 +0,0 @@ -#! /bin/sh -# -# install - install a program, script, or datafile -# This comes from X11R5. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. -# - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -transformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 -else - true -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d $dst ]; then - instcmd=: - else - instcmd=mkdir - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f $src -o -d $src ] - then - true - else - echo "install: $src does not exist" - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "install: no destination specified" - exit 1 - else - true - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d $dst ] - then - dst="$dst"/`basename $src` - else - true - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' -' -IFS="${IFS-${defaultIFS}}" - -oIFS="${IFS}" -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS="${oIFS}" - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp="${pathcomp}${1}" - shift - - if [ ! -d "${pathcomp}" ] ; - then - $mkdirprog "${pathcomp}" - else - true - fi - - pathcomp="${pathcomp}/" -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd $dst && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename $dst` - else - dstfile=`basename $dst $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename $dst` - else - true - fi - -# Make a temp file name in the proper directory. - - dsttmp=$dstdir/#inst.$$# - -# Move or copy the file name to the temp name - - $doit $instcmd $src $dsttmp && - - trap "rm -f ${dsttmp}" 0 && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && - -# Now rename the file to the real destination. - - $doit $rmcmd -f $dstdir/$dstfile && - $doit $mvcmd $dsttmp $dstdir/$dstfile - -fi && - - -exit 0 diff --git a/bundled/replace/libreplace.m4 b/bundled/replace/libreplace.m4 deleted file mode 100644 index 2303641d..00000000 --- a/bundled/replace/libreplace.m4 +++ /dev/null @@ -1,319 +0,0 @@ -AC_DEFUN_ONCE(AC_LIBREPLACE_LOCATION_CHECKS, -[ -echo "LIBREPLACE_LOCATION_CHECKS: START" - -dnl find the libreplace sources. This is meant to work both for -dnl libreplace standalone builds, and builds of packages using libreplace -libreplacedir="" -libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace" -for d in $libreplacepaths; do - if test -f "$d/replace.c"; then - libreplacedir="$d" - AC_SUBST(libreplacedir) - break; - fi -done -if test x"$libreplacedir" = "x"; then - AC_MSG_ERROR([cannot find libreplace in $libreplacepaths]) -fi -LIBREPLACEOBJ="$libreplacedir/replace.o" -AC_SUBST(LIBREPLACEOBJ) - -AC_CANONICAL_BUILD -AC_CANONICAL_HOST -AC_CANONICAL_TARGET - -echo "LIBREPLACE_LOCATION_CHECKS: END" -]) dnl end AC_LIBREPLACE_LOCATION_CHECKS - - -AC_DEFUN_ONCE(AC_LIBREPLACE_BROKEN_CHECKS, -[ -echo "LIBREPLACE_BROKEN_CHECKS: START" - -dnl find the libreplace sources. This is meant to work both for -dnl libreplace standalone builds, and builds of packages using libreplace -libreplacedir="" -libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace" -for d in $libreplacepaths; do - if test -f "$d/replace.c"; then - libreplacedir="$d" - AC_SUBST(libreplacedir) - break; - fi -done -if test x"$libreplacedir" = "x"; then - AC_MSG_ERROR([cannot find libreplace in $libreplacepaths]) -fi - -LIBREPLACEOBJ="$libreplacedir/replace.o" -AC_SUBST(LIBREPLACEOBJ) - -LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/snprintf.o" - -AC_TYPE_UID_T -AC_TYPE_MODE_T -AC_TYPE_OFF_T -AC_TYPE_SIZE_T -AC_TYPE_PID_T -AC_STRUCT_ST_RDEV -AC_CHECK_TYPE(ino_t,unsigned) -AC_CHECK_TYPE(loff_t,off_t) -AC_CHECK_TYPE(offset_t,loff_t) - -AC_FUNC_MEMCMP - -AC_CHECK_FUNCS([pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp utime utimes]) - -AC_CHECK_HEADERS(stdbool.h stdint.h sys/select.h) -AC_CHECK_HEADERS(setjmp.h utime.h) - -LIBREPLACE_PROVIDE_HEADER([stdint.h]) -LIBREPLACE_PROVIDE_HEADER([stdbool.h]) - -AC_CHECK_TYPE(bool, -[AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],, -[ -AC_INCLUDES_DEFAULT -#ifdef HAVE_STDBOOL_H -#include -#endif] -) - -AC_CHECK_TYPE(_Bool, -[AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],, -[ -AC_INCLUDES_DEFAULT -#ifdef HAVE_STDBOOL_H -#include -#endif] -) - -AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[ -AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"], - libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)]) -if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then - AC_DEFINE(HAVE_MMAP,1,[Whether mmap works]) -fi - - -AC_CHECK_HEADERS(sys/syslog.h syslog.h) -AC_CHECK_HEADERS(sys/time.h time.h) -AC_CHECK_HEADERS(stdarg.h vararg.h) -AC_CHECK_HEADERS(sys/mount.h mntent.h) -AC_CHECK_HEADERS(stropts.h) -AC_CHECK_HEADERS(unix.h) - -AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror strerror_r) -AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename) -AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup) -AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf) -AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath) -AC_CHECK_FUNCS(fdatasync,,[ - # if we didn't find it, look in librt (Solaris hides it there...) - AC_CHECK_LIB(rt, fdatasync, - [libreplace_cv_HAVE_FDATASYNC_IN_LIBRT=yes - AC_DEFINE(HAVE_FDATASYNC, 1, Define to 1 if there is support for fdatasync)]) -]) -AC_CHECK_FUNCS(get_current_dir_name) -AC_HAVE_DECL(setresuid, [#include ]) -AC_HAVE_DECL(setresgid, [#include ]) -AC_HAVE_DECL(errno, [#include ]) - -AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[ -AC_TRY_RUN([#include -#include -#include -#include -main() { - struct stat st; - char tpl[20]="/tmp/test.XXXXXX"; - int fd = mkstemp(tpl); - if (fd == -1) exit(1); - unlink(tpl); - if (fstat(fd, &st) != 0) exit(1); - if ((st.st_mode & 0777) != 0600) exit(1); - exit(0); -}], -libreplace_cv_HAVE_SECURE_MKSTEMP=yes, -libreplace_cv_HAVE_SECURE_MKSTEMP=no, -libreplace_cv_HAVE_SECURE_MKSTEMP=cross)]) -if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then - AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure]) -fi - -dnl Provided by snprintf.c: -AC_CHECK_HEADERS(stdio.h strings.h) -AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf]) -AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf) - -AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[ -AC_TRY_RUN([ -#include -#include -#include -#include -void foo(const char *format, ...) { - va_list ap; - int len; - char buf[20]; - long long l = 1234567890; - l *= 100; - - va_start(ap, format); - len = vsnprintf(buf, 0, format, ap); - va_end(ap); - if (len != 5) exit(1); - - va_start(ap, format); - len = vsnprintf(0, 0, format, ap); - va_end(ap); - if (len != 5) exit(2); - - if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3); - - if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4); - if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5); - if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6); - if (snprintf(buf, 20, "%s", 0) < 3) exit(7); - - exit(0); -} -main() { foo("hello"); } -], -libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)]) -if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then - AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf]) -fi - - -dnl VA_COPY -AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[ -AC_TRY_LINK([#include -va_list ap1,ap2;], [va_copy(ap1,ap2);], -libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)]) -if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then - AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available]) -fi - -if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then -AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[ -AC_TRY_LINK([#include -va_list ap1,ap2;], [__va_copy(ap1,ap2);], -libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)]) -if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then - AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available]) -fi -fi - -dnl __FUNCTION__ macro -AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[ -AC_TRY_COMPILE([#include ], [printf("%s\n", __FUNCTION__);], -libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)]) -if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then - AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro]) -else - dnl __func__ macro - AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[ - AC_TRY_COMPILE([#include ], [printf("%s\n", __func__);], - libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)]) - if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then - AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro]) - fi -fi - -AC_CHECK_HEADERS([sys/param.h limits.h]) - -AC_CHECK_TYPE(comparison_fn_t, -[AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])]) - -AC_HAVE_DECL(setenv, [#include ]) -AC_CHECK_FUNCS(setenv unsetenv) -AC_HAVE_DECL(environ, [#include ]) - -AC_CHECK_FUNCS(strnlen) -AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq) - -AC_CHECK_FUNCS(memmem) - -# this test disabled as we don't actually need __VA_ARGS__ yet -AC_TRY_CPP([ -#define eprintf(...) fprintf(stderr, __VA_ARGS__) -eprintf("bla", "bar"); -], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available])) - - -AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [ - AC_TRY_COMPILE([ -#include -#if STDC_HEADERS -#include -#include -#endif -#include ],[sig_atomic_t i = 0], - libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)]) -if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then - AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type]) -fi - - -AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[ -AC_TRY_COMPILE([ -#include -#ifdef HAVE_FCNTL_H -#include -#endif], -[int fd = open("/dev/null", O_DIRECT);], -libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)]) -if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then - AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT]) -fi - - -dnl Check if the C compiler understands volatile (it should, being ANSI). -AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [ - AC_TRY_COMPILE([#include ],[volatile int i = 0], - libreplace_cv_volatile=yes,libreplace_cv_volatile=no)]) -if test x"$libreplace_cv_volatile" = x"yes"; then - AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile]) -fi - -m4_include(system/config.m4) - -m4_include(dlfcn.m4) -m4_include(getpass.m4) -m4_include(strptime.m4) -m4_include(win32.m4) -m4_include(timegm.m4) -m4_include(repdir.m4) -m4_include(crypt.m4) - -AC_CHECK_FUNCS([printf memset memcpy],,[AC_MSG_ERROR([Required function not found])]) - -echo "LIBREPLACE_BROKEN_CHECKS: END" -]) dnl end AC_LIBREPLACE_BROKEN_CHECKS - -AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START, -[ -#LIBREPLACE_ALL_CHECKS: START" -]) -AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END, -[ -#LIBREPLACE_ALL_CHECKS: END" -]) -m4_define(AC_LIBREPLACE_ALL_CHECKS, -[ -AC__LIBREPLACE_ALL_CHECKS_START -AC_LIBREPLACE_LOCATION_CHECKS -AC_LIBREPLACE_CC_CHECKS -AC_LIBREPLACE_BROKEN_CHECKS -AC__LIBREPLACE_ALL_CHECKS_END -CFLAGS="$CFLAGS -I$libreplacedir" -]) - -m4_include(libreplace_cc.m4) -m4_include(libreplace_ld.m4) -m4_include(libreplace_network.m4) -m4_include(libreplace_macros.m4) - -m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[m4_include(autoconf-2.60.m4)]) diff --git a/bundled/replace/libreplace_cc.m4 b/bundled/replace/libreplace_cc.m4 deleted file mode 100644 index 48d9e84a..00000000 --- a/bundled/replace/libreplace_cc.m4 +++ /dev/null @@ -1,179 +0,0 @@ - -AC_DEFUN_ONCE(AC__LIBREPLACE_ONLY_CC_CHECKS_START, -[ -echo "LIBREPLACE_CC_CHECKS: START" -]) - -AC_DEFUN_ONCE(AC__LIBREPLACE_ONLY_CC_CHECKS_END, -[ -echo "LIBREPLACE_CC_CHECKS: END" -]) - -dnl -dnl -dnl AC_LIBREPLACE_CC_CHECKS -dnl -dnl Note: we need to use m4_define instead of AC_DEFUN because -dnl of the ordering of tests -dnl -dnl -m4_define(AC_LIBREPLACE_CC_CHECKS, -[ -AC__LIBREPLACE_ONLY_CC_CHECKS_START - -dnl stop the C89 attempt by autoconf - if autoconf detects -Ae it will enable it -dnl which conflicts with C99 on HPUX -ac_cv_prog_cc_Ae=no - -savedCFLAGS=$CFLAGS -AC_PROG_CC -CFLAGS=$savedCFLAGS - -dnl don't try for C99 if we are using gcc, as otherwise we -dnl lose immediate structure constants -if test x"$GCC" != x"yes" ; then -AC_PROG_CC_C99 -fi - -if test x"$GCC" = x"yes" ; then - AC_MSG_CHECKING([for version of gcc]) - GCC_VERSION=`$CC -dumpversion` - AC_MSG_RESULT(${GCC_VERSION}) -fi -AC_USE_SYSTEM_EXTENSIONS -AC_C_BIGENDIAN -AC_C_INLINE -LIBREPLACE_C99_STRUCT_INIT([],[AC_MSG_WARN([c99 structure initializer are not supported])]) - -AC_PROG_INSTALL - -AC_ISC_POSIX -AC_N_DEFINE(_XOPEN_SOURCE_EXTENDED) - -AC_SYS_LARGEFILE - -dnl Add #include for broken IRIX header files -case "$host_os" in - *irix6*) AC_ADD_INCLUDE() - ;; - *hpux*) - # mmap on HPUX is completely broken... - AC_DEFINE(MMAP_BLACKLIST, 1, [Whether MMAP is broken]) - if test "`uname -r`" = "B.11.00" -o "`uname -r`" = "B.11.11"; then - AC_MSG_WARN([Enabling HPUX 11.00/11.11 header bug workaround]) - CFLAGS="$CFLAGS -Dpread=pread64 -Dpwrite=pwrite64" - fi - if test "`uname -r`" = "B.11.23"; then - AC_MSG_WARN([Enabling HPUX 11.23 machine/sys/getppdp.h bug workaround]) - CFLAGS="$CFLAGS -D_MACHINE_SYS_GETPPDP_INCLUDED" - fi - ;; - *aix*) - AC_DEFINE(BROKEN_STRNDUP, 1, [Whether strndup is broken]) - AC_DEFINE(BROKEN_STRNLEN, 1, [Whether strnlen is broken]) - if test "${GCC}" != "yes"; then - ## for funky AIX compiler using strncpy() - CFLAGS="$CFLAGS -D_LINUX_SOURCE_COMPAT -qmaxmem=32000" - fi - ;; - *osf*) - # this brings in socklen_t - AC_N_DEFINE(_XOPEN_SOURCE,600) - AC_N_DEFINE(_OSF_SOURCE) - ;; - # - # VOS may need to have POSIX support and System V compatibility enabled. - # - *vos*) - case "$CFLAGS" in - *-D_POSIX_C_SOURCE*);; - *) - CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112L" - AC_DEFINE(_POSIX_C_SOURCE, 200112L, [Whether to enable POSIX support]) - ;; - esac - case "$CFLAGS" in - *-D_SYSV*|*-D_SVID_SOURCE*);; - *) - CFLAGS="$CFLAGS -D_SYSV" - AC_DEFINE(_SYSV, 1, [Whether to enable System V compatibility]) - ;; - esac - ;; -esac - - - -AC_CHECK_HEADERS([standards.h]) - -# Solaris needs HAVE_LONG_LONG defined -AC_CHECK_TYPES(long long) - -AC_CHECK_SIZEOF(int) -AC_CHECK_SIZEOF(char) -AC_CHECK_SIZEOF(short) -AC_CHECK_SIZEOF(long) -AC_CHECK_SIZEOF(long long) - -AC_CHECK_TYPE(int8_t, char) -AC_CHECK_TYPE(uint8_t, unsigned char) -AC_CHECK_TYPE(int16_t, short) -AC_CHECK_TYPE(uint16_t, unsigned short) - -if test $ac_cv_sizeof_int -eq 4 ; then -AC_CHECK_TYPE(int32_t, int) -AC_CHECK_TYPE(uint32_t, unsigned int) -elif test $ac_cv_size_long -eq 4 ; then -AC_CHECK_TYPE(int32_t, long) -AC_CHECK_TYPE(uint32_t, unsigned long) -else -AC_MSG_ERROR([LIBREPLACE no 32-bit type found]) -fi - -AC_CHECK_TYPE(int64_t, long long) -AC_CHECK_TYPE(uint64_t, unsigned long long) - -AC_CHECK_TYPE(size_t, unsigned int) -AC_CHECK_TYPE(ssize_t, int) - -AC_CHECK_SIZEOF(off_t) -AC_CHECK_SIZEOF(size_t) -AC_CHECK_SIZEOF(ssize_t) - -AC_CHECK_TYPES([intptr_t, uintptr_t, ptrdiff_t]) - -if test x"$ac_cv_type_long_long" != x"yes";then - AC_MSG_ERROR([LIBREPLACE needs type 'long long']) -fi -if test $ac_cv_sizeof_long_long -lt 8;then - AC_MSG_ERROR([LIBREPLACE needs sizeof(long long) >= 8]) -fi - -############################################ -# check if the compiler can do immediate structures -AC_SUBST(libreplace_cv_immediate_structures) -AC_CACHE_CHECK([for immediate structures],libreplace_cv_immediate_structures,[ - AC_TRY_COMPILE([ - #include - ],[ - typedef struct {unsigned x;} FOOBAR; - #define X_FOOBAR(x) ((FOOBAR) { x }) - #define FOO_ONE X_FOOBAR(1) - FOOBAR f = FOO_ONE; - static const struct { - FOOBAR y; - } f2[] = { - {FOO_ONE} - }; - static const FOOBAR f3[] = {FOO_ONE}; - ], - libreplace_cv_immediate_structures=yes, - libreplace_cv_immediate_structures=no, - libreplace_cv_immediate_structures=cross) -]) -if test x"$libreplace_cv_immediate_structures" = x"yes"; then - AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures]) -fi - -AC__LIBREPLACE_ONLY_CC_CHECKS_END -]) dnl end AC_LIBREPLACE_CC_CHECKS diff --git a/bundled/replace/libreplace_ld.m4 b/bundled/replace/libreplace_ld.m4 deleted file mode 100644 index bf0df618..00000000 --- a/bundled/replace/libreplace_ld.m4 +++ /dev/null @@ -1,337 +0,0 @@ -# -# This offers a nice overview how to build shared libraries on all platforms -# http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html -# - -AC_DEFUN([AC_LIBREPLACE_STLD], -[ - AC_PATH_PROG(PROG_AR, ar) - - STLD=${PROG_AR} - - AC_SUBST(STLD) -]) - -AC_DEFUN([AC_LIBREPLACE_STLD_FLAGS], -[ - STLD_FLAGS="-rcs" - AC_SUBST(STLD_FLAGS) -]) - -AC_DEFUN([AC_LD_EXPORT_DYNAMIC], -[ -saved_LDFLAGS="$LDFLAGS" -if AC_TRY_COMMAND([${CC-cc} $CFLAGS -Wl,--version 2>&1 | grep "GNU ld" >/dev/null]); then - LD_EXPORT_DYNAMIC="-Wl,-export-dynamic" -else - case "$host_os" in - hpux* ) - LD_EXPORT_DYNAMIC="-Wl,-E" - ;; - *) - LD_EXPORT_DYNAMIC="" - ;; - esac -fi -AC_SUBST(LD_EXPORT_DYNAMIC) -LDFLAGS="$saved_LDFLAGS" -]) - -AC_DEFUN([AC_LD_PICFLAG], -[ -case "$host_os" in - *linux*|*gnu*) - PICFLAG="-fPIC" - ;; - *solaris*) - if test "${GCC}" = "yes"; then - PICFLAG="-fPIC" - else - PICFLAG="-KPIC" - fi - ;; - *sunos*) - PICFLAG="-KPIC" # Is this correct for SunOS - ;; - *netbsd* | *freebsd* | *dragonfly* ) - PICFLAG="-fPIC -DPIC" - ;; - *openbsd*) - PICFLAG="-fPIC" - ;; - *irix*) - if test "${GCC}" = "yes"; then - PICFLAG="-fPIC" - else - PICFLAG="-KPIC" - fi - ;; - *aix*) - # as AIX code is always position independent... - PICFLAG="-O2" - ;; - *hpux*) - if test "${GCC}" = "yes"; then - PICFLAG="-fPIC" - elif test "$host_cpu" = "ia64"; then - PICFLAG="+z" - elif test $ac_cv_prog_cc_Ae = yes; then - PICFLAG="+z +ESnolit" - fi - ;; - *osf*) - PICFLAG="-fPIC" - ;; - *unixware*) - PICFLAG="-KPIC" - ;; - *darwin*) - PICFLAG="-fno-common" - ;; -esac -AC_SUBST(PICFLAG) -]) - -AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_LINKER], -[ - LD_SHLIB_LINKER="${CC}" - - case "$host_os" in - *irix*) - LD_SHLIB_LINKER="${PROG_LD}" - ;; - esac - - AC_SUBST(LD_SHLIB_LINKER) -]) - -AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_FLAGS], -[ - LD_SHLIB_FLAGS="-shared" - - case "$host_os" in - *linux*|*gnu*) - LD_SHLIB_FLAGS="-shared -Wl,-Bsymbolic" - ;; - *solaris*) - LD_SHLIB_FLAGS="-G" - if test "${GCC}" = "no"; then - ## ${CFLAGS} added for building 64-bit shared - ## libs using Sun's Compiler - LD_SHLIB_FLAGS="-G \${CFLAGS}" - fi - ;; - *sunos*) - LD_SHLIB_FLAGS="-G" - ;; - *irix*) - LD_SHLIB_FLAGS="-shared" - ;; - *aix*) - LD_SHLIB_FLAGS="-Wl,-G,-bexpall,-bbigtoc" - ;; - *hpux*) - if test "${GCC}" = "yes"; then - LD_SHLIB_FLAGS="-shared" - else - LD_SHLIB_FLAGS="-b" - fi - ;; - *osf*) - LD_SHLIB_FLAGS="-shared" - ;; - *darwin*) - LD_SHLIB_FLAGS="-dynamiclib -Wl,-search_paths_first" - ;; - esac - - AC_SUBST(LD_SHLIB_FLAGS) -]) - -AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_DISALLOW_UNDEF_FLAG], -[ - LD_SHLIB_DISALLOW_UNDEF_FLAG="" - - # - # TODO: enforce error not only warnings - # - # NOTE: -Wl,--no-allow-shlib-undefined isn't what we want... - # as it bails out on broken system libraries - # - case "$host_os" in - *osf*) - LD_SHLIB_DISALLOW_UNDEF_FLAG="-warning_unresolved" - ;; - *darwin*) - LD_SHLIB_DISALLOW_UNDEF_FLAG="-undefined error" - ;; - esac - - AC_SUBST(LD_SHLIB_DISALLOW_UNDEF_FLAG) -]) - -AC_DEFUN([AC_LIBREPLACE_SHLD], -[ - AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_LINKER]) - SHLD="$LD_SHLIB_LINKER" - AC_SUBST(SHLD) -]) - -AC_DEFUN([AC_LIBREPLACE_SHLD_FLAGS], -[ - AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_FLAGS]) - AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_DISALLOW_UNDEF_FLAG]) - SHLD_FLAGS="$LD_SHLIB_FLAGS $LD_SHLIB_DISALLOW_UNDEF_FLAG" - AC_SUBST(SHLD_FLAGS) -]) - -AC_DEFUN([AC_LD_SHLIBEXT], -[ - SHLIBEXT="so" - case "$host_os" in - *hpux*) - if test "$host_cpu" = "ia64"; then - SHLIBEXT="so" - else - SHLIBEXT="sl" - fi - ;; - *darwin*) - SHLIBEXT="dylib" - ;; - esac - AC_SUBST(SHLIBEXT) -]) - -AC_DEFUN([AC_LD_SONAMEFLAG], -[ - AC_SUBST(SONAMEFLAG) - SONAMEFLAG="" - case "$host_os" in - *linux*|*gnu*|*qnx*) - SONAMEFLAG="-Wl,-soname=" - ;; - *solaris*) - SONAMEFLAG="-h " - if test "${GCC}" = "yes"; then - SONAMEFLAG="-Wl,-soname=" - fi - ;; - *sunos*) - SONAMEFLAG="-Wl,-h," - ;; - *netbsd* | *freebsd* | *dragonfly* ) - SONAMEFLAG="-Wl,-soname," - ;; - *openbsd*) - SONAMEFLAG="-Wl,-soname," - ;; - *irix*) - SONAMEFLAG="-Wl,-soname," - ;; - *hpux*) - SONAMEFLAG="-Wl,+h," - ;; - *osf*) - SONAMEFLAG="-Wl,-soname," - ;; - *unixware*) - SONAMEFLAG="-Wl,-soname," - ;; - *darwin*) - SONAMEFLAG="#" - ;; - *aix*) - # Not supported - SONAMEFLAG="#" - ;; - esac -]) - -AC_DEFUN([AC_LD_VERSIONSCRIPT], -[ - AC_SUBST(VERSIONSCRIPT) - VERSIONSCRIPT="" - case "$host_os" in - *linux*|*gnu*) - VERSIONSCRIPT="-Wl,--version-script" - ;; - *solaris*) - if test "${GCC}" = "yes"; then - VERSIONSCRIPT="-Wl,--version-script" - fi - ;; - esac -]) - -AC_DEFUN([AC_LIBREPLACE_MDLD], -[ - AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_LINKER]) - MDLD="$LD_SHLIB_LINKER" - AC_SUBST(MDLD) -]) - -AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_ALLOW_UNDEF_FLAG], -[ - LD_ALLOW_SHLIB_UNDEF_FLAG="" - - case "$host_os" in - *linux*|*gnu*) - LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,--allow-shlib-undefined" - ;; - *osf*) - LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,-expect_unresolved,\"*\"" - ;; - *darwin*) - LD_SHLIB_ALLOW_UNDEF_FLAG="-undefined dynamic_lookup" - ;; - *aix*) - LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,-bnoentry" - ;; - esac - - AC_SUBST(LD_SHLIB_ALLOW_UNDEF_FLAG) -]) - -AC_DEFUN([AC_LIBREPLACE_MDLD_FLAGS], -[ - AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_FLAGS]) - AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_ALLOW_UNDEF_FLAG]) - MDLD_FLAGS="$LD_SHLIB_FLAGS $LD_SHLIB_ALLOW_UNDEF_FLAG" - AC_SUBST(MDLD_FLAGS) -]) - -AC_DEFUN([AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR], -[ - case "$host_os" in - *linux*|*gnu*) - LIB_PATH_VAR=LD_LIBRARY_PATH - ;; - *bsd*) - LIB_PATH_VAR=LD_LIBRARY_PATH - ;; - *solaris*) - LIB_PATH_VAR=LD_LIBRARY_PATH - ;; - *hpux*) - LIB_PATH_VAR=SHLIB_PATH - ;; - *osf*) - LIB_PATH_VAR=LD_LIBRARY_PATH - ;; - *aix*) - LIB_PATH_VAR=LIBPATH - ;; - *irix*) - LIB_PATH_VAR=LD_LIBRARY_PATH - ;; - *darwin*) - LIB_PATH_VAR=DYLD_LIBRARY_PATH - ;; - *) - LIB_PATH_VAR=LD_LIBRARY_PATH - ;; - esac - - AC_SUBST(LIB_PATH_VAR) -]) diff --git a/bundled/replace/libreplace_macros.m4 b/bundled/replace/libreplace_macros.m4 deleted file mode 100644 index 1856eacf..00000000 --- a/bundled/replace/libreplace_macros.m4 +++ /dev/null @@ -1,332 +0,0 @@ -# -# This is a collection of useful autoconf macros -# - -############################################ -# Check if the compiler handles c99 struct initialization, and if not try -AC99 and -c99 flags -# Usage: LIBREPLACE_C99_STRUCT_INIT(success-action,failure-action) -# changes CFLAGS to add -AC99 or -c99 if needed -AC_DEFUN([LIBREPLACE_C99_STRUCT_INIT], -[ -saved_CFLAGS="$CFLAGS"; -c99_init=no -if test x"$c99_init" = x"no"; then - AC_MSG_CHECKING(for C99 designated initializers) - CFLAGS="$saved_CFLAGS"; - AC_TRY_COMPILE([#include ], - [ struct foo {int x;char y;}; - struct foo bar = { .y = 'X', .x = 1 }; - ], - [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)]) -fi -if test x"$c99_init" = x"no"; then - AC_MSG_CHECKING(for C99 designated initializers with -AC99) - CFLAGS="$saved_CFLAGS -AC99"; - AC_TRY_COMPILE([#include ], - [ struct foo {int x;char y;}; - struct foo bar = { .y = 'X', .x = 1 }; - ], - [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)]) -fi -if test x"$c99_init" = x"no"; then - AC_MSG_CHECKING(for C99 designated initializers with -qlanglvl=extc99) - CFLAGS="$saved_CFLAGS -qlanglvl=extc99"; - AC_TRY_COMPILE([#include ], - [ struct foo {int x;char y;}; - struct foo bar = { .y = 'X', .x = 1 }; - ], - [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)]) -fi -if test x"$c99_init" = x"no"; then - AC_MSG_CHECKING(for C99 designated initializers with -qlanglvl=stdc99) - CFLAGS="$saved_CFLAGS -qlanglvl=stdc99"; - AC_TRY_COMPILE([#include ], - [ struct foo {int x;char y;}; - struct foo bar = { .y = 'X', .x = 1 }; - ], - [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)]) -fi -if test x"$c99_init" = x"no"; then - AC_MSG_CHECKING(for C99 designated initializers with -c99) - CFLAGS="$saved_CFLAGS -c99" - AC_TRY_COMPILE([#include ], - [ struct foo {int x;char y;}; - struct foo bar = { .y = 'X', .x = 1 }; - ], - [AC_MSG_RESULT(yes); c99_init=yes],[AC_MSG_RESULT(no)]) -fi - -if test "`uname`" = "HP-UX"; then - if test "$ac_cv_c_compiler_gnu" = no; then - # special override for broken HP-UX compiler - I can't find a way to test - # this properly (its a compiler bug) - CFLAGS="$CFLAGS -AC99"; - c99_init=yes; - fi -fi - -if test x"$c99_init" = x"yes"; then - saved_CFLAGS="" - $1 -else - CFLAGS="$saved_CFLAGS" - saved_CFLAGS="" - $2 -fi -]) - -dnl AC_PROG_CC_FLAG(flag) -AC_DEFUN(AC_PROG_CC_FLAG, -[AC_CACHE_CHECK(whether ${CC-cc} accepts -$1, ac_cv_prog_cc_$1, -[echo 'void f(){}' > conftest.c -if test -z "`${CC-cc} -$1 -c conftest.c 2>&1`"; then - ac_cv_prog_cc_$1=yes -else - ac_cv_prog_cc_$1=no -fi -rm -f conftest* -])]) - -dnl see if a declaration exists for a function or variable -dnl defines HAVE_function_DECL if it exists -dnl AC_HAVE_DECL(var, includes) -AC_DEFUN(AC_HAVE_DECL, -[ - AC_CACHE_CHECK([for $1 declaration],ac_cv_have_$1_decl,[ - AC_TRY_COMPILE([$2],[int i = (int)$1], - ac_cv_have_$1_decl=yes,ac_cv_have_$1_decl=no)]) - if test x"$ac_cv_have_$1_decl" = x"yes"; then - AC_DEFINE([HAVE_]translit([$1], [a-z], [A-Z])[_DECL],1,[Whether $1() is available]) - fi -]) - - -# AC_CHECK_LIB_EXT(LIBRARY, [EXT_LIBS], [FUNCTION], -# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], -# [ADD-ACTION-IF-FOUND],[OTHER-LIBRARIES]) -# ------------------------------------------------------ -# -# Use a cache variable name containing both the library and function name, -# because the test really is for library $1 defining function $3, not -# just for library $1. Separate tests with the same $1 and different $3s -# may have different results. -# -# Note that using directly AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$3]) -# is asking for trouble, since AC_CHECK_LIB($lib, fun) would give -# ac_cv_lib_$lib_fun, which is definitely not what was meant. Hence -# the AS_LITERAL_IF indirection. -# -# FIXME: This macro is extremely suspicious. It DEFINEs unconditionally, -# whatever the FUNCTION, in addition to not being a *S macro. Note -# that the cache does depend upon the function we are looking for. -# -# It is on purpose we used `ac_check_lib_ext_save_LIBS' and not just -# `ac_save_LIBS': there are many macros which don't want to see `LIBS' -# changed but still want to use AC_CHECK_LIB_EXT, so they save `LIBS'. -# And ``ac_save_LIBS' is too tempting a name, so let's leave them some -# freedom. -AC_DEFUN([AC_CHECK_LIB_EXT], -[ -AH_CHECK_LIB_EXT([$1]) -ac_check_lib_ext_save_LIBS=$LIBS -LIBS="-l$1 $$2 $7 $LIBS" -AS_LITERAL_IF([$1], - [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1])], - [AS_VAR_PUSHDEF([ac_Lib_ext], [ac_cv_lib_ext_$1''])])dnl - -m4_ifval([$3], - [ - AH_CHECK_FUNC_EXT([$3]) - AS_LITERAL_IF([$1], - [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1_$3])], - [AS_VAR_PUSHDEF([ac_Lib_func], [ac_cv_lib_ext_$1''_$3])])dnl - AC_CACHE_CHECK([for $3 in -l$1], ac_Lib_func, - [AC_TRY_LINK_FUNC($3, - [AS_VAR_SET(ac_Lib_func, yes); - AS_VAR_SET(ac_Lib_ext, yes)], - [AS_VAR_SET(ac_Lib_func, no); - AS_VAR_SET(ac_Lib_ext, no)]) - ]) - AS_IF([test AS_VAR_GET(ac_Lib_func) = yes], - [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_$3))])dnl - AS_VAR_POPDEF([ac_Lib_func])dnl - ],[ - AC_CACHE_CHECK([for -l$1], ac_Lib_ext, - [AC_TRY_LINK_FUNC([main], - [AS_VAR_SET(ac_Lib_ext, yes)], - [AS_VAR_SET(ac_Lib_ext, no)]) - ]) - ]) -LIBS=$ac_check_lib_ext_save_LIBS - -AS_IF([test AS_VAR_GET(ac_Lib_ext) = yes], - [m4_default([$4], - [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1)) - case "$$2" in - *-l$1*) - ;; - *) - $2="-l$1 $$2" - ;; - esac]) - [$6] - ], - [$5])dnl -AS_VAR_POPDEF([ac_Lib_ext])dnl -])# AC_CHECK_LIB_EXT - -# AH_CHECK_LIB_EXT(LIBNAME) -# --------------------- -m4_define([AH_CHECK_LIB_EXT], -[AH_TEMPLATE(AS_TR_CPP(HAVE_LIB$1), - [Define to 1 if you have the `]$1[' library (-l]$1[).])]) - -dnl AC_SEARCH_LIBS_EXT(FUNCTION, SEARCH-LIBS, EXT_LIBS, -dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], -dnl [OTHER-LIBRARIES]) -dnl -------------------------------------------------------- -dnl Search for a library defining FUNC, if it's not already available. -AC_DEFUN([AC_SEARCH_LIBS_EXT], -[AC_CACHE_CHECK([for library containing $1], [ac_cv_search_ext_$1], -[ -ac_func_search_ext_save_LIBS=$LIBS -ac_cv_search_ext_$1=no -AC_LINK_IFELSE([AC_LANG_CALL([], [$1])], - [ac_cv_search_ext_$1="none required"]) -if test "$ac_cv_search_ext_$1" = no; then - for ac_lib in $2; do - LIBS="-l$ac_lib $$3 $6 $ac_func_search_save_ext_LIBS" - AC_LINK_IFELSE([AC_LANG_CALL([], [$1])], - [ac_cv_search_ext_$1="-l$ac_lib" -break]) - done -fi -LIBS=$ac_func_search_ext_save_LIBS]) -AS_IF([test "$ac_cv_search_ext_$1" != no], - [test "$ac_cv_search_ext_$1" = "none required" || $3="$ac_cv_search_ext_$1 $$3" - $4], - [$5])dnl -]) - -dnl check for a function in a $LIBS and $OTHER_LIBS libraries variable. -dnl AC_CHECK_FUNC_EXT(func,OTHER_LIBS,IF-TRUE,IF-FALSE) -AC_DEFUN([AC_CHECK_FUNC_EXT], -[ - AH_CHECK_FUNC_EXT($1) - ac_check_func_ext_save_LIBS=$LIBS - LIBS="$2 $LIBS" - AS_VAR_PUSHDEF([ac_var], [ac_cv_func_ext_$1])dnl - AC_CACHE_CHECK([for $1], ac_var, - [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$1])], - [AS_VAR_SET(ac_var, yes)], - [AS_VAR_SET(ac_var, no)])]) - LIBS=$ac_check_func_ext_save_LIBS - AS_IF([test AS_VAR_GET(ac_var) = yes], - [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1])) $3], - [$4])dnl -AS_VAR_POPDEF([ac_var])dnl -])# AC_CHECK_FUNC - -# AH_CHECK_FUNC_EXT(FUNCNAME) -# --------------------- -m4_define([AH_CHECK_FUNC_EXT], -[AH_TEMPLATE(AS_TR_CPP(HAVE_$1), - [Define to 1 if you have the `]$1[' function.])]) - -dnl Define an AC_DEFINE with ifndef guard. -dnl AC_N_DEFINE(VARIABLE [, VALUE]) -AC_DEFUN([AC_N_DEFINE], -[ -AH_VERBATIM([$1], [ -#ifndef $1 -# undef $1 -#endif -]) - - cat >>confdefs.h <<\EOF -#ifndef $1 -[#define] $1 m4_if($#, 1, 1, [$2]) -#endif -EOF -]) - -dnl Add an #include -dnl AC_ADD_INCLUDE(VARIABLE) -define(AC_ADD_INCLUDE, -[cat >> confdefs.h <<\EOF -[#include] $1 -EOF -]) - -dnl remove an #include -dnl AC_REMOVE_INCLUDE(VARIABLE) -define(AC_REMOVE_INCLUDE, -[ -grep -v '[#include] $1' confdefs.h >confdefs.h.tmp -cat confdefs.h.tmp > confdefs.h -rm confdefs.h.tmp -]) - -dnl remove an #define -dnl AC_REMOVE_DEFINE(VARIABLE) -define(AC_REMOVE_DEFINE, -[ -grep -v '[#define] $1 ' confdefs.h |grep -v '[#define] $1[$]'>confdefs.h.tmp -cat confdefs.h.tmp > confdefs.h -rm confdefs.h.tmp -]) - -dnl AS_HELP_STRING is not available in autoconf 2.57, and AC_HELP_STRING is deprecated -dnl in autoconf 2.59, so define AS_HELP_STRING to be AC_HELP_STRING unless it is already -dnl defined. -m4_ifdef([AS_HELP_STRING], , [m4_define([AS_HELP_STRING], m4_defn([AC_HELP_STRING]))]) - -dnl check if the prototype in the header matches the given one -dnl AC_VERIFY_C_PROTOTYPE(prototype,functionbody,[IF-TRUE].[IF-FALSE],[extraheaders]) -AC_DEFUN(AC_VERIFY_C_PROTOTYPE, -[AC_CACHE_CHECK([for prototype $1], AS_TR_SH([ac_cv_c_prototype_$1]), - AC_COMPILE_IFELSE([AC_LANG_SOURCE([ - AC_INCLUDES_DEFAULT - $5 - $1 - { - $2 - } - ])],[ - AS_TR_SH([ac_cv_c_prototype_$1])=yes - ],[ - AS_TR_SH([ac_cv_c_prototype_$1])=no - ]) -) -AS_IF([test $AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4]) -]) - -AC_DEFUN(LIBREPLACE_PROVIDE_HEADER, -[AC_CHECK_HEADER([$1], - [ AC_CONFIG_COMMANDS(rm-$1, [rm -f $libreplacedir/$1], [libreplacedir=$libreplacedir]) ], - [ AC_CONFIG_COMMANDS(mk-$1, [echo "#include \"replace.h\"" > $libreplacedir/$1], [libreplacedir=$libreplacedir]) ] - ) -]) - -dnl AC_HAVE_TYPE(TYPE,INCLUDES) -AC_DEFUN([AC_HAVE_TYPE], [ -AC_REQUIRE([AC_HEADER_STDC]) -cv=`echo "$1" | sed 'y%./+- %__p__%'` -AC_MSG_CHECKING(for $1) -AC_CACHE_VAL([ac_cv_type_$cv], -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -AC_INCLUDES_DEFAULT -$2]], -[[$1 foo;]])], -[eval "ac_cv_type_$cv=yes"], -[eval "ac_cv_type_$cv=no"]))dnl -ac_foo=`eval echo \\$ac_cv_type_$cv` -AC_MSG_RESULT($ac_foo) -if test "$ac_foo" = yes; then - ac_tr_hdr=HAVE_`echo $1 | sed 'y%abcdefghijklmnopqrstuvwxyz./- %ABCDEFGHIJKLMNOPQRSTUVWXYZ____%'` -if false; then - AC_CHECK_TYPES($1) -fi - AC_DEFINE_UNQUOTED($ac_tr_hdr, 1, [Define if you have type `$1']) -fi -]) diff --git a/bundled/replace/libreplace_network.m4 b/bundled/replace/libreplace_network.m4 deleted file mode 100644 index f9bca40c..00000000 --- a/bundled/replace/libreplace_network.m4 +++ /dev/null @@ -1,466 +0,0 @@ -AC_DEFUN_ONCE(AC_LIBREPLACE_NETWORK_CHECKS, -[ -echo "LIBREPLACE_NETWORK_CHECKS: START" - -AC_DEFINE(LIBREPLACE_NETWORK_CHECKS, 1, [LIBREPLACE_NETWORK_CHECKS were used]) -LIBREPLACE_NETWORK_OBJS="" -LIBREPLACE_NETWORK_LIBS="" - -AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h) -AC_CHECK_HEADERS(netinet/in_systm.h) -AC_CHECK_HEADERS([netinet/ip.h], [], [],[ - #include - #ifdef HAVE_NETINET_IN_H - #include - #endif - #ifdef HAVE_NETINET_IN_SYSTM_H - #include - #endif -]) -AC_CHECK_HEADERS(netinet/tcp.h netinet/in_ip.h) -AC_CHECK_HEADERS(sys/sockio.h sys/un.h) -AC_CHECK_HEADERS(sys/uio.h) - -dnl we need to check that net/if.h really can be used, to cope with hpux -dnl where including it always fails -AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[ - AC_COMPILE_IFELSE([AC_LANG_SOURCE([ - AC_INCLUDES_DEFAULT - #if HAVE_SYS_SOCKET_H - # include - #endif - #include - int main(void) {return 0;}])], - [libreplace_cv_USABLE_NET_IF_H=yes], - [libreplace_cv_USABLE_NET_IF_H=no] - ) -]) -if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then - AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h) -fi - -AC_HAVE_TYPE([socklen_t],[#include ]) -AC_HAVE_TYPE([sa_family_t],[#include ]) -AC_HAVE_TYPE([struct addrinfo], [#include ]) -AC_HAVE_TYPE([struct sockaddr], [#include ]) -AC_HAVE_TYPE([struct sockaddr_storage], [ -#include -#include -#include -]) -AC_HAVE_TYPE([struct sockaddr_in6], [ -#include -#include -#include -]) - -if test x"$ac_cv_type_struct_sockaddr_storage" = x"yes"; then -AC_CHECK_MEMBER(struct sockaddr_storage.ss_family, - AC_DEFINE(HAVE_SS_FAMILY, 1, [Defined if struct sockaddr_storage has ss_family field]),, - [ -#include -#include -#include - ]) - -if test x"$ac_cv_member_struct_sockaddr_storage_ss_family" != x"yes"; then -AC_CHECK_MEMBER(struct sockaddr_storage.__ss_family, - AC_DEFINE(HAVE___SS_FAMILY, 1, [Defined if struct sockaddr_storage has __ss_family field]),, - [ -#include -#include -#include - ]) -fi -fi - -AC_CACHE_CHECK([for sin_len in sock],libreplace_cv_HAVE_SOCK_SIN_LEN,[ - AC_TRY_COMPILE( - [ -#include -#include -#include - ],[ -struct sockaddr_in sock; sock.sin_len = sizeof(sock); - ],[ - libreplace_cv_HAVE_SOCK_SIN_LEN=yes - ],[ - libreplace_cv_HAVE_SOCK_SIN_LEN=no - ]) -]) -if test x"$libreplace_cv_HAVE_SOCK_SIN_LEN" = x"yes"; then - AC_DEFINE(HAVE_SOCK_SIN_LEN,1,[Whether the sockaddr_in struct has a sin_len property]) -fi - -############################################ -# check for unix domain sockets -AC_CACHE_CHECK([for unix domain sockets],libreplace_cv_HAVE_UNIXSOCKET,[ - AC_TRY_COMPILE([ -#include -#include -#include -#include -#include - ],[ -struct sockaddr_un sunaddr; -sunaddr.sun_family = AF_UNIX; - ],[ - libreplace_cv_HAVE_UNIXSOCKET=yes - ],[ - libreplace_cv_HAVE_UNIXSOCKET=no - ]) -]) -if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then - AC_DEFINE(HAVE_UNIXSOCKET,1,[If we need to build with unixscoket support]) -fi - -dnl The following test is roughly taken from the cvs sources. -dnl -dnl If we can't find connect, try looking in -lsocket, -lnsl, and -linet. -dnl The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has -dnl libsocket.so which has a bad implementation of gethostbyname (it -dnl only looks in /etc/hosts), so we only look for -lsocket if we need -dnl it. -AC_CHECK_FUNCS(connect) -if test x"$ac_cv_func_connect" = x"no"; then - AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, connect) - AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, connect) - AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, connect) - AC_CHECK_LIB_EXT(inet, LIBREPLACE_NETWORK_LIBS, connect) - dnl We can't just call AC_CHECK_FUNCS(connect) here, - dnl because the value has been cached. - if test x"$ac_cv_lib_ext_nsl_s_connect" = x"yes" || - test x"$ac_cv_lib_ext_nsl_connect" = x"yes" || - test x"$ac_cv_lib_ext_socket_connect" = x"yes" || - test x"$ac_cv_lib_ext_inet_connect" = x"yes" - then - AC_DEFINE(HAVE_CONNECT,1,[Whether the system has connect()]) - fi -fi - -AC_CHECK_FUNCS(gethostbyname) -if test x"$ac_cv_func_gethostbyname" = x"no"; then - AC_CHECK_LIB_EXT(nsl_s, LIBREPLACE_NETWORK_LIBS, gethostbyname) - AC_CHECK_LIB_EXT(nsl, LIBREPLACE_NETWORK_LIBS, gethostbyname) - AC_CHECK_LIB_EXT(socket, LIBREPLACE_NETWORK_LIBS, gethostbyname) - dnl We can't just call AC_CHECK_FUNCS(gethostbyname) here, - dnl because the value has been cached. - if test x"$ac_cv_lib_ext_nsl_s_gethostbyname" = x"yes" || - test x"$ac_cv_lib_ext_nsl_gethostbyname" = x"yes" || - test x"$ac_cv_lib_ext_socket_gethostbyname" = x"yes" - then - AC_DEFINE(HAVE_GETHOSTBYNAME,1, - [Whether the system has gethostbyname()]) - fi -fi - -dnl HP-UX has if_nametoindex in -lipv6 -AC_CHECK_FUNCS(if_nametoindex) -if test x"$ac_cv_func_if_nametoindex" = x"no"; then - AC_CHECK_LIB_EXT(ipv6, LIBREPLACE_NETWORK_LIBS, if_nametoindex) - dnl We can't just call AC_CHECK_FUNCS(if_nametoindex) here, - dnl because the value has been cached. - if test x"$ac_cv_lib_ext_ipv6_if_nametoindex" = x"yes" - then - AC_DEFINE(HAVE_IF_NAMETOINDEX, 1, - [Whether the system has if_nametoindex()]) - fi -fi - -# The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}" -old_LIBS=$LIBS -LIBS="${LIBREPLACE_NETWORK_LIBS}" -libreplace_SAVE_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="$CPPFLAGS -I$libreplacedir" - -AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/socketpair.o"]) - -AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[ -AC_TRY_RUN([ -#include -#include -#include -#include -#ifdef HAVE_ARPA_INET_H -#include -#endif -main() { struct in_addr ip; ip.s_addr = 0x12345678; -if (strcmp(inet_ntoa(ip),"18.52.86.120") && - strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } -exit(1);}], - libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)]) - -AC_CHECK_FUNCS(inet_ntoa,[],[libreplace_cv_REPLACE_INET_NTOA=yes]) -if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then - AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced]) - LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntoa.o" -fi - -AC_CHECK_FUNCS(inet_aton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_aton.o"]) - -AC_CHECK_FUNCS(inet_ntop,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_ntop.o"]) - -AC_CHECK_FUNCS(inet_pton,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/inet_pton.o"]) - -dnl test for getaddrinfo/getnameinfo -AC_CACHE_CHECK([for getaddrinfo],libreplace_cv_HAVE_GETADDRINFO,[ -AC_TRY_LINK([ -#include -#if STDC_HEADERS -#include -#include -#endif -#include -#include ], -[ -struct sockaddr sa; -struct addrinfo *ai = NULL; -int ret = getaddrinfo(NULL, NULL, NULL, &ai); -if (ret != 0) { - const char *es = gai_strerror(ret); -} -freeaddrinfo(ai); -ret = getnameinfo(&sa, sizeof(sa), - NULL, 0, - NULL, 0, 0); - -], -libreplace_cv_HAVE_GETADDRINFO=yes,libreplace_cv_HAVE_GETADDRINFO=no)]) - -if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then - # getaddrinfo is broken on some AIX systems - # see bug 5910, use our replacements if we detect - # a broken system. - AC_TRY_RUN([ - #include - #include - #include - #include - int main(int argc, const char *argv[]) - { - struct addrinfo hints = {0,}; - struct addrinfo *ppres; - const char hostname[] = "0.0.0.0"; - hints.ai_socktype = SOCK_STREAM; - hints.ai_family = AF_INET; - hints.ai_flags = - AI_NUMERICHOST|AI_PASSIVE|AI_ADDRCONFIG; - return getaddrinfo(hostname, NULL, &hints, &ppres) != 0 ? 1 : 0; - }], - libreplace_cv_HAVE_GETADDRINFO=yes, - libreplace_cv_HAVE_GETADDRINFO=no) -fi - -if test x"$libreplace_cv_HAVE_GETADDRINFO" = x"yes"; then - AC_DEFINE(HAVE_GETADDRINFO,1,[Whether the system has getaddrinfo]) - AC_DEFINE(HAVE_GETNAMEINFO,1,[Whether the system has getnameinfo]) - AC_DEFINE(HAVE_FREEADDRINFO,1,[Whether the system has freeaddrinfo]) - AC_DEFINE(HAVE_GAI_STRERROR,1,[Whether the system has gai_strerror]) -else - LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getaddrinfo.o" -fi - -AC_CHECK_HEADERS([ifaddrs.h]) - -dnl Used when getifaddrs is not available -AC_CHECK_MEMBERS([struct sockaddr.sa_len], - [AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1, [Whether struct sockaddr has a sa_len member])], - [], - [#include ]) - -dnl test for getifaddrs and freeifaddrs -AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[ -AC_TRY_LINK([ -#include -#if STDC_HEADERS -#include -#include -#endif -#include -#include -#include -#include -#include ], -[ -struct ifaddrs *ifp = NULL; -int ret = getifaddrs (&ifp); -freeifaddrs(ifp); -], -libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)]) -if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then - AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs]) - AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs]) - AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available]) -fi - -################## -# look for a method of finding the list of network interfaces -iface=no; -AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[ -AC_TRY_RUN([ -#define HAVE_IFACE_GETIFADDRS 1 -#define NO_CONFIG_H 1 -#define AUTOCONF_TEST 1 -#define SOCKET_WRAPPER_NOT_REPLACE -#include "$libreplacedir/replace.c" -#include "$libreplacedir/inet_ntop.c" -#include "$libreplacedir/snprintf.c" -#include "$libreplacedir/getifaddrs.c" -#define getifaddrs_test main -#include "$libreplacedir/test/getifaddrs.c"], - libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)]) -if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then - iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available]) -else - LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} $libreplacedir/getifaddrs.o" -fi - - -if test $iface = no; then -AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[ -AC_TRY_RUN([ -#define HAVE_IFACE_AIX 1 -#define NO_CONFIG_H 1 -#define AUTOCONF_TEST 1 -#undef _XOPEN_SOURCE_EXTENDED -#define SOCKET_WRAPPER_NOT_REPLACE -#include "$libreplacedir/replace.c" -#include "$libreplacedir/inet_ntop.c" -#include "$libreplacedir/snprintf.c" -#include "$libreplacedir/getifaddrs.c" -#define getifaddrs_test main -#include "$libreplacedir/test/getifaddrs.c"], - libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)]) -if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then - iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available]) -fi -fi - - -if test $iface = no; then -AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[ -AC_TRY_RUN([ -#define HAVE_IFACE_IFCONF 1 -#define NO_CONFIG_H 1 -#define AUTOCONF_TEST 1 -#define SOCKET_WRAPPER_NOT_REPLACE -#include "$libreplacedir/replace.c" -#include "$libreplacedir/inet_ntop.c" -#include "$libreplacedir/snprintf.c" -#include "$libreplacedir/getifaddrs.c" -#define getifaddrs_test main -#include "$libreplacedir/test/getifaddrs.c"], - libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)]) -if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then - iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available]) -fi -fi - -if test $iface = no; then -AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[ -AC_TRY_RUN([ -#define HAVE_IFACE_IFREQ 1 -#define NO_CONFIG_H 1 -#define AUTOCONF_TEST 1 -#define SOCKET_WRAPPER_NOT_REPLACE -#include "$libreplacedir/replace.c" -#include "$libreplacedir/inet_ntop.c" -#include "$libreplacedir/snprintf.c" -#include "$libreplacedir/getifaddrs.c" -#define getifaddrs_test main -#include "$libreplacedir/test/getifaddrs.c"], - libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)]) -if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then - iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available]) -fi -fi - -dnl Some old Linux systems have broken header files and -dnl miss the IPV6_V6ONLY define in netinet/in.h, -dnl but have it in linux/in6.h. -dnl We can't include both files so we just check if the value -dnl if defined and do the replacement in system/network.h -AC_CACHE_CHECK([for IPV6_V6ONLY support],libreplace_cv_HAVE_IPV6_V6ONLY,[ - AC_TRY_COMPILE([ -#include /* for NULL */ -#include -#include -#include -#include - ], - [ -#ifndef IPV6_V6ONLY -#error no IPV6_V6ONLY -#endif - ],[ - libreplace_cv_HAVE_IPV6_V6ONLY=yes - ],[ - libreplace_cv_HAVE_IPV6_V6ONLY=no - ]) -]) -if test x"$libreplace_cv_HAVE_IPV6_V6ONLY" != x"yes"; then - dnl test for IPV6_V6ONLY - AC_CACHE_CHECK([for IPV6_V6ONLY in linux/in6.h],libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26,[ - AC_TRY_COMPILE([ - #include - ], - [ - #if (IPV6_V6ONLY != 26) - #error no linux IPV6_V6ONLY - #endif - ],[ - libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26=yes - ],[ - libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26=no - ]) - ]) - if test x"$libreplace_cv_HAVE_LINUX_IPV6_V6ONLY_26" = x"yes"; then - AC_DEFINE(HAVE_LINUX_IPV6_V6ONLY_26,1,[Whether the system has IPV6_V6ONLY in linux/in6.h]) - fi -fi - -dnl test for ipv6 -AC_CACHE_CHECK([for ipv6 support],libreplace_cv_HAVE_IPV6,[ - AC_TRY_LINK([ -#include /* for NULL */ -#include -#include -#include -#include - ], - [ -struct sockaddr_storage sa_store; -struct addrinfo *ai = NULL; -struct in6_addr in6addr; -int idx = if_nametoindex("iface1"); -int s = socket(AF_INET6, SOCK_STREAM, 0); -int ret = getaddrinfo(NULL, NULL, NULL, &ai); -if (ret != 0) { - const char *es = gai_strerror(ret); -} -freeaddrinfo(ai); -{ - int val = 1; - #ifdef HAVE_LINUX_IPV6_V6ONLY_26 - #define IPV6_V6ONLY 26 - #endif - ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, - (const void *)&val, sizeof(val)); -} - ],[ - libreplace_cv_HAVE_IPV6=yes - ],[ - libreplace_cv_HAVE_IPV6=no - ]) -]) -if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then - AC_DEFINE(HAVE_IPV6,1,[Whether the system has IPv6 support]) -fi - -LIBS=$old_LIBS -CPPFLAGS="$libreplace_SAVE_CPPFLAGS" - -LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}" - -echo "LIBREPLACE_NETWORK_CHECKS: END" -]) dnl end AC_LIBREPLACE_NETWORK_CHECKS diff --git a/bundled/replace/repdir.m4 b/bundled/replace/repdir.m4 deleted file mode 100644 index 682ab44c..00000000 --- a/bundled/replace/repdir.m4 +++ /dev/null @@ -1,81 +0,0 @@ -AC_CACHE_CHECK([for broken readdir],libreplace_cv_READDIR_NEEDED,[ - AC_TRY_RUN([ -#define test_readdir_os2_delete main -#include "$libreplacedir/test/os2_delete.c"], - [libreplace_cv_READDIR_NEEDED=no], - [libreplace_cv_READDIR_NEEDED=yes], - [libreplace_cv_READDIR_NEEDED="assuming not"]) -]) - -AC_CHECK_FUNCS(dirfd) -AC_HAVE_DECL(dirfd, [#include ]) - -# -# try to replace with getdirentries() if needed -# -if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then -AC_CHECK_FUNCS(getdirentries) -AC_VERIFY_C_PROTOTYPE([long telldir(const DIR *dir)], - [ - return 0; - ],[ - AC_DEFINE(TELLDIR_TAKES_CONST_DIR, 1, [Whether telldir takes a const pointer]) - ],[],[ - #include - ]) - -AC_VERIFY_C_PROTOTYPE([int seekdir(DIR *dir, long ofs)], - [ - return 0; - ],[ - AC_DEFINE(SEEKDIR_RETURNS_INT, 1, [Whether seekdir returns an int]) - ],[],[ - #include - ]) -AC_CACHE_CHECK([for replacing readdir using getdirentries()],libreplace_cv_READDIR_GETDIRENTRIES,[ - AC_TRY_RUN([ -#define _LIBREPLACE_REPLACE_H -#include "$libreplacedir/repdir_getdirentries.c" -#define test_readdir_os2_delete main -#include "$libreplacedir/test/os2_delete.c"], - [libreplace_cv_READDIR_GETDIRENTRIES=yes], - [libreplace_cv_READDIR_GETDIRENTRIES=no]) -]) -fi -if test x"$libreplace_cv_READDIR_GETDIRENTRIES" = x"yes"; then - AC_DEFINE(REPLACE_READDIR,1,[replace readdir]) - AC_DEFINE(REPLACE_READDIR_GETDIRENTRIES,1,[replace readdir using getdirentries()]) - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/repdir_getdirentries.o" - libreplace_cv_READDIR_NEEDED=no -fi - -# -# try to replace with getdents() if needed -# -if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then -AC_CHECK_FUNCS(getdents) -AC_CACHE_CHECK([for replacing readdir using getdents()],libreplace_cv_READDIR_GETDENTS,[ - AC_TRY_RUN([ -#define _LIBREPLACE_REPLACE_H -#error _donot_use_getdents_replacement_anymore -#include "$libreplacedir/repdir_getdents.c" -#define test_readdir_os2_delete main -#include "$libreplacedir/test/os2_delete.c"], - [libreplace_cv_READDIR_GETDENTS=yes], - [libreplace_cv_READDIR_GETDENTS=no]) -]) -fi -if test x"$libreplace_cv_READDIR_GETDENTS" = x"yes"; then - AC_DEFINE(REPLACE_READDIR,1,[replace readdir]) - AC_DEFINE(REPLACE_READDIR_GETDENTS,1,[replace readdir using getdents()]) - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/repdir_getdents.o" - libreplace_cv_READDIR_NEEDED=no -fi - -AC_MSG_CHECKING([a usable readdir()]) -if test x"$libreplace_cv_READDIR_NEEDED" = x"yes"; then - AC_MSG_RESULT(no) - AC_MSG_WARN([the provided readdir() is broken]) -else - AC_MSG_RESULT(yes) -fi diff --git a/bundled/replace/repdir_getdents.c b/bundled/replace/repdir_getdents.c deleted file mode 100644 index afc634a7..00000000 --- a/bundled/replace/repdir_getdents.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - Copyright (C) Andrew Tridgell 2005 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ -/* - a replacement for opendir/readdir/telldir/seekdir/closedir for BSD systems - - This is needed because the existing directory handling in FreeBSD - and OpenBSD (and possibly NetBSD) doesn't correctly handle unlink() - on files in a directory where telldir() has been used. On a block - boundary it will occasionally miss a file when seekdir() is used to - return to a position previously recorded with telldir(). - - This also fixes a severe performance and memory usage problem with - telldir() on BSD systems. Each call to telldir() in BSD adds an - entry to a linked list, and those entries are cleaned up on - closedir(). This means with a large directory closedir() can take an - arbitrary amount of time, causing network timeouts as millions of - telldir() entries are freed - - Note! This replacement code is not portable. It relies on getdents() - always leaving the file descriptor at a seek offset that is a - multiple of DIR_BUF_SIZE. If the code detects that this doesn't - happen then it will abort(). It also does not handle directories - with offsets larger than can be stored in a long, - - This code is available under other free software licenses as - well. Contact the author. -*/ - -#include -#include -#include -#include -#include -#include -#include - -#define DIR_BUF_BITS 9 -#define DIR_BUF_SIZE (1<fd = open(dname, O_RDONLY); - if (d->fd == -1) { - free(d); - return NULL; - } - if (fstat(d->fd, &sb) < 0) { - close(d->fd); - free(d); - return NULL; - } - if (!S_ISDIR(sb.st_mode)) { - close(d->fd); - free(d); - errno = ENOTDIR; - return NULL; - } - d->ofs = 0; - d->seekpos = 0; - d->nbytes = 0; - return (DIR *)d; -} - -struct dirent *readdir(DIR *dir) -{ - struct dir_buf *d = (struct dir_buf *)dir; - struct dirent *de; - - if (d->ofs >= d->nbytes) { - d->seekpos = lseek(d->fd, 0, SEEK_CUR); - d->nbytes = getdents(d->fd, d->buf, DIR_BUF_SIZE); - d->ofs = 0; - } - if (d->ofs >= d->nbytes) { - return NULL; - } - de = (struct dirent *)&d->buf[d->ofs]; - d->ofs += de->d_reclen; - return de; -} - -long telldir(DIR *dir) -{ - struct dir_buf *d = (struct dir_buf *)dir; - if (d->ofs >= d->nbytes) { - d->seekpos = lseek(d->fd, 0, SEEK_CUR); - d->ofs = 0; - d->nbytes = 0; - } - /* this relies on seekpos always being a multiple of - DIR_BUF_SIZE. Is that always true on BSD systems? */ - if (d->seekpos & (DIR_BUF_SIZE-1)) { - abort(); - } - return d->seekpos + d->ofs; -} - -void seekdir(DIR *dir, long ofs) -{ - struct dir_buf *d = (struct dir_buf *)dir; - d->seekpos = lseek(d->fd, ofs & ~(DIR_BUF_SIZE-1), SEEK_SET); - d->nbytes = getdents(d->fd, d->buf, DIR_BUF_SIZE); - d->ofs = 0; - while (d->ofs < (ofs & (DIR_BUF_SIZE-1))) { - if (readdir(dir) == NULL) break; - } -} - -void rewinddir(DIR *dir) -{ - seekdir(dir, 0); -} - -int closedir(DIR *dir) -{ - struct dir_buf *d = (struct dir_buf *)dir; - int r = close(d->fd); - if (r != 0) { - return r; - } - free(d); - return 0; -} - -#ifndef dirfd -/* darn, this is a macro on some systems. */ -int dirfd(DIR *dir) -{ - struct dir_buf *d = (struct dir_buf *)dir; - return d->fd; -} -#endif diff --git a/bundled/replace/repdir_getdirentries.c b/bundled/replace/repdir_getdirentries.c deleted file mode 100644 index 197e5931..00000000 --- a/bundled/replace/repdir_getdirentries.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - Copyright (C) Andrew Tridgell 2005 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ -/* - a replacement for opendir/readdir/telldir/seekdir/closedir for BSD - systems using getdirentries - - This is needed because the existing directory handling in FreeBSD - and OpenBSD (and possibly NetBSD) doesn't correctly handle unlink() - on files in a directory where telldir() has been used. On a block - boundary it will occasionally miss a file when seekdir() is used to - return to a position previously recorded with telldir(). - - This also fixes a severe performance and memory usage problem with - telldir() on BSD systems. Each call to telldir() in BSD adds an - entry to a linked list, and those entries are cleaned up on - closedir(). This means with a large directory closedir() can take an - arbitrary amount of time, causing network timeouts as millions of - telldir() entries are freed - - Note! This replacement code is not portable. It relies on - getdirentries() always leaving the file descriptor at a seek offset - that is a multiple of DIR_BUF_SIZE. If the code detects that this - doesn't happen then it will abort(). It also does not handle - directories with offsets larger than can be stored in a long, - - This code is available under other free software licenses as - well. Contact the author. -*/ - -#include "replace.h" -#include -#include -#include -#include -#include -#include -#include - -#define DIR_BUF_BITS 9 -#define DIR_BUF_SIZE (1<fd = open(dname, O_RDONLY); - if (d->fd == -1) { - free(d); - return NULL; - } - if (fstat(d->fd, &sb) < 0) { - close(d->fd); - free(d); - return NULL; - } - if (!S_ISDIR(sb.st_mode)) { - close(d->fd); - free(d); - errno = ENOTDIR; - return NULL; - } - d->ofs = 0; - d->seekpos = 0; - d->nbytes = 0; - return (DIR *)d; -} - -struct dirent *readdir(DIR *dir) -{ - struct dir_buf *d = (struct dir_buf *)dir; - struct dirent *de; - - if (d->ofs >= d->nbytes) { - long pos; - d->nbytes = getdirentries(d->fd, d->buf, DIR_BUF_SIZE, &pos); - d->seekpos = pos; - d->ofs = 0; - } - if (d->ofs >= d->nbytes) { - return NULL; - } - de = (struct dirent *)&d->buf[d->ofs]; - d->ofs += de->d_reclen; - return de; -} - -#ifdef TELLDIR_TAKES_CONST_DIR -long telldir(const DIR *dir) -#else -long telldir(DIR *dir) -#endif -{ - struct dir_buf *d = (struct dir_buf *)dir; - if (d->ofs >= d->nbytes) { - d->seekpos = lseek(d->fd, 0, SEEK_CUR); - d->ofs = 0; - d->nbytes = 0; - } - /* this relies on seekpos always being a multiple of - DIR_BUF_SIZE. Is that always true on BSD systems? */ - if (d->seekpos & (DIR_BUF_SIZE-1)) { - abort(); - } - return d->seekpos + d->ofs; -} - -#ifdef SEEKDIR_RETURNS_INT -int seekdir(DIR *dir, long ofs) -#else -void seekdir(DIR *dir, long ofs) -#endif -{ - struct dir_buf *d = (struct dir_buf *)dir; - long pos; - d->seekpos = lseek(d->fd, ofs & ~(DIR_BUF_SIZE-1), SEEK_SET); - d->nbytes = getdirentries(d->fd, d->buf, DIR_BUF_SIZE, &pos); - d->ofs = 0; - while (d->ofs < (ofs & (DIR_BUF_SIZE-1))) { - if (readdir(dir) == NULL) break; - } -#ifdef SEEKDIR_RETURNS_INT - return -1; -#endif -} - -void rewinddir(DIR *dir) -{ - seekdir(dir, 0); -} - -int closedir(DIR *dir) -{ - struct dir_buf *d = (struct dir_buf *)dir; - int r = close(d->fd); - if (r != 0) { - return r; - } - free(d); - return 0; -} - -#ifndef dirfd -/* darn, this is a macro on some systems. */ -int dirfd(DIR *dir) -{ - struct dir_buf *d = (struct dir_buf *)dir; - return d->fd; -} -#endif - - diff --git a/bundled/replace/replace.c b/bundled/replace/replace.c deleted file mode 100644 index 12716ea6..00000000 --- a/bundled/replace/replace.c +++ /dev/null @@ -1,762 +0,0 @@ -/* - Unix SMB/CIFS implementation. - replacement routines for broken systems - Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) Jelmer Vernooij 2005-2008 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "replace.h" - -#include "system/filesys.h" -#include "system/time.h" -#include "system/passwd.h" -#include "system/syslog.h" -#include "system/locale.h" -#include "system/wait.h" - -#ifdef _WIN32 -#define mkdir(d,m) _mkdir(d) -#endif - -void replace_dummy(void); -void replace_dummy(void) {} - -#ifndef HAVE_FTRUNCATE - /******************************************************************* -ftruncate for operating systems that don't have it -********************************************************************/ -int rep_ftruncate(int f, off_t l) -{ -#ifdef HAVE_CHSIZE - return chsize(f,l); -#elif defined(F_FREESP) - struct flock fl; - - fl.l_whence = 0; - fl.l_len = 0; - fl.l_start = l; - fl.l_type = F_WRLCK; - return fcntl(f, F_FREESP, &fl); -#else -#error "you must have a ftruncate function" -#endif -} -#endif /* HAVE_FTRUNCATE */ - - -#ifndef HAVE_STRLCPY -/* like strncpy but does not 0 fill the buffer and always null - terminates. bufsize is the size of the destination buffer */ -size_t rep_strlcpy(char *d, const char *s, size_t bufsize) -{ - size_t len = strlen(s); - size_t ret = len; - if (bufsize <= 0) return 0; - if (len >= bufsize) len = bufsize-1; - memcpy(d, s, len); - d[len] = 0; - return ret; -} -#endif - -#ifndef HAVE_STRLCAT -/* like strncat but does not 0 fill the buffer and always null - terminates. bufsize is the length of the buffer, which should - be one more than the maximum resulting string length */ -size_t rep_strlcat(char *d, const char *s, size_t bufsize) -{ - size_t len1 = strlen(d); - size_t len2 = strlen(s); - size_t ret = len1 + len2; - - if (len1+len2 >= bufsize) { - if (bufsize < (len1+1)) { - return ret; - } - len2 = bufsize - (len1+1); - } - if (len2 > 0) { - memcpy(d+len1, s, len2); - d[len1+len2] = 0; - } - return ret; -} -#endif - -#ifndef HAVE_MKTIME -/******************************************************************* -a mktime() replacement for those who don't have it - contributed by -C.A. Lademann -Corrections by richard.kettlewell@kewill.com -********************************************************************/ - -#define MINUTE 60 -#define HOUR 60*MINUTE -#define DAY 24*HOUR -#define YEAR 365*DAY -time_t rep_mktime(struct tm *t) -{ - struct tm *u; - time_t epoch = 0; - int n; - int mon [] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - y, m, i; - - if(t->tm_year < 70) - return((time_t)-1); - - n = t->tm_year + 1900 - 1; - epoch = (t->tm_year - 70) * YEAR + - ((n / 4 - n / 100 + n / 400) - (1969 / 4 - 1969 / 100 + 1969 / 400)) * DAY; - - y = t->tm_year + 1900; - m = 0; - - for(i = 0; i < t->tm_mon; i++) { - epoch += mon [m] * DAY; - if(m == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) - epoch += DAY; - - if(++m > 11) { - m = 0; - y++; - } - } - - epoch += (t->tm_mday - 1) * DAY; - epoch += t->tm_hour * HOUR + t->tm_min * MINUTE + t->tm_sec; - - if((u = localtime(&epoch)) != NULL) { - t->tm_sec = u->tm_sec; - t->tm_min = u->tm_min; - t->tm_hour = u->tm_hour; - t->tm_mday = u->tm_mday; - t->tm_mon = u->tm_mon; - t->tm_year = u->tm_year; - t->tm_wday = u->tm_wday; - t->tm_yday = u->tm_yday; - t->tm_isdst = u->tm_isdst; - } - - return(epoch); -} -#endif /* !HAVE_MKTIME */ - - -#ifndef HAVE_INITGROUPS -/**************************************************************************** - some systems don't have an initgroups call -****************************************************************************/ -int rep_initgroups(char *name, gid_t id) -{ -#ifndef HAVE_SETGROUPS - /* yikes! no SETGROUPS or INITGROUPS? how can this work? */ - errno = ENOSYS; - return -1; -#else /* HAVE_SETGROUPS */ - -#include - - gid_t *grouplst = NULL; - int max_gr = NGROUPS_MAX; - int ret; - int i,j; - struct group *g; - char *gr; - - if((grouplst = malloc(sizeof(gid_t) * max_gr)) == NULL) { - errno = ENOMEM; - return -1; - } - - grouplst[0] = id; - i = 1; - while (i < max_gr && ((g = (struct group *)getgrent()) != (struct group *)NULL)) { - if (g->gr_gid == id) - continue; - j = 0; - gr = g->gr_mem[0]; - while (gr && (*gr != (char)NULL)) { - if (strcmp(name,gr) == 0) { - grouplst[i] = g->gr_gid; - i++; - gr = (char *)NULL; - break; - } - gr = g->gr_mem[++j]; - } - } - endgrent(); - ret = setgroups(i, grouplst); - free(grouplst); - return ret; -#endif /* HAVE_SETGROUPS */ -} -#endif /* HAVE_INITGROUPS */ - - -#if (defined(SecureWare) && defined(SCO)) -/* This is needed due to needing the nap() function but we don't want - to include the Xenix libraries since that will break other things... - BTW: system call # 0x0c28 is the same as calling nap() */ -long nap(long milliseconds) { - return syscall(0x0c28, milliseconds); - } -#endif - - -#ifndef HAVE_MEMMOVE -/******************************************************************* -safely copies memory, ensuring no overlap problems. -this is only used if the machine does not have its own memmove(). -this is not the fastest algorithm in town, but it will do for our -needs. -********************************************************************/ -void *rep_memmove(void *dest,const void *src,int size) -{ - unsigned long d,s; - int i; - if (dest==src || !size) return(dest); - - d = (unsigned long)dest; - s = (unsigned long)src; - - if ((d >= (s+size)) || (s >= (d+size))) { - /* no overlap */ - memcpy(dest,src,size); - return(dest); - } - - if (d < s) { - /* we can forward copy */ - if (s-d >= sizeof(int) && - !(s%sizeof(int)) && - !(d%sizeof(int)) && - !(size%sizeof(int))) { - /* do it all as words */ - int *idest = (int *)dest; - int *isrc = (int *)src; - size /= sizeof(int); - for (i=0;i= sizeof(int) && - !(s%sizeof(int)) && - !(d%sizeof(int)) && - !(size%sizeof(int))) { - /* do it all as words */ - int *idest = (int *)dest; - int *isrc = (int *)src; - size /= sizeof(int); - for (i=size-1;i>=0;i--) idest[i] = isrc[i]; - } else { - /* simplest */ - char *cdest = (char *)dest; - char *csrc = (char *)src; - for (i=size-1;i>=0;i--) cdest[i] = csrc[i]; - } - } - return(dest); -} -#endif /* HAVE_MEMMOVE */ - -#ifndef HAVE_STRDUP -/**************************************************************************** -duplicate a string -****************************************************************************/ -char *rep_strdup(const char *s) -{ - size_t len; - char *ret; - - if (!s) return(NULL); - - len = strlen(s)+1; - ret = (char *)malloc(len); - if (!ret) return(NULL); - memcpy(ret,s,len); - return(ret); -} -#endif /* HAVE_STRDUP */ - -#ifndef HAVE_SETLINEBUF -void rep_setlinebuf(FILE *stream) -{ - setvbuf(stream, (char *)NULL, _IOLBF, 0); -} -#endif /* HAVE_SETLINEBUF */ - -#ifndef HAVE_VSYSLOG -#ifdef HAVE_SYSLOG -void rep_vsyslog (int facility_priority, const char *format, va_list arglist) -{ - char *msg = NULL; - vasprintf(&msg, format, arglist); - if (!msg) - return; - syslog(facility_priority, "%s", msg); - free(msg); -} -#endif /* HAVE_SYSLOG */ -#endif /* HAVE_VSYSLOG */ - -#ifndef HAVE_STRNLEN -/** - Some platforms don't have strnlen -**/ - size_t rep_strnlen(const char *s, size_t max) -{ - size_t len; - - for (len = 0; len < max; len++) { - if (s[len] == '\0') { - break; - } - } - return len; -} -#endif - -#ifndef HAVE_STRNDUP -/** - Some platforms don't have strndup. -**/ -char *rep_strndup(const char *s, size_t n) -{ - char *ret; - - n = strnlen(s, n); - ret = malloc(n+1); - if (!ret) - return NULL; - memcpy(ret, s, n); - ret[n] = 0; - - return ret; -} -#endif - -#if !defined(HAVE_WAITPID) && defined(HAVE_WAIT4) -int rep_waitpid(pid_t pid,int *status,int options) -{ - return wait4(pid, status, options, NULL); -} -#endif - -#ifndef HAVE_SETEUID -int rep_seteuid(uid_t euid) -{ -#ifdef HAVE_SETRESUID - return setresuid(-1, euid, -1); -#else - errno = ENOSYS; - return -1; -#endif -} -#endif - -#ifndef HAVE_SETEGID -int rep_setegid(gid_t egid) -{ -#ifdef HAVE_SETRESGID - return setresgid(-1, egid, -1); -#else - errno = ENOSYS; - return -1; -#endif -} -#endif - -/******************************************************************* -os/2 also doesn't have chroot -********************************************************************/ -#ifndef HAVE_CHROOT -int rep_chroot(const char *dname) -{ - errno = ENOSYS; - return -1; -} -#endif - -/***************************************************************** - Possibly replace mkstemp if it is broken. -*****************************************************************/ - -#ifndef HAVE_SECURE_MKSTEMP -int rep_mkstemp(char *template) -{ - /* have a reasonable go at emulating it. Hope that - the system mktemp() isn't completely hopeless */ - char *p = mktemp(template); - if (!p) - return -1; - return open(p, O_CREAT|O_EXCL|O_RDWR, 0600); -} -#endif - -#ifndef HAVE_MKDTEMP -char *rep_mkdtemp(char *template) -{ - char *dname; - - if ((dname = mktemp(template))) { - if (mkdir(dname, 0700) >= 0) { - return dname; - } - } - - return NULL; -} -#endif - -/***************************************************************** - Watch out: this is not thread safe. -*****************************************************************/ - -#ifndef HAVE_PREAD -ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset) -{ - if (lseek(__fd, __offset, SEEK_SET) != __offset) { - return -1; - } - return read(__fd, __buf, __nbytes); -} -#endif - -/***************************************************************** - Watch out: this is not thread safe. -*****************************************************************/ - -#ifndef HAVE_PWRITE -ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset) -{ - if (lseek(__fd, __offset, SEEK_SET) != __offset) { - return -1; - } - return write(__fd, __buf, __nbytes); -} -#endif - -#ifndef HAVE_STRCASESTR -char *rep_strcasestr(const char *haystack, const char *needle) -{ - const char *s; - size_t nlen = strlen(needle); - for (s=haystack;*s;s++) { - if (toupper(*needle) == toupper(*s) && - strncasecmp(s, needle, nlen) == 0) { - return (char *)((uintptr_t)s); - } - } - return NULL; -} -#endif - -#ifndef HAVE_STRTOK_R -/* based on GLIBC version, copyright Free Software Foundation */ -char *rep_strtok_r(char *s, const char *delim, char **save_ptr) -{ - char *token; - - if (s == NULL) s = *save_ptr; - - s += strspn(s, delim); - if (*s == '\0') { - *save_ptr = s; - return NULL; - } - - token = s; - s = strpbrk(token, delim); - if (s == NULL) { - *save_ptr = token + strlen(token); - } else { - *s = '\0'; - *save_ptr = s + 1; - } - - return token; -} -#endif - -#ifndef HAVE_STRTOLL -long long int rep_strtoll(const char *str, char **endptr, int base) -{ -#ifdef HAVE_STRTOQ - return strtoq(str, endptr, base); -#elif defined(HAVE___STRTOLL) - return __strtoll(str, endptr, base); -#elif SIZEOF_LONG == SIZEOF_LONG_LONG - return (long long int) strtol(str, endptr, base); -#else -# error "You need a strtoll function" -#endif -} -#endif - - -#ifndef HAVE_STRTOULL -unsigned long long int rep_strtoull(const char *str, char **endptr, int base) -{ -#ifdef HAVE_STRTOUQ - return strtouq(str, endptr, base); -#elif defined(HAVE___STRTOULL) - return __strtoull(str, endptr, base); -#elif SIZEOF_LONG == SIZEOF_LONG_LONG - return (unsigned long long int) strtoul(str, endptr, base); -#else -# error "You need a strtoull function" -#endif -} -#endif - -#ifndef HAVE_SETENV -int rep_setenv(const char *name, const char *value, int overwrite) -{ - char *p; - size_t l1, l2; - int ret; - - if (!overwrite && getenv(name)) { - return 0; - } - - l1 = strlen(name); - l2 = strlen(value); - - p = malloc(l1+l2+2); - if (p == NULL) { - return -1; - } - memcpy(p, name, l1); - p[l1] = '='; - memcpy(p+l1+1, value, l2); - p[l1+l2+1] = 0; - - ret = putenv(p); - if (ret != 0) { - free(p); - } - - return ret; -} -#endif - -#ifndef HAVE_UNSETENV -int rep_unsetenv(const char *name) -{ - extern char **environ; - size_t len = strlen(name); - size_t i, count; - - if (environ == NULL || getenv(name) == NULL) { - return 0; - } - - for (i=0;environ[i];i++) /* noop */ ; - - count=i; - - for (i=0;i= needlelen) { - char *p = (char *)memchr(haystack, *(const char *)needle, - haystacklen-(needlelen-1)); - if (!p) return NULL; - if (memcmp(p, needle, needlelen) == 0) { - return p; - } - haystack = p+1; - haystacklen -= (p - (const char *)haystack) + 1; - } - return NULL; -} -#endif - -#ifndef HAVE_VDPRINTF -int rep_vdprintf(int fd, const char *format, va_list ap) -{ - char *s = NULL; - int ret; - - vasprintf(&s, format, ap); - if (s == NULL) { - errno = ENOMEM; - return -1; - } - ret = write(fd, s, strlen(s)); - free(s); - return ret; -} -#endif - -#ifndef HAVE_DPRINTF -int rep_dprintf(int fd, const char *format, ...) -{ - int ret; - va_list ap; - - va_start(ap, format); - ret = vdprintf(fd, format, ap); - va_end(ap); - - return ret; -} -#endif - -#ifndef HAVE_GET_CURRENT_DIR_NAME -char *rep_get_current_dir_name(void) -{ - char buf[PATH_MAX+1]; - char *p; - p = getcwd(buf, sizeof(buf)); - if (p == NULL) { - return NULL; - } - return strdup(p); -} -#endif - -#if !defined(HAVE_STRERROR_R) || !defined(STRERROR_R_PROTO_COMPATIBLE) -int rep_strerror_r(int errnum, char *buf, size_t buflen) -{ - char *s = strerror(errnum); - if (strlen(s)+1 > buflen) { - errno = ERANGE; - return -1; - } - strncpy(buf, s, buflen); - return 0; -} -#endif diff --git a/bundled/replace/replace.h b/bundled/replace/replace.h deleted file mode 100644 index 4efcb4c6..00000000 --- a/bundled/replace/replace.h +++ /dev/null @@ -1,774 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - macros to go along with the lib/replace/ portability layer code - - Copyright (C) Andrew Tridgell 2005 - Copyright (C) Jelmer Vernooij 2006-2008 - Copyright (C) Jeremy Allison 2007. - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#ifndef _LIBREPLACE_REPLACE_H -#define _LIBREPLACE_REPLACE_H - -#ifndef NO_CONFIG_H -#include "config.h" -#endif - -#ifdef HAVE_STANDARDS_H -#include -#endif - -#include -#include -#include -#include - -#if defined(_MSC_VER) || defined(__MINGW32__) -#include "win32_replace.h" -#endif - - -#ifdef HAVE_STDINT_H -#include -/* force off HAVE_INTTYPES_H so that roken doesn't try to include both, - which causes a warning storm on irix */ -#undef HAVE_INTTYPES_H -#elif HAVE_INTTYPES_H -#define __STDC_FORMAT_MACROS -#include -#endif - -#ifndef __PRI64_PREFIX -# if __WORDSIZE == 64 -# define __PRI64_PREFIX "l" -# else -# define __PRI64_PREFIX "ll" -# endif -#endif - -/* Decimal notation. */ -#ifndef PRId8 -# define PRId8 "d" -#endif -#ifndef PRId16 -# define PRId16 "d" -#endif -#ifndef PRId32 -# define PRId32 "d" -#endif -#ifndef PRId64 -# define PRId64 __PRI64_PREFIX "d" -#endif - -#ifndef PRIi8 -# define PRIi8 "i" -#endif -#ifndef PRIi16 -# define PRIi16 "i" -#endif -#ifndef PRIi32 -# define PRIi32 "i" -#endif -#ifndef PRIi64 -# define PRIi64 __PRI64_PREFIX "i" -#endif - -#ifndef PRIu8 -# define PRIu8 "u" -#endif -#ifndef PRIu16 -# define PRIu16 "u" -#endif -#ifndef PRIu32 -# define PRIu32 "u" -#endif -#ifndef PRIu64 -# define PRIu64 __PRI64_PREFIX "u" -#endif - -#ifdef HAVE_STRING_H -#include -#endif - -#ifdef HAVE_STRINGS_H -#include -#endif - -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -#if STDC_HEADERS -#include -#include -#endif - -#ifndef HAVE_STRERROR -extern char *sys_errlist[]; -#define strerror(i) sys_errlist[i] -#endif - -#ifndef HAVE_ERRNO_DECL -extern int errno; -#endif - -#ifndef HAVE_STRDUP -#define strdup rep_strdup -char *rep_strdup(const char *s); -#endif - -#ifndef HAVE_MEMMOVE -#define memmove rep_memmove -void *rep_memmove(void *dest,const void *src,int size); -#endif - -#ifndef HAVE_MEMMEM -#define memmem rep_memmem -void *rep_memmem(const void *haystack, size_t haystacklen, - const void *needle, size_t needlelen); -#endif - -#ifndef HAVE_MKTIME -#define mktime rep_mktime -/* prototype is in "system/time.h" */ -#endif - -#ifndef HAVE_TIMEGM -#define timegm rep_timegm -/* prototype is in "system/time.h" */ -#endif - -#ifndef HAVE_UTIME -#define utime rep_utime -/* prototype is in "system/time.h" */ -#endif - -#ifndef HAVE_UTIMES -#define utimes rep_utimes -/* prototype is in "system/time.h" */ -#endif - -#ifndef HAVE_STRLCPY -#define strlcpy rep_strlcpy -size_t rep_strlcpy(char *d, const char *s, size_t bufsize); -#endif - -#ifndef HAVE_STRLCAT -#define strlcat rep_strlcat -size_t rep_strlcat(char *d, const char *s, size_t bufsize); -#endif - -#if (defined(BROKEN_STRNDUP) || !defined(HAVE_STRNDUP)) -#undef HAVE_STRNDUP -#define strndup rep_strndup -char *rep_strndup(const char *s, size_t n); -#endif - -#if (defined(BROKEN_STRNLEN) || !defined(HAVE_STRNLEN)) -#undef HAVE_STRNLEN -#define strnlen rep_strnlen -size_t rep_strnlen(const char *s, size_t n); -#endif - -#if !HAVE_DECL_ENVIRON -#ifdef __APPLE__ -#include -#define environ (*_NSGetEnviron()) -#else -extern char **environ; -#endif -#endif - -#ifndef HAVE_SETENV -#define setenv rep_setenv -int rep_setenv(const char *name, const char *value, int overwrite); -#else -#ifndef HAVE_SETENV_DECL -int setenv(const char *name, const char *value, int overwrite); -#endif -#endif - -#ifndef HAVE_UNSETENV -#define unsetenv rep_unsetenv -int rep_unsetenv(const char *name); -#endif - -#ifndef HAVE_SETEUID -#define seteuid rep_seteuid -int rep_seteuid(uid_t); -#endif - -#ifndef HAVE_SETEGID -#define setegid rep_setegid -int rep_setegid(gid_t); -#endif - -#if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL)) -/* stupid glibc */ -int setresuid(uid_t ruid, uid_t euid, uid_t suid); -#endif -#if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL)) -int setresgid(gid_t rgid, gid_t egid, gid_t sgid); -#endif - -#ifndef HAVE_CHOWN -#define chown rep_chown -int rep_chown(const char *path, uid_t uid, gid_t gid); -#endif - -#ifndef HAVE_CHROOT -#define chroot rep_chroot -int rep_chroot(const char *dirname); -#endif - -#ifndef HAVE_LINK -#define link rep_link -int rep_link(const char *oldpath, const char *newpath); -#endif - -#ifndef HAVE_READLINK -#define readlink rep_readlink -ssize_t rep_readlink(const char *path, char *buf, size_t bufsize); -#endif - -#ifndef HAVE_SYMLINK -#define symlink rep_symlink -int rep_symlink(const char *oldpath, const char *newpath); -#endif - -#ifndef HAVE_REALPATH -#define realpath rep_realpath -char *rep_realpath(const char *path, char *resolved_path); -#endif - -#ifndef HAVE_LCHOWN -#define lchown rep_lchown -int rep_lchown(const char *fname,uid_t uid,gid_t gid); -#endif - -#ifdef HAVE_UNIX_H -#include -#endif - -#ifndef HAVE_SETLINEBUF -#define setlinebuf rep_setlinebuf -void rep_setlinebuf(FILE *); -#endif - -#ifndef HAVE_STRCASESTR -#define strcasestr rep_strcasestr -char *rep_strcasestr(const char *haystack, const char *needle); -#endif - -#ifndef HAVE_STRTOK_R -#define strtok_r rep_strtok_r -char *rep_strtok_r(char *s, const char *delim, char **save_ptr); -#endif - -#ifndef HAVE_STRTOLL -#define strtoll rep_strtoll -long long int rep_strtoll(const char *str, char **endptr, int base); -#endif - -#ifndef HAVE_STRTOULL -#define strtoull rep_strtoull -unsigned long long int rep_strtoull(const char *str, char **endptr, int base); -#endif - -#ifndef HAVE_FTRUNCATE -#define ftruncate rep_ftruncate -int rep_ftruncate(int,off_t); -#endif - -#ifndef HAVE_INITGROUPS -#define initgroups rep_initgroups -int rep_initgroups(char *name, gid_t id); -#endif - -#if !defined(HAVE_BZERO) && defined(HAVE_MEMSET) -#define bzero(a,b) memset((a),'\0',(b)) -#endif - -#ifndef HAVE_DLERROR -#define dlerror rep_dlerror -char *rep_dlerror(void); -#endif - -#ifndef HAVE_DLOPEN -#define dlopen rep_dlopen -#ifdef DLOPEN_TAKES_UNSIGNED_FLAGS -void *rep_dlopen(const char *name, unsigned int flags); -#else -void *rep_dlopen(const char *name, int flags); -#endif -#endif - -#ifndef HAVE_DLSYM -#define dlsym rep_dlsym -void *rep_dlsym(void *handle, const char *symbol); -#endif - -#ifndef HAVE_DLCLOSE -#define dlclose rep_dlclose -int rep_dlclose(void *handle); -#endif - -#ifndef HAVE_SOCKETPAIR -#define socketpair rep_socketpair -/* prototype is in system/network.h */ -#endif - -#ifndef HAVE_VDPRINTF -#define vdprintf rep_vdprintf -int rep_vdprintf(int fd, const char *format, va_list ap); -#endif - -#ifndef HAVE_DPRINTF -#define dprintf rep_dprintf -int rep_dprintf(int fd, const char *format, ...); -#endif - -#ifndef PRINTF_ATTRIBUTE -#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) -/** Use gcc attribute to check printf fns. a1 is the 1-based index of - * the parameter containing the format, and a2 the index of the first - * argument. Note that some gcc 2.x versions don't handle this - * properly **/ -#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2))) -#else -#define PRINTF_ATTRIBUTE(a1, a2) -#endif -#endif - -#ifndef _DEPRECATED_ -#if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) -#define _DEPRECATED_ __attribute__ ((deprecated)) -#else -#define _DEPRECATED_ -#endif -#endif - -#ifndef HAVE_VASPRINTF -#define vasprintf rep_vasprintf -int rep_vasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); -#endif - -#if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF) -#define snprintf rep_snprintf -int rep_snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4); -#endif - -#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF) -#define vsnprintf rep_vsnprintf -int rep_vsnprintf(char *,size_t ,const char *, va_list ap) PRINTF_ATTRIBUTE(3,0); -#endif - -#ifndef HAVE_ASPRINTF -#define asprintf rep_asprintf -int rep_asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3); -#endif - -#ifndef HAVE_VSYSLOG -#ifdef HAVE_SYSLOG -#define vsyslog rep_vsyslog -void rep_vsyslog (int facility_priority, const char *format, va_list arglist) PRINTF_ATTRIBUTE(2,0); -#endif -#endif - -/* we used to use these fns, but now we have good replacements - for snprintf and vsnprintf */ -#define slprintf snprintf - - -#ifndef HAVE_VA_COPY -#undef va_copy -#ifdef HAVE___VA_COPY -#define va_copy(dest, src) __va_copy(dest, src) -#else -#define va_copy(dest, src) (dest) = (src) -#endif -#endif - -#ifndef HAVE_VOLATILE -#define volatile -#endif - -#ifndef HAVE_COMPARISON_FN_T -typedef int (*comparison_fn_t)(const void *, const void *); -#endif - -#ifdef REPLACE_STRPTIME -#define strptime rep_strptime -struct tm; -char *rep_strptime(const char *buf, const char *format, struct tm *tm); -#endif - -#ifndef HAVE_DUP2 -#define dup2 rep_dup2 -int rep_dup2(int oldfd, int newfd); -#endif - -/* Load header file for dynamic linking stuff */ -#ifdef HAVE_DLFCN_H -#include -#endif - -#ifndef RTLD_LAZY -#define RTLD_LAZY 0 -#endif -#ifndef RTLD_NOW -#define RTLD_NOW 0 -#endif -#ifndef RTLD_GLOBAL -#define RTLD_GLOBAL 0 -#endif - -#ifndef HAVE_SECURE_MKSTEMP -#define mkstemp(path) rep_mkstemp(path) -int rep_mkstemp(char *temp); -#endif - -#ifndef HAVE_MKDTEMP -#define mkdtemp rep_mkdtemp -char *rep_mkdtemp(char *template); -#endif - -#ifndef HAVE_PREAD -#define pread rep_pread -ssize_t rep_pread(int __fd, void *__buf, size_t __nbytes, off_t __offset); -#define LIBREPLACE_PREAD_REPLACED 1 -#else -#define LIBREPLACE_PREAD_NOT_REPLACED 1 -#endif - -#ifndef HAVE_PWRITE -#define pwrite rep_pwrite -ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset); -#define LIBREPLACE_PWRITE_REPLACED 1 -#else -#define LIBREPLACE_PWRITE_NOT_REPLACED 1 -#endif - -#if !defined(HAVE_INET_NTOA) || defined(REPLACE_INET_NTOA) -#define inet_ntoa rep_inet_ntoa -/* prototype is in "system/network.h" */ -#endif - -#ifndef HAVE_INET_PTON -#define inet_pton rep_inet_pton -/* prototype is in "system/network.h" */ -#endif - -#ifndef HAVE_INET_NTOP -#define inet_ntop rep_inet_ntop -/* prototype is in "system/network.h" */ -#endif - -#ifndef HAVE_INET_ATON -#define inet_aton rep_inet_aton -/* prototype is in "system/network.h" */ -#endif - -#ifndef HAVE_CONNECT -#define connect rep_connect -/* prototype is in "system/network.h" */ -#endif - -#ifndef HAVE_GETHOSTBYNAME -#define gethostbyname rep_gethostbyname -/* prototype is in "system/network.h" */ -#endif - -#ifndef HAVE_GETIFADDRS -#define getifaddrs rep_getifaddrs -/* prototype is in "system/network.h" */ -#endif - -#ifndef HAVE_FREEIFADDRS -#define freeifaddrs rep_freeifaddrs -/* prototype is in "system/network.h" */ -#endif - -#ifndef HAVE_GET_CURRENT_DIR_NAME -#define get_current_dir_name rep_get_current_dir_name -char *rep_get_current_dir_name(void); -#endif - -#if !defined(HAVE_STRERROR_R) || !defined(STRERROR_R_PROTO_COMPATIBLE) -#define strerror_r rep_strerror_r -int rep_strerror_r(int errnum, char *buf, size_t buflen); -#endif - -#ifdef HAVE_LIMITS_H -#include -#endif - -#ifdef HAVE_SYS_PARAM_H -#include -#endif - -/* The extra casts work around common compiler bugs. */ -#define _TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) -/* The outer cast is needed to work around a bug in Cray C 5.0.3.0. - It is necessary at least when t == time_t. */ -#define _TYPE_MINIMUM(t) ((t) (_TYPE_SIGNED (t) \ - ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0)) -#define _TYPE_MAXIMUM(t) ((t) (~ (t) 0 - _TYPE_MINIMUM (t))) - -#ifndef UINT16_MAX -#define UINT16_MAX 65535 -#endif - -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#ifndef UINT64_MAX -#define UINT64_MAX ((uint64_t)-1) -#endif - -#ifndef CHAR_BIT -#define CHAR_BIT 8 -#endif - -#ifndef INT32_MAX -#define INT32_MAX _TYPE_MAXIMUM(int32_t) -#endif - -#ifdef HAVE_STDBOOL_H -#include -#endif - -#if !defined(HAVE_BOOL) -#ifdef HAVE__Bool -#define bool _Bool -#else -typedef int bool; -#endif -#endif - -#if !defined(HAVE_INTPTR_T) -typedef long long intptr_t ; -#endif - -#if !defined(HAVE_UINTPTR_T) -typedef unsigned long long uintptr_t ; -#endif - -#if !defined(HAVE_PTRDIFF_T) -typedef unsigned long long ptrdiff_t ; -#endif - -/* - * to prevent from doing a redefine of 'bool' - * - * IRIX, HPUX, MacOS 10 and Solaris need BOOL_DEFINED - * Tru64 needs _BOOL_EXISTS - * AIX needs _BOOL,_TRUE,_FALSE - */ -#ifndef BOOL_DEFINED -#define BOOL_DEFINED -#endif -#ifndef _BOOL_EXISTS -#define _BOOL_EXISTS -#endif -#ifndef _BOOL -#define _BOOL -#endif - -#ifndef __bool_true_false_are_defined -#define __bool_true_false_are_defined -#endif - -#ifndef true -#define true (1) -#endif -#ifndef false -#define false (0) -#endif - -#ifndef _TRUE -#define _TRUE true -#endif -#ifndef _FALSE -#define _FALSE false -#endif - -#ifndef HAVE_FUNCTION_MACRO -#ifdef HAVE_func_MACRO -#define __FUNCTION__ __func__ -#else -#define __FUNCTION__ ("") -#endif -#endif - - -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif - -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - -#if !defined(HAVE_VOLATILE) -#define volatile -#endif - -/** - this is a warning hack. The idea is to use this everywhere that we - get the "discarding const" warning from gcc. That doesn't actually - fix the problem of course, but it means that when we do get to - cleaning them up we can do it by searching the code for - discard_const. - - It also means that other error types aren't as swamped by the noise - of hundreds of const warnings, so we are more likely to notice when - we get new errors. - - Please only add more uses of this macro when you find it - _really_ hard to fix const warnings. Our aim is to eventually use - this function in only a very few places. - - Also, please call this via the discard_const_p() macro interface, as that - makes the return type safe. -*/ -#define discard_const(ptr) ((void *)((uintptr_t)(ptr))) - -/** Type-safe version of discard_const */ -#define discard_const_p(type, ptr) ((type *)discard_const(ptr)) - -#ifndef __STRING -#define __STRING(x) #x -#endif - -#ifndef __STRINGSTRING -#define __STRINGSTRING(x) __STRING(x) -#endif - -#ifndef __LINESTR__ -#define __LINESTR__ __STRINGSTRING(__LINE__) -#endif - -#ifndef __location__ -#define __location__ __FILE__ ":" __LINESTR__ -#endif - -/** - * zero a structure - */ -#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) - -/** - * zero a structure given a pointer to the structure - */ -#define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0) - -/** - * zero a structure given a pointer to the structure - no zero check - */ -#define ZERO_STRUCTPN(x) memset((char *)(x), 0, sizeof(*(x))) - -/* zero an array - note that sizeof(array) must work - ie. it must not be a - pointer */ -#define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x)) - -/** - * work out how many elements there are in a static array - */ -#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) - -/** - * pointer difference macro - */ -#define PTR_DIFF(p1,p2) ((ptrdiff_t)(((const char *)(p1)) - (const char *)(p2))) - -#if MMAP_BLACKLIST -#undef HAVE_MMAP -#endif - -#ifdef __COMPAR_FN_T -#define QSORT_CAST (__compar_fn_t) -#endif - -#ifndef QSORT_CAST -#define QSORT_CAST (int (*)(const void *, const void *)) -#endif - -#ifndef PATH_MAX -#define PATH_MAX 1024 -#endif - -#ifndef MAX_DNS_NAME_LENGTH -#define MAX_DNS_NAME_LENGTH 256 /* Actually 255 but +1 for terminating null. */ -#endif - -#ifndef HAVE_CRYPT -char *ufc_crypt(const char *key, const char *salt); -#define crypt ufc_crypt -#else -#ifdef HAVE_CRYPT_H -#include -#endif -#endif - -/* these macros gain us a few percent of speed on gcc */ -#if (__GNUC__ >= 3) -/* the strange !! is to ensure that __builtin_expect() takes either 0 or 1 - as its first argument */ -#ifndef likely -#define likely(x) __builtin_expect(!!(x), 1) -#endif -#ifndef unlikely -#define unlikely(x) __builtin_expect(!!(x), 0) -#endif -#else -#ifndef likely -#define likely(x) (x) -#endif -#ifndef unlikely -#define unlikely(x) (x) -#endif -#endif - -#ifndef HAVE_FDATASYNC -#define fdatasync(fd) fsync(fd) -#endif - -/* these are used to mark symbols as local to a shared lib, or - * publicly available via the shared lib API */ -#ifndef _PUBLIC_ -#ifdef HAVE_VISIBILITY_ATTR -#define _PUBLIC_ __attribute__((visibility("default"))) -#else -#define _PUBLIC_ -#endif -#endif - -#ifndef _PRIVATE_ -#ifdef HAVE_VISIBILITY_ATTR -# define _PRIVATE_ __attribute__((visibility("hidden"))) -#else -# define _PRIVATE_ -#endif -#endif - -#endif /* _LIBREPLACE_REPLACE_H */ diff --git a/bundled/replace/samba.m4 b/bundled/replace/samba.m4 deleted file mode 100644 index b7582202..00000000 --- a/bundled/replace/samba.m4 +++ /dev/null @@ -1,34 +0,0 @@ -AC_LIBREPLACE_BROKEN_CHECKS -AC_LIBREPLACE_NETWORK_CHECKS - -SMB_EXT_LIB(LIBREPLACE_EXT, [${LIBDL} ${CRYPT_LIBS}]) -SMB_ENABLE(LIBREPLACE_EXT) - -SMB_EXT_LIB(LIBREPLACE_NETWORK, [${LIBREPLACE_NETWORK_LIBS}]) -SMB_ENABLE(LIBREPLACE_NETWORK) - -# remove leading ./ -LIBREPLACE_DIR=`echo ${libreplacedir} |sed -e 's/^\.\///g'` - -# remove leading srcdir .. we are looking for the relative -# path within the samba source tree or wherever libreplace is. -# We need to make sure the object is not forced to end up in -# the source directory because we might be using a separate -# build directory. -LIBREPLACE_DIR=`echo ${LIBREPLACE_DIR} | sed -e "s|^$srcdir/||g"` - -LIBREPLACE_OBJS="${LIBREPLACEOBJ}" - -SMB_SUBSYSTEM(LIBREPLACE, - [${LIBREPLACE_OBJS}], - [LIBREPLACE_EXT LIBREPLACE_NETWORK], - [-Ilib/replace]) - -LIBREPLACE_HOSTCC_OBJS=`echo ${LIBREPLACE_OBJS} |sed -e 's/\.o/\.ho/g'` - -SMB_SUBSYSTEM(LIBREPLACE_HOSTCC, - [${LIBREPLACE_HOSTCC_OBJS}], - [], - [-Ilib/replace]) - -AC_CHECK_FUNCS([syslog],,[AC_MSG_ERROR([Required function not found])]) diff --git a/bundled/replace/snprintf.c b/bundled/replace/snprintf.c deleted file mode 100644 index bca77426..00000000 --- a/bundled/replace/snprintf.c +++ /dev/null @@ -1,1531 +0,0 @@ -/* - * NOTE: If you change this file, please merge it into rsync, samba, etc. - */ - -/* - * Copyright Patrick Powell 1995 - * This code is based on code written by Patrick Powell (papowell@astart.com) - * It may be used for any purpose as long as this notice remains intact - * on all source code distributions - */ - -/************************************************************** - * Original: - * Patrick Powell Tue Apr 11 09:48:21 PDT 1995 - * A bombproof version of doprnt (dopr) included. - * Sigh. This sort of thing is always nasty do deal with. Note that - * the version here does not include floating point... - * - * snprintf() is used instead of sprintf() as it does limit checks - * for string length. This covers a nasty loophole. - * - * The other functions are there to prevent NULL pointers from - * causing nast effects. - * - * More Recently: - * Brandon Long 9/15/96 for mutt 0.43 - * This was ugly. It is still ugly. I opted out of floating point - * numbers, but the formatter understands just about everything - * from the normal C string format, at least as far as I can tell from - * the Solaris 2.5 printf(3S) man page. - * - * Brandon Long 10/22/97 for mutt 0.87.1 - * Ok, added some minimal floating point support, which means this - * probably requires libm on most operating systems. Don't yet - * support the exponent (e,E) and sigfig (g,G). Also, fmtint() - * was pretty badly broken, it just wasn't being exercised in ways - * which showed it, so that's been fixed. Also, formated the code - * to mutt conventions, and removed dead code left over from the - * original. Also, there is now a builtin-test, just compile with: - * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm - * and run snprintf for results. - * - * Thomas Roessler 01/27/98 for mutt 0.89i - * The PGP code was using unsigned hexadecimal formats. - * Unfortunately, unsigned formats simply didn't work. - * - * Michael Elkins 03/05/98 for mutt 0.90.8 - * The original code assumed that both snprintf() and vsnprintf() were - * missing. Some systems only have snprintf() but not vsnprintf(), so - * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF. - * - * Andrew Tridgell (tridge@samba.org) Oct 1998 - * fixed handling of %.0f - * added test for HAVE_LONG_DOUBLE - * - * tridge@samba.org, idra@samba.org, April 2001 - * got rid of fcvt code (twas buggy and made testing harder) - * added C99 semantics - * - * date: 2002/12/19 19:56:31; author: herb; state: Exp; lines: +2 -0 - * actually print args for %g and %e - * - * date: 2002/06/03 13:37:52; author: jmcd; state: Exp; lines: +8 -0 - * Since includes.h isn't included here, VA_COPY has to be defined here. I don't - * see any include file that is guaranteed to be here, so I'm defining it - * locally. Fixes AIX and Solaris builds. - * - * date: 2002/06/03 03:07:24; author: tridge; state: Exp; lines: +5 -13 - * put the ifdef for HAVE_VA_COPY in one place rather than in lots of - * functions - * - * date: 2002/05/17 14:51:22; author: jmcd; state: Exp; lines: +21 -4 - * Fix usage of va_list passed as an arg. Use __va_copy before using it - * when it exists. - * - * date: 2002/04/16 22:38:04; author: idra; state: Exp; lines: +20 -14 - * Fix incorrect zpadlen handling in fmtfp. - * Thanks to Ollie Oldham for spotting it. - * few mods to make it easier to compile the tests. - * addedd the "Ollie" test to the floating point ones. - * - * Martin Pool (mbp@samba.org) April 2003 - * Remove NO_CONFIG_H so that the test case can be built within a source - * tree with less trouble. - * Remove unnecessary SAFE_FREE() definition. - * - * Martin Pool (mbp@samba.org) May 2003 - * Put in a prototype for dummy_snprintf() to quiet compiler warnings. - * - * Move #endif to make sure VA_COPY, LDOUBLE, etc are defined even - * if the C library has some snprintf functions already. - * - * Darren Tucker (dtucker@zip.com.au) 2005 - * Fix bug allowing read overruns of the source string with "%.*s" - * Usually harmless unless the read runs outside the process' allocation - * (eg if your malloc does guard pages) in which case it will segfault. - * From OpenSSH. Also added test for same. - * - * Simo Sorce (idra@samba.org) Jan 2006 - * - * Add support for position independent parameters - * fix fmtstr now it conforms to sprintf wrt min.max - * - **************************************************************/ - -#include "replace.h" -#include "system/locale.h" - -#ifdef TEST_SNPRINTF /* need math library headers for testing */ - -/* In test mode, we pretend that this system doesn't have any snprintf - * functions, regardless of what config.h says. */ -# undef HAVE_SNPRINTF -# undef HAVE_VSNPRINTF -# undef HAVE_C99_VSNPRINTF -# undef HAVE_ASPRINTF -# undef HAVE_VASPRINTF -# include -#endif /* TEST_SNPRINTF */ - -#if defined(HAVE_SNPRINTF) && defined(HAVE_VSNPRINTF) && defined(HAVE_C99_VSNPRINTF) -/* only include stdio.h if we are not re-defining snprintf or vsnprintf */ -#include - /* make the compiler happy with an empty file */ - void dummy_snprintf(void); - void dummy_snprintf(void) {} -#endif /* HAVE_SNPRINTF, etc */ - -/* yes this really must be a ||. Don't muck with this (tridge) */ -#if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF) - -#ifdef HAVE_LONG_DOUBLE -#define LDOUBLE long double -#else -#define LDOUBLE double -#endif - -#ifdef HAVE_LONG_LONG -#define LLONG long long -#else -#define LLONG long -#endif - -#ifndef VA_COPY -#ifdef HAVE_VA_COPY -#define VA_COPY(dest, src) va_copy(dest, src) -#else -#ifdef HAVE___VA_COPY -#define VA_COPY(dest, src) __va_copy(dest, src) -#else -#define VA_COPY(dest, src) (dest) = (src) -#endif -#endif - -/* - * dopr(): poor man's version of doprintf - */ - -/* format read states */ -#define DP_S_DEFAULT 0 -#define DP_S_FLAGS 1 -#define DP_S_MIN 2 -#define DP_S_DOT 3 -#define DP_S_MAX 4 -#define DP_S_MOD 5 -#define DP_S_CONV 6 -#define DP_S_DONE 7 - -/* format flags - Bits */ -#define DP_F_MINUS (1 << 0) -#define DP_F_PLUS (1 << 1) -#define DP_F_SPACE (1 << 2) -#define DP_F_NUM (1 << 3) -#define DP_F_ZERO (1 << 4) -#define DP_F_UP (1 << 5) -#define DP_F_UNSIGNED (1 << 6) - -/* Conversion Flags */ -#define DP_C_CHAR 1 -#define DP_C_SHORT 2 -#define DP_C_LONG 3 -#define DP_C_LDOUBLE 4 -#define DP_C_LLONG 5 -#define DP_C_SIZET 6 - -/* Chunk types */ -#define CNK_FMT_STR 0 -#define CNK_INT 1 -#define CNK_OCTAL 2 -#define CNK_UINT 3 -#define CNK_HEX 4 -#define CNK_FLOAT 5 -#define CNK_CHAR 6 -#define CNK_STRING 7 -#define CNK_PTR 8 -#define CNK_NUM 9 -#define CNK_PRCNT 10 - -#define char_to_int(p) ((p)- '0') -#ifndef MAX -#define MAX(p,q) (((p) >= (q)) ? (p) : (q)) -#endif - -struct pr_chunk { - int type; /* chunk type */ - int num; /* parameter number */ - int min; - int max; - int flags; - int cflags; - int start; - int len; - LLONG value; - LDOUBLE fvalue; - char *strvalue; - void *pnum; - struct pr_chunk *min_star; - struct pr_chunk *max_star; - struct pr_chunk *next; -}; - -struct pr_chunk_x { - struct pr_chunk **chunks; - int num; -}; - -static int dopr(char *buffer, size_t maxlen, const char *format, - va_list args_in); -static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, - char *value, int flags, int min, int max); -static void fmtint(char *buffer, size_t *currlen, size_t maxlen, - LLONG value, int base, int min, int max, int flags); -static void fmtfp(char *buffer, size_t *currlen, size_t maxlen, - LDOUBLE fvalue, int min, int max, int flags); -static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c); -static struct pr_chunk *new_chunk(void); -static int add_cnk_list_entry(struct pr_chunk_x **list, - int max_num, struct pr_chunk *chunk); - -static int dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) -{ - char ch; - int state; - int pflag; - int pnum; - int pfirst; - size_t currlen; - va_list args; - const char *base; - struct pr_chunk *chunks = NULL; - struct pr_chunk *cnk = NULL; - struct pr_chunk_x *clist = NULL; - int max_pos; - int ret = -1; - - VA_COPY(args, args_in); - - state = DP_S_DEFAULT; - pfirst = 1; - pflag = 0; - pnum = 0; - - max_pos = 0; - base = format; - ch = *format++; - - /* retrieve the string structure as chunks */ - while (state != DP_S_DONE) { - if (ch == '\0') - state = DP_S_DONE; - - switch(state) { - case DP_S_DEFAULT: - - if (cnk) { - cnk->next = new_chunk(); - cnk = cnk->next; - } else { - cnk = new_chunk(); - } - if (!cnk) goto done; - if (!chunks) chunks = cnk; - - if (ch == '%') { - state = DP_S_FLAGS; - ch = *format++; - } else { - cnk->type = CNK_FMT_STR; - cnk->start = format - base -1; - while ((ch != '\0') && (ch != '%')) ch = *format++; - cnk->len = format - base - cnk->start -1; - } - break; - case DP_S_FLAGS: - switch (ch) { - case '-': - cnk->flags |= DP_F_MINUS; - ch = *format++; - break; - case '+': - cnk->flags |= DP_F_PLUS; - ch = *format++; - break; - case ' ': - cnk->flags |= DP_F_SPACE; - ch = *format++; - break; - case '#': - cnk->flags |= DP_F_NUM; - ch = *format++; - break; - case '0': - cnk->flags |= DP_F_ZERO; - ch = *format++; - break; - case 'I': - /* internationalization not supported yet */ - ch = *format++; - break; - default: - state = DP_S_MIN; - break; - } - break; - case DP_S_MIN: - if (isdigit((unsigned char)ch)) { - cnk->min = 10 * cnk->min + char_to_int (ch); - ch = *format++; - } else if (ch == '$') { - if (!pfirst && !pflag) { - /* parameters must be all positioned or none */ - goto done; - } - if (pfirst) { - pfirst = 0; - pflag = 1; - } - if (cnk->min == 0) /* what ?? */ - goto done; - cnk->num = cnk->min; - cnk->min = 0; - ch = *format++; - } else if (ch == '*') { - if (pfirst) pfirst = 0; - cnk->min_star = new_chunk(); - if (!cnk->min_star) /* out of memory :-( */ - goto done; - cnk->min_star->type = CNK_INT; - if (pflag) { - int num; - ch = *format++; - if (!isdigit((unsigned char)ch)) { - /* parameters must be all positioned or none */ - goto done; - } - for (num = 0; isdigit((unsigned char)ch); ch = *format++) { - num = 10 * num + char_to_int(ch); - } - cnk->min_star->num = num; - if (ch != '$') /* what ?? */ - goto done; - } else { - cnk->min_star->num = ++pnum; - } - max_pos = add_cnk_list_entry(&clist, max_pos, cnk->min_star); - if (max_pos == 0) /* out of memory :-( */ - goto done; - ch = *format++; - state = DP_S_DOT; - } else { - if (pfirst) pfirst = 0; - state = DP_S_DOT; - } - break; - case DP_S_DOT: - if (ch == '.') { - state = DP_S_MAX; - ch = *format++; - } else { - state = DP_S_MOD; - } - break; - case DP_S_MAX: - if (isdigit((unsigned char)ch)) { - if (cnk->max < 0) - cnk->max = 0; - cnk->max = 10 * cnk->max + char_to_int (ch); - ch = *format++; - } else if (ch == '$') { - if (!pfirst && !pflag) { - /* parameters must be all positioned or none */ - goto done; - } - if (cnk->max <= 0) /* what ?? */ - goto done; - cnk->num = cnk->max; - cnk->max = -1; - ch = *format++; - } else if (ch == '*') { - cnk->max_star = new_chunk(); - if (!cnk->max_star) /* out of memory :-( */ - goto done; - cnk->max_star->type = CNK_INT; - if (pflag) { - int num; - ch = *format++; - if (!isdigit((unsigned char)ch)) { - /* parameters must be all positioned or none */ - goto done; - } - for (num = 0; isdigit((unsigned char)ch); ch = *format++) { - num = 10 * num + char_to_int(ch); - } - cnk->max_star->num = num; - if (ch != '$') /* what ?? */ - goto done; - } else { - cnk->max_star->num = ++pnum; - } - max_pos = add_cnk_list_entry(&clist, max_pos, cnk->max_star); - if (max_pos == 0) /* out of memory :-( */ - goto done; - - ch = *format++; - state = DP_S_MOD; - } else { - state = DP_S_MOD; - } - break; - case DP_S_MOD: - switch (ch) { - case 'h': - cnk->cflags = DP_C_SHORT; - ch = *format++; - if (ch == 'h') { - cnk->cflags = DP_C_CHAR; - ch = *format++; - } - break; - case 'l': - cnk->cflags = DP_C_LONG; - ch = *format++; - if (ch == 'l') { /* It's a long long */ - cnk->cflags = DP_C_LLONG; - ch = *format++; - } - break; - case 'L': - cnk->cflags = DP_C_LDOUBLE; - ch = *format++; - break; - case 'z': - cnk->cflags = DP_C_SIZET; - ch = *format++; - break; - default: - break; - } - state = DP_S_CONV; - break; - case DP_S_CONV: - if (cnk->num == 0) cnk->num = ++pnum; - max_pos = add_cnk_list_entry(&clist, max_pos, cnk); - if (max_pos == 0) /* out of memory :-( */ - goto done; - - switch (ch) { - case 'd': - case 'i': - cnk->type = CNK_INT; - break; - case 'o': - cnk->type = CNK_OCTAL; - cnk->flags |= DP_F_UNSIGNED; - break; - case 'u': - cnk->type = CNK_UINT; - cnk->flags |= DP_F_UNSIGNED; - break; - case 'X': - cnk->flags |= DP_F_UP; - case 'x': - cnk->type = CNK_HEX; - cnk->flags |= DP_F_UNSIGNED; - break; - case 'A': - /* hex float not supported yet */ - case 'E': - case 'G': - case 'F': - cnk->flags |= DP_F_UP; - case 'a': - /* hex float not supported yet */ - case 'e': - case 'f': - case 'g': - cnk->type = CNK_FLOAT; - break; - case 'c': - cnk->type = CNK_CHAR; - break; - case 's': - cnk->type = CNK_STRING; - break; - case 'p': - cnk->type = CNK_PTR; - cnk->flags |= DP_F_UNSIGNED; - break; - case 'n': - cnk->type = CNK_NUM; - break; - case '%': - cnk->type = CNK_PRCNT; - break; - default: - /* Unknown, bail out*/ - goto done; - } - ch = *format++; - state = DP_S_DEFAULT; - break; - case DP_S_DONE: - break; - default: - /* hmm? */ - break; /* some picky compilers need this */ - } - } - - /* retrieve the format arguments */ - for (pnum = 0; pnum < max_pos; pnum++) { - int i; - - if (clist[pnum].num == 0) { - /* ignoring a parameter should not be permitted - * all parameters must be matched at least once - * BUT seem some system ignore this rule ... - * at least my glibc based system does --SSS - */ -#ifdef DEBUG_SNPRINTF - printf("parameter at position %d not used\n", pnum+1); -#endif - /* eat the parameter */ - va_arg (args, int); - continue; - } - for (i = 1; i < clist[pnum].num; i++) { - if (clist[pnum].chunks[0]->type != clist[pnum].chunks[i]->type) { - /* nooo noo no! - * all the references to a parameter - * must be of the same type - */ - goto done; - } - } - cnk = clist[pnum].chunks[0]; - switch (cnk->type) { - case CNK_INT: - if (cnk->cflags == DP_C_SHORT) - cnk->value = va_arg (args, int); - else if (cnk->cflags == DP_C_LONG) - cnk->value = va_arg (args, long int); - else if (cnk->cflags == DP_C_LLONG) - cnk->value = va_arg (args, LLONG); - else if (cnk->cflags == DP_C_SIZET) - cnk->value = va_arg (args, ssize_t); - else - cnk->value = va_arg (args, int); - - for (i = 1; i < clist[pnum].num; i++) { - clist[pnum].chunks[i]->value = cnk->value; - } - break; - - case CNK_OCTAL: - case CNK_UINT: - case CNK_HEX: - if (cnk->cflags == DP_C_SHORT) - cnk->value = va_arg (args, unsigned int); - else if (cnk->cflags == DP_C_LONG) - cnk->value = (unsigned long int)va_arg (args, unsigned long int); - else if (cnk->cflags == DP_C_LLONG) - cnk->value = (LLONG)va_arg (args, unsigned LLONG); - else if (cnk->cflags == DP_C_SIZET) - cnk->value = (size_t)va_arg (args, size_t); - else - cnk->value = (unsigned int)va_arg (args, unsigned int); - - for (i = 1; i < clist[pnum].num; i++) { - clist[pnum].chunks[i]->value = cnk->value; - } - break; - - case CNK_FLOAT: - if (cnk->cflags == DP_C_LDOUBLE) - cnk->fvalue = va_arg (args, LDOUBLE); - else - cnk->fvalue = va_arg (args, double); - - for (i = 1; i < clist[pnum].num; i++) { - clist[pnum].chunks[i]->fvalue = cnk->fvalue; - } - break; - - case CNK_CHAR: - cnk->value = va_arg (args, int); - - for (i = 1; i < clist[pnum].num; i++) { - clist[pnum].chunks[i]->value = cnk->value; - } - break; - - case CNK_STRING: - cnk->strvalue = va_arg (args, char *); - if (!cnk->strvalue) cnk->strvalue = "(NULL)"; - - for (i = 1; i < clist[pnum].num; i++) { - clist[pnum].chunks[i]->strvalue = cnk->strvalue; - } - break; - - case CNK_PTR: - cnk->strvalue = va_arg (args, void *); - for (i = 1; i < clist[pnum].num; i++) { - clist[pnum].chunks[i]->strvalue = cnk->strvalue; - } - break; - - case CNK_NUM: - if (cnk->cflags == DP_C_CHAR) - cnk->pnum = va_arg (args, char *); - else if (cnk->cflags == DP_C_SHORT) - cnk->pnum = va_arg (args, short int *); - else if (cnk->cflags == DP_C_LONG) - cnk->pnum = va_arg (args, long int *); - else if (cnk->cflags == DP_C_LLONG) - cnk->pnum = va_arg (args, LLONG *); - else if (cnk->cflags == DP_C_SIZET) - cnk->pnum = va_arg (args, ssize_t *); - else - cnk->pnum = va_arg (args, int *); - - for (i = 1; i < clist[pnum].num; i++) { - clist[pnum].chunks[i]->pnum = cnk->pnum; - } - break; - - case CNK_PRCNT: - break; - - default: - /* what ?? */ - goto done; - } - } - /* print out the actual string from chunks */ - currlen = 0; - cnk = chunks; - while (cnk) { - int len, min, max; - - if (cnk->min_star) min = cnk->min_star->value; - else min = cnk->min; - if (cnk->max_star) max = cnk->max_star->value; - else max = cnk->max; - - switch (cnk->type) { - - case CNK_FMT_STR: - if (maxlen != 0 && maxlen > currlen) { - if (maxlen > (currlen + cnk->len)) len = cnk->len; - else len = maxlen - currlen; - - memcpy(&(buffer[currlen]), &(base[cnk->start]), len); - } - currlen += cnk->len; - - break; - - case CNK_INT: - case CNK_UINT: - fmtint (buffer, &currlen, maxlen, cnk->value, 10, min, max, cnk->flags); - break; - - case CNK_OCTAL: - fmtint (buffer, &currlen, maxlen, cnk->value, 8, min, max, cnk->flags); - break; - - case CNK_HEX: - fmtint (buffer, &currlen, maxlen, cnk->value, 16, min, max, cnk->flags); - break; - - case CNK_FLOAT: - fmtfp (buffer, &currlen, maxlen, cnk->fvalue, min, max, cnk->flags); - break; - - case CNK_CHAR: - dopr_outch (buffer, &currlen, maxlen, cnk->value); - break; - - case CNK_STRING: - if (max == -1) { - max = strlen(cnk->strvalue); - } - fmtstr (buffer, &currlen, maxlen, cnk->strvalue, cnk->flags, min, max); - break; - - case CNK_PTR: - fmtint (buffer, &currlen, maxlen, (long)(cnk->strvalue), 16, min, max, cnk->flags); - break; - - case CNK_NUM: - if (cnk->cflags == DP_C_CHAR) - *((char *)(cnk->pnum)) = (char)currlen; - else if (cnk->cflags == DP_C_SHORT) - *((short int *)(cnk->pnum)) = (short int)currlen; - else if (cnk->cflags == DP_C_LONG) - *((long int *)(cnk->pnum)) = (long int)currlen; - else if (cnk->cflags == DP_C_LLONG) - *((LLONG *)(cnk->pnum)) = (LLONG)currlen; - else if (cnk->cflags == DP_C_SIZET) - *((ssize_t *)(cnk->pnum)) = (ssize_t)currlen; - else - *((int *)(cnk->pnum)) = (int)currlen; - break; - - case CNK_PRCNT: - dopr_outch (buffer, &currlen, maxlen, '%'); - break; - - default: - /* what ?? */ - goto done; - } - cnk = cnk->next; - } - if (maxlen != 0) { - if (currlen < maxlen - 1) - buffer[currlen] = '\0'; - else if (maxlen > 0) - buffer[maxlen - 1] = '\0'; - } - ret = currlen; - -done: - va_end(args); - - while (chunks) { - cnk = chunks->next; - free(chunks); - chunks = cnk; - } - if (clist) { - for (pnum = 0; pnum < max_pos; pnum++) { - if (clist[pnum].chunks) free(clist[pnum].chunks); - } - free(clist); - } - return ret; -} - -static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, - char *value, int flags, int min, int max) -{ - int padlen, strln; /* amount to pad */ - int cnt = 0; - -#ifdef DEBUG_SNPRINTF - printf("fmtstr min=%d max=%d s=[%s]\n", min, max, value); -#endif - if (value == 0) { - value = ""; - } - - for (strln = 0; strln < max && value[strln]; ++strln); /* strlen */ - padlen = min - strln; - if (padlen < 0) - padlen = 0; - if (flags & DP_F_MINUS) - padlen = -padlen; /* Left Justify */ - - while (padlen > 0) { - dopr_outch (buffer, currlen, maxlen, ' '); - --padlen; - } - while (*value && (cnt < max)) { - dopr_outch (buffer, currlen, maxlen, *value++); - ++cnt; - } - while (padlen < 0) { - dopr_outch (buffer, currlen, maxlen, ' '); - ++padlen; - } -} - -/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */ - -static void fmtint(char *buffer, size_t *currlen, size_t maxlen, - LLONG value, int base, int min, int max, int flags) -{ - int signvalue = 0; - unsigned LLONG uvalue; - char convert[20]; - int place = 0; - int spadlen = 0; /* amount to space pad */ - int zpadlen = 0; /* amount to zero pad */ - int caps = 0; - - if (max < 0) - max = 0; - - uvalue = value; - - if(!(flags & DP_F_UNSIGNED)) { - if( value < 0 ) { - signvalue = '-'; - uvalue = -value; - } else { - if (flags & DP_F_PLUS) /* Do a sign (+/i) */ - signvalue = '+'; - else if (flags & DP_F_SPACE) - signvalue = ' '; - } - } - - if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */ - - do { - convert[place++] = - (caps? "0123456789ABCDEF":"0123456789abcdef") - [uvalue % (unsigned)base ]; - uvalue = (uvalue / (unsigned)base ); - } while(uvalue && (place < 20)); - if (place == 20) place--; - convert[place] = 0; - - zpadlen = max - place; - spadlen = min - MAX (max, place) - (signvalue ? 1 : 0); - if (zpadlen < 0) zpadlen = 0; - if (spadlen < 0) spadlen = 0; - if (flags & DP_F_ZERO) { - zpadlen = MAX(zpadlen, spadlen); - spadlen = 0; - } - if (flags & DP_F_MINUS) - spadlen = -spadlen; /* Left Justifty */ - -#ifdef DEBUG_SNPRINTF - printf("zpad: %d, spad: %d, min: %d, max: %d, place: %d\n", - zpadlen, spadlen, min, max, place); -#endif - - /* Spaces */ - while (spadlen > 0) { - dopr_outch (buffer, currlen, maxlen, ' '); - --spadlen; - } - - /* Sign */ - if (signvalue) - dopr_outch (buffer, currlen, maxlen, signvalue); - - /* Zeros */ - if (zpadlen > 0) { - while (zpadlen > 0) { - dopr_outch (buffer, currlen, maxlen, '0'); - --zpadlen; - } - } - - /* Digits */ - while (place > 0) - dopr_outch (buffer, currlen, maxlen, convert[--place]); - - /* Left Justified spaces */ - while (spadlen < 0) { - dopr_outch (buffer, currlen, maxlen, ' '); - ++spadlen; - } -} - -static LDOUBLE abs_val(LDOUBLE value) -{ - LDOUBLE result = value; - - if (value < 0) - result = -value; - - return result; -} - -static LDOUBLE POW10(int exp) -{ - LDOUBLE result = 1; - - while (exp) { - result *= 10; - exp--; - } - - return result; -} - -static LLONG ROUND(LDOUBLE value) -{ - LLONG intpart; - - intpart = (LLONG)value; - value = value - intpart; - if (value >= 0.5) intpart++; - - return intpart; -} - -/* a replacement for modf that doesn't need the math library. Should - be portable, but slow */ -static double my_modf(double x0, double *iptr) -{ - int i; - LLONG l=0; - double x = x0; - double f = 1.0; - - for (i=0;i<100;i++) { - l = (long)x; - if (l <= (x+1) && l >= (x-1)) break; - x *= 0.1; - f *= 10.0; - } - - if (i == 100) { - /* yikes! the number is beyond what we can handle. What do we do? */ - (*iptr) = 0; - return 0; - } - - if (i != 0) { - double i2; - double ret; - - ret = my_modf(x0-l*f, &i2); - (*iptr) = l*f + i2; - return ret; - } - - (*iptr) = l; - return x - (*iptr); -} - - -static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, - LDOUBLE fvalue, int min, int max, int flags) -{ - int signvalue = 0; - double ufvalue; - char iconvert[311]; - char fconvert[311]; - int iplace = 0; - int fplace = 0; - int padlen = 0; /* amount to pad */ - int zpadlen = 0; - int caps = 0; - int idx; - double intpart; - double fracpart; - double temp; - - /* - * AIX manpage says the default is 0, but Solaris says the default - * is 6, and sprintf on AIX defaults to 6 - */ - if (max < 0) - max = 6; - - ufvalue = abs_val (fvalue); - - if (fvalue < 0) { - signvalue = '-'; - } else { - if (flags & DP_F_PLUS) { /* Do a sign (+/i) */ - signvalue = '+'; - } else { - if (flags & DP_F_SPACE) - signvalue = ' '; - } - } - -#if 0 - if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */ -#endif - -#if 0 - if (max == 0) ufvalue += 0.5; /* if max = 0 we must round */ -#endif - - /* - * Sorry, we only support 9 digits past the decimal because of our - * conversion method - */ - if (max > 9) - max = 9; - - /* We "cheat" by converting the fractional part to integer by - * multiplying by a factor of 10 - */ - - temp = ufvalue; - my_modf(temp, &intpart); - - fracpart = ROUND((POW10(max)) * (ufvalue - intpart)); - - if (fracpart >= POW10(max)) { - intpart++; - fracpart -= POW10(max); - } - - - /* Convert integer part */ - do { - temp = intpart*0.1; - my_modf(temp, &intpart); - idx = (int) ((temp -intpart +0.05)* 10.0); - /* idx = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */ - /* printf ("%llf, %f, %x\n", temp, intpart, idx); */ - iconvert[iplace++] = - (caps? "0123456789ABCDEF":"0123456789abcdef")[idx]; - } while (intpart && (iplace < 311)); - if (iplace == 311) iplace--; - iconvert[iplace] = 0; - - /* Convert fractional part */ - if (fracpart) - { - do { - temp = fracpart*0.1; - my_modf(temp, &fracpart); - idx = (int) ((temp -fracpart +0.05)* 10.0); - /* idx = (int) ((((temp/10) -fracpart) +0.05) *10); */ - /* printf ("%lf, %lf, %ld\n", temp, fracpart, idx ); */ - fconvert[fplace++] = - (caps? "0123456789ABCDEF":"0123456789abcdef")[idx]; - } while(fracpart && (fplace < 311)); - if (fplace == 311) fplace--; - } - fconvert[fplace] = 0; - - /* -1 for decimal point, another -1 if we are printing a sign */ - padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); - zpadlen = max - fplace; - if (zpadlen < 0) zpadlen = 0; - if (padlen < 0) - padlen = 0; - if (flags & DP_F_MINUS) - padlen = -padlen; /* Left Justifty */ - - if ((flags & DP_F_ZERO) && (padlen > 0)) { - if (signvalue) { - dopr_outch (buffer, currlen, maxlen, signvalue); - --padlen; - signvalue = 0; - } - while (padlen > 0) { - dopr_outch (buffer, currlen, maxlen, '0'); - --padlen; - } - } - while (padlen > 0) { - dopr_outch (buffer, currlen, maxlen, ' '); - --padlen; - } - if (signvalue) - dopr_outch (buffer, currlen, maxlen, signvalue); - - while (iplace > 0) - dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]); - -#ifdef DEBUG_SNPRINTF - printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen); -#endif - - /* - * Decimal point. This should probably use locale to find the correct - * char to print out. - */ - if (max > 0) { - dopr_outch (buffer, currlen, maxlen, '.'); - - while (zpadlen > 0) { - dopr_outch (buffer, currlen, maxlen, '0'); - --zpadlen; - } - - while (fplace > 0) - dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]); - } - - while (padlen < 0) { - dopr_outch (buffer, currlen, maxlen, ' '); - ++padlen; - } -} - -static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) -{ - if (*currlen < maxlen) { - buffer[(*currlen)] = c; - } - (*currlen)++; -} - -static struct pr_chunk *new_chunk(void) { - struct pr_chunk *new_c = (struct pr_chunk *)malloc(sizeof(struct pr_chunk)); - - if (!new_c) - return NULL; - - new_c->type = 0; - new_c->num = 0; - new_c->min = 0; - new_c->min_star = NULL; - new_c->max = -1; - new_c->max_star = NULL; - new_c->flags = 0; - new_c->cflags = 0; - new_c->start = 0; - new_c->len = 0; - new_c->value = 0; - new_c->fvalue = 0; - new_c->strvalue = NULL; - new_c->pnum = NULL; - new_c->next = NULL; - - return new_c; -} - -static int add_cnk_list_entry(struct pr_chunk_x **list, - int max_num, struct pr_chunk *chunk) { - struct pr_chunk_x *l; - struct pr_chunk **c; - int max; - int cnum; - int i, pos; - - if (chunk->num > max_num) { - max = chunk->num; - - if (*list == NULL) { - l = (struct pr_chunk_x *)malloc(sizeof(struct pr_chunk_x) * max); - pos = 0; - } else { - l = (struct pr_chunk_x *)realloc(*list, sizeof(struct pr_chunk_x) * max); - pos = max_num; - } - if (l == NULL) { - for (i = 0; i < max; i++) { - if ((*list)[i].chunks) free((*list)[i].chunks); - } - return 0; - } - for (i = pos; i < max; i++) { - l[i].chunks = NULL; - l[i].num = 0; - } - } else { - l = *list; - max = max_num; - } - - i = chunk->num - 1; - cnum = l[i].num + 1; - if (l[i].chunks == NULL) { - c = (struct pr_chunk **)malloc(sizeof(struct pr_chunk *) * cnum); - } else { - c = (struct pr_chunk **)realloc(l[i].chunks, sizeof(struct pr_chunk *) * cnum); - } - if (c == NULL) { - for (i = 0; i < max; i++) { - if (l[i].chunks) free(l[i].chunks); - } - return 0; - } - c[l[i].num] = chunk; - l[i].chunks = c; - l[i].num = cnum; - - *list = l; - return max; -} - - int vsnprintf (char *str, size_t count, const char *fmt, va_list args) -{ - return dopr(str, count, fmt, args); -} -#endif - -/* yes this really must be a ||. Don't muck with this (tridge) - * - * The logic for these two is that we need our own definition if the - * OS *either* has no definition of *sprintf, or if it does have one - * that doesn't work properly according to the autoconf test. - */ -#if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF) - int snprintf(char *str,size_t count,const char *fmt,...) -{ - size_t ret; - va_list ap; - - va_start(ap, fmt); - ret = vsnprintf(str, count, fmt, ap); - va_end(ap); - return ret; -} -#endif - -#ifndef HAVE_C99_VSNPRINTF - int printf(const char *fmt, ...) -{ - va_list ap; - int ret; - char *s; - - s = NULL; - va_start(ap, fmt); - ret = vasprintf(&s, fmt, ap); - va_end(ap); - - if (s) { - fwrite(s, 1, strlen(s), stdout); - } - free(s); - - return ret; -} -#endif - -#ifndef HAVE_C99_VSNPRINTF - int fprintf(FILE *stream, const char *fmt, ...) -{ - va_list ap; - int ret; - char *s; - - s = NULL; - va_start(ap, fmt); - ret = vasprintf(&s, fmt, ap); - va_end(ap); - - if (s) { - fwrite(s, 1, strlen(s), stream); - } - free(s); - - return ret; -} -#endif - -#endif - -#ifndef HAVE_VASPRINTF - int vasprintf(char **ptr, const char *format, va_list ap) -{ - int ret; - va_list ap2; - - VA_COPY(ap2, ap); - ret = vsnprintf(NULL, 0, format, ap2); - va_end(ap2); - if (ret < 0) return ret; - - (*ptr) = (char *)malloc(ret+1); - if (!*ptr) return -1; - - VA_COPY(ap2, ap); - ret = vsnprintf(*ptr, ret+1, format, ap2); - va_end(ap2); - - return ret; -} -#endif - - -#ifndef HAVE_ASPRINTF - int asprintf(char **ptr, const char *format, ...) -{ - va_list ap; - int ret; - - *ptr = NULL; - va_start(ap, format); - ret = vasprintf(ptr, format, ap); - va_end(ap); - - return ret; -} -#endif - -#ifdef TEST_SNPRINTF - - int sprintf(char *str,const char *fmt,...); - int printf(const char *fmt,...); - - int main (void) -{ - char buf1[1024]; - char buf2[1024]; - char *buf3; - char *fp_fmt[] = { - "%1.1f", - "%-1.5f", - "%1.5f", - "%123.9f", - "%10.5f", - "% 10.5f", - "%+22.9f", - "%+4.9f", - "%01.3f", - "%4f", - "%3.1f", - "%3.2f", - "%.0f", - "%f", - "%-8.8f", - "%-9.9f", - NULL - }; - double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 203.9, 0.96, 0.996, - 0.9996, 1.996, 4.136, 5.030201, 0.00205, - /* END LIST */ 0}; - char *int_fmt[] = { - "%-1.5d", - "%1.5d", - "%123.9d", - "%5.5d", - "%10.5d", - "% 10.5d", - "%+22.33d", - "%01.3d", - "%4d", - "%d", - NULL - }; - long int_nums[] = { -1, 134, 91340, 341, 0203, 1234567890, 0}; - char *str_fmt[] = { - "%10.5s", - "%-10.5s", - "%5.10s", - "%-5.10s", - "%10.1s", - "%0.10s", - "%10.0s", - "%1.10s", - "%s", - "%.1s", - "%.10s", - "%10s", - NULL - }; - char *str_vals[] = {"hello", "a", "", "a longer string", NULL}; -#ifdef HAVE_LONG_LONG - char *ll_fmt[] = { - "%llu", - NULL - }; - LLONG ll_nums[] = { 134, 91340, 341, 0203, 1234567890, 128006186140000000LL, 0}; -#endif - int x, y; - int fail = 0; - int num = 0; - int l1, l2; - char *ss_fmt[] = { - "%zd", - "%zu", - NULL - }; - size_t ss_nums[] = {134, 91340, 123456789, 0203, 1234567890, 0}; - - printf ("Testing snprintf format codes against system sprintf...\n"); - - for (x = 0; fp_fmt[x] ; x++) { - for (y = 0; fp_nums[y] != 0 ; y++) { - buf1[0] = buf2[0] = '\0'; - l1 = snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]); - l2 = sprintf (buf2, fp_fmt[x], fp_nums[y]); - buf1[1023] = buf2[1023] = '\0'; - if (strcmp (buf1, buf2) || (l1 != l2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n", - fp_fmt[x], l1, buf1, l2, buf2); - fail++; - } - num++; - } - } - - for (x = 0; int_fmt[x] ; x++) { - for (y = 0; int_nums[y] != 0 ; y++) { - buf1[0] = buf2[0] = '\0'; - l1 = snprintf(buf1, sizeof(buf1), int_fmt[x], int_nums[y]); - l2 = sprintf (buf2, int_fmt[x], int_nums[y]); - buf1[1023] = buf2[1023] = '\0'; - if (strcmp (buf1, buf2) || (l1 != l2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n", - int_fmt[x], l1, buf1, l2, buf2); - fail++; - } - num++; - } - } - - for (x = 0; str_fmt[x] ; x++) { - for (y = 0; str_vals[y] != 0 ; y++) { - buf1[0] = buf2[0] = '\0'; - l1 = snprintf(buf1, sizeof(buf1), str_fmt[x], str_vals[y]); - l2 = sprintf (buf2, str_fmt[x], str_vals[y]); - buf1[1023] = buf2[1023] = '\0'; - if (strcmp (buf1, buf2) || (l1 != l2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n", - str_fmt[x], l1, buf1, l2, buf2); - fail++; - } - num++; - } - } - -#ifdef HAVE_LONG_LONG - for (x = 0; ll_fmt[x] ; x++) { - for (y = 0; ll_nums[y] != 0 ; y++) { - buf1[0] = buf2[0] = '\0'; - l1 = snprintf(buf1, sizeof(buf1), ll_fmt[x], ll_nums[y]); - l2 = sprintf (buf2, ll_fmt[x], ll_nums[y]); - buf1[1023] = buf2[1023] = '\0'; - if (strcmp (buf1, buf2) || (l1 != l2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n", - ll_fmt[x], l1, buf1, l2, buf2); - fail++; - } - num++; - } - } -#endif - -#define BUFSZ 2048 - - buf1[0] = buf2[0] = '\0'; - if ((buf3 = malloc(BUFSZ)) == NULL) { - fail++; - } else { - num++; - memset(buf3, 'a', BUFSZ); - snprintf(buf1, sizeof(buf1), "%.*s", 1, buf3); - buf1[1023] = '\0'; - if (strcmp(buf1, "a") != 0) { - printf("length limit buf1 '%s' expected 'a'\n", buf1); - fail++; - } - } - - buf1[0] = buf2[0] = '\0'; - l1 = snprintf(buf1, sizeof(buf1), "%4$*1$d %2$s %3$*1$.*1$f", 3, "pos test", 12.3456, 9); - l2 = sprintf(buf2, "%4$*1$d %2$s %3$*1$.*1$f", 3, "pos test", 12.3456, 9); - buf1[1023] = buf2[1023] = '\0'; - if (strcmp(buf1, buf2) || (l1 != l2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n", - "%4$*1$d %2$s %3$*1$.*1$f", l1, buf1, l2, buf2); - fail++; - } - - buf1[0] = buf2[0] = '\0'; - l1 = snprintf(buf1, sizeof(buf1), "%4$*4$d %2$s %3$*4$.*4$f", 3, "pos test", 12.3456, 9); - l2 = sprintf(buf2, "%4$*4$d %2$s %3$*4$.*4$f", 3, "pos test", 12.3456, 9); - buf1[1023] = buf2[1023] = '\0'; - if (strcmp(buf1, buf2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n", - "%4$*1$d %2$s %3$*1$.*1$f", l1, buf1, l2, buf2); - fail++; - } - - for (x = 0; ss_fmt[x] ; x++) { - for (y = 0; ss_nums[y] != 0 ; y++) { - buf1[0] = buf2[0] = '\0'; - l1 = snprintf(buf1, sizeof(buf1), ss_fmt[x], ss_nums[y]); - l2 = sprintf (buf2, ss_fmt[x], ss_nums[y]); - buf1[1023] = buf2[1023] = '\0'; - if (strcmp (buf1, buf2) || (l1 != l2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n", - ss_fmt[x], l1, buf1, l2, buf2); - fail++; - } - num++; - } - } -#if 0 - buf1[0] = buf2[0] = '\0'; - l1 = snprintf(buf1, sizeof(buf1), "%lld", (LLONG)1234567890); - l2 = sprintf(buf2, "%lld", (LLONG)1234567890); - buf1[1023] = buf2[1023] = '\0'; - if (strcmp(buf1, buf2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n", - "%lld", l1, buf1, l2, buf2); - fail++; - } - - buf1[0] = buf2[0] = '\0'; - l1 = snprintf(buf1, sizeof(buf1), "%Lf", (LDOUBLE)890.1234567890123); - l2 = sprintf(buf2, "%Lf", (LDOUBLE)890.1234567890123); - buf1[1023] = buf2[1023] = '\0'; - if (strcmp(buf1, buf2)) { - printf("snprintf doesn't match Format: %s\n\tsnprintf(%d) = [%s]\n\t sprintf(%d) = [%s]\n", - "%Lf", l1, buf1, l2, buf2); - fail++; - } -#endif - printf ("%d tests failed out of %d.\n", fail, num); - - printf("seeing how many digits we support\n"); - { - double v0 = 0.12345678901234567890123456789012345678901; - for (x=0; x<100; x++) { - double p = pow(10, x); - double r = v0*p; - snprintf(buf1, sizeof(buf1), "%1.1f", r); - sprintf(buf2, "%1.1f", r); - if (strcmp(buf1, buf2)) { - printf("we seem to support %d digits\n", x-1); - break; - } - } - } - - return 0; -} -#endif /* TEST_SNPRINTF */ diff --git a/bundled/replace/socket.c b/bundled/replace/socket.c deleted file mode 100644 index 35e975fc..00000000 --- a/bundled/replace/socket.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * - * Dummy replacements for socket functions. - * - * Copyright (C) Michael Adam 2008 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "replace.h" -#include "system/network.h" - -int rep_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) -{ - errno = ENOSYS; - return -1; -} - -struct hostent *rep_gethostbyname(const char *name) -{ - errno = ENOSYS; - return NULL; -} diff --git a/bundled/replace/socketpair.c b/bundled/replace/socketpair.c deleted file mode 100644 index c7757309..00000000 --- a/bundled/replace/socketpair.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * replacement routines for broken systems - * Copyright (C) Jelmer Vernooij 2006 - * Copyright (C) Michael Adam 2008 - * - * ** NOTE! The following LGPL license applies to the replace - * ** library. This does NOT imply that all of Samba is released - * ** under the LGPL - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, see . - */ - -#include "replace.h" -#include "system/network.h" - -int rep_socketpair(int d, int type, int protocol, int sv[2]) -{ - if (d != AF_UNIX) { - errno = EAFNOSUPPORT; - return -1; - } - - if (protocol != 0) { - errno = EPROTONOSUPPORT; - return -1; - } - - if (type != SOCK_STREAM) { - errno = EOPNOTSUPP; - return -1; - } - - return pipe(sv); -} diff --git a/bundled/replace/strptime.c b/bundled/replace/strptime.c deleted file mode 100644 index 0e40f756..00000000 --- a/bundled/replace/strptime.c +++ /dev/null @@ -1,990 +0,0 @@ -/* Convert a string representation of time to a time value. - Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 3 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - see . */ - -/* XXX This version of the implementation is not really complete. - Some of the fields cannot add information alone. But if seeing - some of them in the same format (such as year, week and weekday) - this is enough information for determining the date. */ - -#include "replace.h" -#include "system/locale.h" -#include "system/time.h" - -#ifndef __P -# if defined (__GNUC__) || (defined (__STDC__) && __STDC__) -# define __P(args) args -# else -# define __P(args) () -# endif /* GCC. */ -#endif /* Not __P. */ - -#if ! HAVE_LOCALTIME_R && ! defined localtime_r -# ifdef _LIBC -# define localtime_r __localtime_r -# else -/* Approximate localtime_r as best we can in its absence. */ -# define localtime_r my_localtime_r -static struct tm *localtime_r __P ((const time_t *, struct tm *)); -static struct tm * -localtime_r (t, tp) - const time_t *t; - struct tm *tp; -{ - struct tm *l = localtime (t); - if (! l) - return 0; - *tp = *l; - return tp; -} -# endif /* ! _LIBC */ -#endif /* ! HAVE_LOCALTIME_R && ! defined (localtime_r) */ - - -#define match_char(ch1, ch2) if (ch1 != ch2) return NULL -#if defined __GNUC__ && __GNUC__ >= 2 -# define match_string(cs1, s2) \ - ({ size_t len = strlen (cs1); \ - int result = strncasecmp ((cs1), (s2), len) == 0; \ - if (result) (s2) += len; \ - result; }) -#else -/* Oh come on. Get a reasonable compiler. */ -# define match_string(cs1, s2) \ - (strncasecmp ((cs1), (s2), strlen (cs1)) ? 0 : ((s2) += strlen (cs1), 1)) -#endif -/* We intentionally do not use isdigit() for testing because this will - lead to problems with the wide character version. */ -#define get_number(from, to, n) \ - do { \ - int __n = n; \ - val = 0; \ - while (*rp == ' ') \ - ++rp; \ - if (*rp < '0' || *rp > '9') \ - return NULL; \ - do { \ - val *= 10; \ - val += *rp++ - '0'; \ - } while (--__n > 0 && val * 10 <= to && *rp >= '0' && *rp <= '9'); \ - if (val < from || val > to) \ - return NULL; \ - } while (0) -#ifdef _NL_CURRENT -# define get_alt_number(from, to, n) \ - ({ \ - __label__ do_normal; \ - if (*decided != raw) \ - { \ - const char *alts = _NL_CURRENT (LC_TIME, ALT_DIGITS); \ - int __n = n; \ - int any = 0; \ - while (*rp == ' ') \ - ++rp; \ - val = 0; \ - do { \ - val *= 10; \ - while (*alts != '\0') \ - { \ - size_t len = strlen (alts); \ - if (strncasecmp (alts, rp, len) == 0) \ - break; \ - alts += len + 1; \ - ++val; \ - } \ - if (*alts == '\0') \ - { \ - if (*decided == not && ! any) \ - goto do_normal; \ - /* If we haven't read anything it's an error. */ \ - if (! any) \ - return NULL; \ - /* Correct the premature multiplication. */ \ - val /= 10; \ - break; \ - } \ - else \ - *decided = loc; \ - } while (--__n > 0 && val * 10 <= to); \ - if (val < from || val > to) \ - return NULL; \ - } \ - else \ - { \ - do_normal: \ - get_number (from, to, n); \ - } \ - 0; \ - }) -#else -# define get_alt_number(from, to, n) \ - /* We don't have the alternate representation. */ \ - get_number(from, to, n) -#endif -#define recursive(new_fmt) \ - (*(new_fmt) != '\0' \ - && (rp = strptime_internal (rp, (new_fmt), tm, decided, era_cnt)) != NULL) - - -#ifdef _LIBC -/* This is defined in locale/C-time.c in the GNU libc. */ -extern const struct locale_data _nl_C_LC_TIME; -extern const unsigned short int __mon_yday[2][13]; - -# define weekday_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (DAY_1)].string) -# define ab_weekday_name \ - (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABDAY_1)].string) -# define month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (MON_1)].string) -# define ab_month_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABMON_1)].string) -# define HERE_D_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_T_FMT)].string) -# define HERE_D_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (D_FMT)].string) -# define HERE_AM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (AM_STR)].string) -# define HERE_PM_STR (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (PM_STR)].string) -# define HERE_T_FMT_AMPM \ - (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (T_FMT_AMPM)].string) -# define HERE_T_FMT (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (T_FMT)].string) - -# define strncasecmp(s1, s2, n) __strncasecmp (s1, s2, n) -#else -static char const weekday_name[][10] = - { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday" - }; -static char const ab_weekday_name[][4] = - { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" - }; -static char const month_name[][10] = - { - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" - }; -static char const ab_month_name[][4] = - { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }; -# define HERE_D_T_FMT "%a %b %e %H:%M:%S %Y" -# define HERE_D_FMT "%m/%d/%y" -# define HERE_AM_STR "AM" -# define HERE_PM_STR "PM" -# define HERE_T_FMT_AMPM "%I:%M:%S %p" -# define HERE_T_FMT "%H:%M:%S" - -static const unsigned short int __mon_yday[2][13] = - { - /* Normal years. */ - { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, - /* Leap years. */ - { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } - }; -#endif - -/* Status of lookup: do we use the locale data or the raw data? */ -enum locale_status { not, loc, raw }; - - -#ifndef __isleap -/* Nonzero if YEAR is a leap year (every 4 years, - except every 100th isn't, and every 400th is). */ -# define __isleap(year) \ - ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) -#endif - -/* Compute the day of the week. */ -static void -day_of_the_week (struct tm *tm) -{ - /* We know that January 1st 1970 was a Thursday (= 4). Compute the - the difference between this data in the one on TM and so determine - the weekday. */ - int corr_year = 1900 + tm->tm_year - (tm->tm_mon < 2); - int wday = (-473 - + (365 * (tm->tm_year - 70)) - + (corr_year / 4) - - ((corr_year / 4) / 25) + ((corr_year / 4) % 25 < 0) - + (((corr_year / 4) / 25) / 4) - + __mon_yday[0][tm->tm_mon] - + tm->tm_mday - 1); - tm->tm_wday = ((wday % 7) + 7) % 7; -} - -/* Compute the day of the year. */ -static void -day_of_the_year (struct tm *tm) -{ - tm->tm_yday = (__mon_yday[__isleap (1900 + tm->tm_year)][tm->tm_mon] - + (tm->tm_mday - 1)); -} - -static char * -#ifdef _LIBC -internal_function -#endif -strptime_internal __P ((const char *rp, const char *fmt, struct tm *tm, - enum locale_status *decided, int era_cnt)); - -static char * -#ifdef _LIBC -internal_function -#endif -strptime_internal (rp, fmt, tm, decided, era_cnt) - const char *rp; - const char *fmt; - struct tm *tm; - enum locale_status *decided; - int era_cnt; -{ - const char *rp_backup; - int cnt; - size_t val; - int have_I, is_pm; - int century, want_century; - int want_era; - int have_wday, want_xday; - int have_yday; - int have_mon, have_mday; -#ifdef _NL_CURRENT - size_t num_eras; -#endif - struct era_entry *era; - - have_I = is_pm = 0; - century = -1; - want_century = 0; - want_era = 0; - era = NULL; - - have_wday = want_xday = have_yday = have_mon = have_mday = 0; - - while (*fmt != '\0') - { - /* A white space in the format string matches 0 more or white - space in the input string. */ - if (isspace (*fmt)) - { - while (isspace (*rp)) - ++rp; - ++fmt; - continue; - } - - /* Any character but `%' must be matched by the same character - in the iput string. */ - if (*fmt != '%') - { - match_char (*fmt++, *rp++); - continue; - } - - ++fmt; -#ifndef _NL_CURRENT - /* We need this for handling the `E' modifier. */ - start_over: -#endif - - /* Make back up of current processing pointer. */ - rp_backup = rp; - - switch (*fmt++) - { - case '%': - /* Match the `%' character itself. */ - match_char ('%', *rp++); - break; - case 'a': - case 'A': - /* Match day of week. */ - for (cnt = 0; cnt < 7; ++cnt) - { -#ifdef _NL_CURRENT - if (*decided !=raw) - { - if (match_string (_NL_CURRENT (LC_TIME, DAY_1 + cnt), rp)) - { - if (*decided == not - && strcmp (_NL_CURRENT (LC_TIME, DAY_1 + cnt), - weekday_name[cnt])) - *decided = loc; - break; - } - if (match_string (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), rp)) - { - if (*decided == not - && strcmp (_NL_CURRENT (LC_TIME, ABDAY_1 + cnt), - ab_weekday_name[cnt])) - *decided = loc; - break; - } - } -#endif - if (*decided != loc - && (match_string (weekday_name[cnt], rp) - || match_string (ab_weekday_name[cnt], rp))) - { - *decided = raw; - break; - } - } - if (cnt == 7) - /* Does not match a weekday name. */ - return NULL; - tm->tm_wday = cnt; - have_wday = 1; - break; - case 'b': - case 'B': - case 'h': - /* Match month name. */ - for (cnt = 0; cnt < 12; ++cnt) - { -#ifdef _NL_CURRENT - if (*decided !=raw) - { - if (match_string (_NL_CURRENT (LC_TIME, MON_1 + cnt), rp)) - { - if (*decided == not - && strcmp (_NL_CURRENT (LC_TIME, MON_1 + cnt), - month_name[cnt])) - *decided = loc; - break; - } - if (match_string (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), rp)) - { - if (*decided == not - && strcmp (_NL_CURRENT (LC_TIME, ABMON_1 + cnt), - ab_month_name[cnt])) - *decided = loc; - break; - } - } -#endif - if (match_string (month_name[cnt], rp) - || match_string (ab_month_name[cnt], rp)) - { - *decided = raw; - break; - } - } - if (cnt == 12) - /* Does not match a month name. */ - return NULL; - tm->tm_mon = cnt; - want_xday = 1; - break; - case 'c': - /* Match locale's date and time format. */ -#ifdef _NL_CURRENT - if (*decided != raw) - { - if (!recursive (_NL_CURRENT (LC_TIME, D_T_FMT))) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (*decided == not && - strcmp (_NL_CURRENT (LC_TIME, D_T_FMT), HERE_D_T_FMT)) - *decided = loc; - want_xday = 1; - break; - } - *decided = raw; - } -#endif - if (!recursive (HERE_D_T_FMT)) - return NULL; - want_xday = 1; - break; - case 'C': - /* Match century number. */ -#ifdef _NL_CURRENT - match_century: -#endif - get_number (0, 99, 2); - century = val; - want_xday = 1; - break; - case 'd': - case 'e': - /* Match day of month. */ - get_number (1, 31, 2); - tm->tm_mday = val; - have_mday = 1; - want_xday = 1; - break; - case 'F': - if (!recursive ("%Y-%m-%d")) - return NULL; - want_xday = 1; - break; - case 'x': -#ifdef _NL_CURRENT - if (*decided != raw) - { - if (!recursive (_NL_CURRENT (LC_TIME, D_FMT))) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (*decided == not - && strcmp (_NL_CURRENT (LC_TIME, D_FMT), HERE_D_FMT)) - *decided = loc; - want_xday = 1; - break; - } - *decided = raw; - } -#endif - /* Fall through. */ - case 'D': - /* Match standard day format. */ - if (!recursive (HERE_D_FMT)) - return NULL; - want_xday = 1; - break; - case 'k': - case 'H': - /* Match hour in 24-hour clock. */ - get_number (0, 23, 2); - tm->tm_hour = val; - have_I = 0; - break; - case 'I': - /* Match hour in 12-hour clock. */ - get_number (1, 12, 2); - tm->tm_hour = val % 12; - have_I = 1; - break; - case 'j': - /* Match day number of year. */ - get_number (1, 366, 3); - tm->tm_yday = val - 1; - have_yday = 1; - break; - case 'm': - /* Match number of month. */ - get_number (1, 12, 2); - tm->tm_mon = val - 1; - have_mon = 1; - want_xday = 1; - break; - case 'M': - /* Match minute. */ - get_number (0, 59, 2); - tm->tm_min = val; - break; - case 'n': - case 't': - /* Match any white space. */ - while (isspace (*rp)) - ++rp; - break; - case 'p': - /* Match locale's equivalent of AM/PM. */ -#ifdef _NL_CURRENT - if (*decided != raw) - { - if (match_string (_NL_CURRENT (LC_TIME, AM_STR), rp)) - { - if (strcmp (_NL_CURRENT (LC_TIME, AM_STR), HERE_AM_STR)) - *decided = loc; - break; - } - if (match_string (_NL_CURRENT (LC_TIME, PM_STR), rp)) - { - if (strcmp (_NL_CURRENT (LC_TIME, PM_STR), HERE_PM_STR)) - *decided = loc; - is_pm = 1; - break; - } - *decided = raw; - } -#endif - if (!match_string (HERE_AM_STR, rp)) { - if (match_string (HERE_PM_STR, rp)) { - is_pm = 1; - } else { - return NULL; - } - } - break; - case 'r': -#ifdef _NL_CURRENT - if (*decided != raw) - { - if (!recursive (_NL_CURRENT (LC_TIME, T_FMT_AMPM))) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (*decided == not && - strcmp (_NL_CURRENT (LC_TIME, T_FMT_AMPM), - HERE_T_FMT_AMPM)) - *decided = loc; - break; - } - *decided = raw; - } -#endif - if (!recursive (HERE_T_FMT_AMPM)) - return NULL; - break; - case 'R': - if (!recursive ("%H:%M")) - return NULL; - break; - case 's': - { - /* The number of seconds may be very high so we cannot use - the `get_number' macro. Instead read the number - character for character and construct the result while - doing this. */ - time_t secs = 0; - if (*rp < '0' || *rp > '9') - /* We need at least one digit. */ - return NULL; - - do - { - secs *= 10; - secs += *rp++ - '0'; - } - while (*rp >= '0' && *rp <= '9'); - - if (localtime_r (&secs, tm) == NULL) - /* Error in function. */ - return NULL; - } - break; - case 'S': - get_number (0, 61, 2); - tm->tm_sec = val; - break; - case 'X': -#ifdef _NL_CURRENT - if (*decided != raw) - { - if (!recursive (_NL_CURRENT (LC_TIME, T_FMT))) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (strcmp (_NL_CURRENT (LC_TIME, T_FMT), HERE_T_FMT)) - *decided = loc; - break; - } - *decided = raw; - } -#endif - /* Fall through. */ - case 'T': - if (!recursive (HERE_T_FMT)) - return NULL; - break; - case 'u': - get_number (1, 7, 1); - tm->tm_wday = val % 7; - have_wday = 1; - break; - case 'g': - get_number (0, 99, 2); - /* XXX This cannot determine any field in TM. */ - break; - case 'G': - if (*rp < '0' || *rp > '9') - return NULL; - /* XXX Ignore the number since we would need some more - information to compute a real date. */ - do - ++rp; - while (*rp >= '0' && *rp <= '9'); - break; - case 'U': - case 'V': - case 'W': - get_number (0, 53, 2); - /* XXX This cannot determine any field in TM without some - information. */ - break; - case 'w': - /* Match number of weekday. */ - get_number (0, 6, 1); - tm->tm_wday = val; - have_wday = 1; - break; - case 'y': -#ifdef _NL_CURRENT - match_year_in_century: -#endif - /* Match year within century. */ - get_number (0, 99, 2); - /* The "Year 2000: The Millennium Rollover" paper suggests that - values in the range 69-99 refer to the twentieth century. */ - tm->tm_year = val >= 69 ? val : val + 100; - /* Indicate that we want to use the century, if specified. */ - want_century = 1; - want_xday = 1; - break; - case 'Y': - /* Match year including century number. */ - get_number (0, 9999, 4); - tm->tm_year = val - 1900; - want_century = 0; - want_xday = 1; - break; - case 'Z': - /* XXX How to handle this? */ - break; - case 'E': -#ifdef _NL_CURRENT - switch (*fmt++) - { - case 'c': - /* Match locale's alternate date and time format. */ - if (*decided != raw) - { - const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_T_FMT); - - if (*fmt == '\0') - fmt = _NL_CURRENT (LC_TIME, D_T_FMT); - - if (!recursive (fmt)) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (strcmp (fmt, HERE_D_T_FMT)) - *decided = loc; - want_xday = 1; - break; - } - *decided = raw; - } - /* The C locale has no era information, so use the - normal representation. */ - if (!recursive (HERE_D_T_FMT)) - return NULL; - want_xday = 1; - break; - case 'C': - if (*decided != raw) - { - if (era_cnt >= 0) - { - era = _nl_select_era_entry (era_cnt); - if (match_string (era->era_name, rp)) - { - *decided = loc; - break; - } - else - return NULL; - } - else - { - num_eras = _NL_CURRENT_WORD (LC_TIME, - _NL_TIME_ERA_NUM_ENTRIES); - for (era_cnt = 0; era_cnt < (int) num_eras; - ++era_cnt, rp = rp_backup) - { - era = _nl_select_era_entry (era_cnt); - if (match_string (era->era_name, rp)) - { - *decided = loc; - break; - } - } - if (era_cnt == (int) num_eras) - { - era_cnt = -1; - if (*decided == loc) - return NULL; - } - else - break; - } - - *decided = raw; - } - /* The C locale has no era information, so use the - normal representation. */ - goto match_century; - case 'y': - if (*decided == raw) - goto match_year_in_century; - - get_number(0, 9999, 4); - tm->tm_year = val; - want_era = 1; - want_xday = 1; - break; - case 'Y': - if (*decided != raw) - { - num_eras = _NL_CURRENT_WORD (LC_TIME, - _NL_TIME_ERA_NUM_ENTRIES); - for (era_cnt = 0; era_cnt < (int) num_eras; - ++era_cnt, rp = rp_backup) - { - era = _nl_select_era_entry (era_cnt); - if (recursive (era->era_format)) - break; - } - if (era_cnt == (int) num_eras) - { - era_cnt = -1; - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - *decided = loc; - era_cnt = -1; - break; - } - - *decided = raw; - } - get_number (0, 9999, 4); - tm->tm_year = val - 1900; - want_century = 0; - want_xday = 1; - break; - case 'x': - if (*decided != raw) - { - const char *fmt = _NL_CURRENT (LC_TIME, ERA_D_FMT); - - if (*fmt == '\0') - fmt = _NL_CURRENT (LC_TIME, D_FMT); - - if (!recursive (fmt)) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (strcmp (fmt, HERE_D_FMT)) - *decided = loc; - break; - } - *decided = raw; - } - if (!recursive (HERE_D_FMT)) - return NULL; - break; - case 'X': - if (*decided != raw) - { - const char *fmt = _NL_CURRENT (LC_TIME, ERA_T_FMT); - - if (*fmt == '\0') - fmt = _NL_CURRENT (LC_TIME, T_FMT); - - if (!recursive (fmt)) - { - if (*decided == loc) - return NULL; - else - rp = rp_backup; - } - else - { - if (strcmp (fmt, HERE_T_FMT)) - *decided = loc; - break; - } - *decided = raw; - } - if (!recursive (HERE_T_FMT)) - return NULL; - break; - default: - return NULL; - } - break; -#else - /* We have no information about the era format. Just use - the normal format. */ - if (*fmt != 'c' && *fmt != 'C' && *fmt != 'y' && *fmt != 'Y' - && *fmt != 'x' && *fmt != 'X') - /* This is an illegal format. */ - return NULL; - - goto start_over; -#endif - case 'O': - switch (*fmt++) - { - case 'd': - case 'e': - /* Match day of month using alternate numeric symbols. */ - get_alt_number (1, 31, 2); - tm->tm_mday = val; - have_mday = 1; - want_xday = 1; - break; - case 'H': - /* Match hour in 24-hour clock using alternate numeric - symbols. */ - get_alt_number (0, 23, 2); - tm->tm_hour = val; - have_I = 0; - break; - case 'I': - /* Match hour in 12-hour clock using alternate numeric - symbols. */ - get_alt_number (1, 12, 2); - tm->tm_hour = val - 1; - have_I = 1; - break; - case 'm': - /* Match month using alternate numeric symbols. */ - get_alt_number (1, 12, 2); - tm->tm_mon = val - 1; - have_mon = 1; - want_xday = 1; - break; - case 'M': - /* Match minutes using alternate numeric symbols. */ - get_alt_number (0, 59, 2); - tm->tm_min = val; - break; - case 'S': - /* Match seconds using alternate numeric symbols. */ - get_alt_number (0, 61, 2); - tm->tm_sec = val; - break; - case 'U': - case 'V': - case 'W': - get_alt_number (0, 53, 2); - /* XXX This cannot determine any field in TM without - further information. */ - break; - case 'w': - /* Match number of weekday using alternate numeric symbols. */ - get_alt_number (0, 6, 1); - tm->tm_wday = val; - have_wday = 1; - break; - case 'y': - /* Match year within century using alternate numeric symbols. */ - get_alt_number (0, 99, 2); - tm->tm_year = val >= 69 ? val : val + 100; - want_xday = 1; - break; - default: - return NULL; - } - break; - default: - return NULL; - } - } - - if (have_I && is_pm) - tm->tm_hour += 12; - - if (century != -1) - { - if (want_century) - tm->tm_year = tm->tm_year % 100 + (century - 19) * 100; - else - /* Only the century, but not the year. Strange, but so be it. */ - tm->tm_year = (century - 19) * 100; - } - -#ifdef _NL_CURRENT - if (era_cnt != -1) - { - era = _nl_select_era_entry(era_cnt); - if (want_era) - tm->tm_year = (era->start_date[0] - + ((tm->tm_year - era->offset) - * era->absolute_direction)); - else - /* Era start year assumed. */ - tm->tm_year = era->start_date[0]; - } - else -#endif - if (want_era) - return NULL; - - if (want_xday && !have_wday) - { - if ( !(have_mon && have_mday) && have_yday) - { - /* We don't have tm_mon and/or tm_mday, compute them. */ - int t_mon = 0; - while (__mon_yday[__isleap(1900 + tm->tm_year)][t_mon] <= tm->tm_yday) - t_mon++; - if (!have_mon) - tm->tm_mon = t_mon - 1; - if (!have_mday) - tm->tm_mday = - (tm->tm_yday - - __mon_yday[__isleap(1900 + tm->tm_year)][t_mon - 1] + 1); - } - day_of_the_week (tm); - } - if (want_xday && !have_yday) - day_of_the_year (tm); - - return discard_const_p(char, rp); -} - - -char *rep_strptime(const char *buf, const char *format, struct tm *tm) -{ - enum locale_status decided; - -#ifdef _NL_CURRENT - decided = not; -#else - decided = raw; -#endif - return strptime_internal (buf, format, tm, &decided, -1); -} diff --git a/bundled/replace/strptime.m4 b/bundled/replace/strptime.m4 deleted file mode 100644 index b1a56b4a..00000000 --- a/bundled/replace/strptime.m4 +++ /dev/null @@ -1,13 +0,0 @@ -AC_CACHE_CHECK([whether strptime is available and works],libreplace_cv_STRPTIME_OK,[ - AC_TRY_RUN([ - #define LIBREPLACE_CONFIGURE_TEST_STRPTIME - #include "$libreplacedir/test/strptime.c" - ], - [libreplace_cv_STRPTIME_OK=yes], - [libreplace_cv_STRPTIME_OK=no], - [libreplace_cv_STRPTIME_OK="assuming not"]) -]) -if test x"$libreplace_cv_STRPTIME_OK" != x"yes"; then - AC_DEFINE(REPLACE_STRPTIME,1,[Whether strptime should be replaced]) - LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/strptime.o" -fi diff --git a/bundled/replace/system/README b/bundled/replace/system/README deleted file mode 100644 index 69a2b80b..00000000 --- a/bundled/replace/system/README +++ /dev/null @@ -1,4 +0,0 @@ -This directory contains wrappers around logical groups of system -include files. The idea is to avoid #ifdef blocks in the main code, -and instead put all the necessary conditional includes in subsystem -specific header files in this directory. diff --git a/bundled/replace/system/aio.h b/bundled/replace/system/aio.h deleted file mode 100644 index 784d77fa..00000000 --- a/bundled/replace/system/aio.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _system_aio_h -#define _system_aio_h -/* - Unix SMB/CIFS implementation. - - AIO system include wrappers - - Copyright (C) Andrew Tridgell 2006 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#ifdef HAVE_LIBAIO_H -#include -#endif - -#endif diff --git a/bundled/replace/system/capability.h b/bundled/replace/system/capability.h deleted file mode 100644 index a7b78f02..00000000 --- a/bundled/replace/system/capability.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _system_capability_h -#define _system_capability_h -/* - Unix SMB/CIFS implementation. - - capability system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#ifdef HAVE_SYS_CAPABILITY_H - -#if defined(BROKEN_REDHAT_7_SYSTEM_HEADERS) && !defined(_I386_STATFS_H) && !defined(_PPC_STATFS_H) -#define _I386_STATFS_H -#define _PPC_STATFS_H -#define BROKEN_REDHAT_7_STATFS_WORKAROUND -#endif - -#if defined(BROKEN_RHEL5_SYS_CAP_HEADER) && !defined(_LINUX_TYPES_H) -#define BROKEN_RHEL5_SYS_CAP_HEADER_WORKAROUND -#endif - -#include - -#ifdef BROKEN_RHEL5_SYS_CAP_HEADER_WORKAROUND -#undef _LINUX_TYPES_H -#undef BROKEN_RHEL5_SYS_CAP_HEADER_WORKAROUND -#endif - -#ifdef BROKEN_REDHAT_7_STATFS_WORKAROUND -#undef _PPC_STATFS_H -#undef _I386_STATFS_H -#undef BROKEN_REDHAT_7_STATFS_WORKAROUND -#endif - -#endif - -#endif diff --git a/bundled/replace/system/config.m4 b/bundled/replace/system/config.m4 deleted file mode 100644 index b8568a51..00000000 --- a/bundled/replace/system/config.m4 +++ /dev/null @@ -1,131 +0,0 @@ -# filesys -AC_HEADER_DIRENT -AC_CHECK_HEADERS(fcntl.h sys/fcntl.h sys/resource.h sys/ioctl.h sys/mode.h sys/filio.h sys/fs/s5param.h sys/filsys.h) -AC_CHECK_HEADERS(sys/acl.h acl/libacl.h sys/file.h) - -# select -AC_CHECK_HEADERS(sys/select.h) - -# time -AC_CHECK_HEADERS(sys/time.h utime.h) -AC_HEADER_TIME -AC_CHECK_FUNCS(utime utimes) - -# wait -AC_HEADER_SYS_WAIT - -# capability -AC_CHECK_HEADERS(sys/capability.h) - -case "$host_os" in -*linux*) -AC_CACHE_CHECK([for broken RedHat 7.2 system header files],libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS,[ -AC_TRY_COMPILE([ - #ifdef HAVE_SYS_VFS_H - #include - #endif - #ifdef HAVE_SYS_CAPABILITY_H - #include - #endif - ],[ - int i; - ], - libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=no, - libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=yes -)]) -if test x"$libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" = x"yes"; then - AC_DEFINE(BROKEN_REDHAT_7_SYSTEM_HEADERS,1,[Broken RedHat 7.2 system header files]) -fi - -AC_CACHE_CHECK([for broken RHEL5 sys/capability.h],libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER,[ -AC_TRY_COMPILE([ - #ifdef HAVE_SYS_CAPABILITY_H - #include - #endif - #include - ],[ - __s8 i; - ], - libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=no, - libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=yes -)]) -if test x"$libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER" = x"yes"; then - AC_DEFINE(BROKEN_RHEL5_SYS_CAP_HEADER,1,[Broken RHEL5 sys/capability.h]) -fi -;; -esac - -# passwd -AC_CHECK_HEADERS(grp.h sys/id.h compat.h shadow.h sys/priv.h pwd.h sys/security.h) -AC_CHECK_FUNCS(getpwnam_r getpwuid_r getpwent_r) -AC_HAVE_DECL(getpwent_r, [ - #include - #include - ]) -AC_VERIFY_C_PROTOTYPE([struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)], - [ - #ifndef HAVE_GETPWENT_R_DECL - #error missing getpwent_r prototype - #endif - return NULL; - ],[ - AC_DEFINE(SOLARIS_GETPWENT_R, 1, [getpwent_r solaris function prototype]) - ],[],[ - #include - #include - ]) -AC_VERIFY_C_PROTOTYPE([struct passwd *getpwent_r(struct passwd *src, char *buf, size_t buflen)], - [ - #ifndef HAVE_GETPWENT_R_DECL - #error missing getpwent_r prototype - #endif - return NULL; - ],[ - AC_DEFINE(SOLARIS_GETPWENT_R, 1, [getpwent_r irix (similar to solaris) function prototype]) - ],[],[ - #include - #include - ]) -AC_CHECK_FUNCS(getgrnam_r getgrgid_r getgrent_r) -AC_HAVE_DECL(getgrent_r, [ - #include - #include - ]) -AC_VERIFY_C_PROTOTYPE([struct group *getgrent_r(struct group *src, char *buf, int buflen)], - [ - #ifndef HAVE_GETGRENT_R_DECL - #error missing getgrent_r prototype - #endif - return NULL; - ],[ - AC_DEFINE(SOLARIS_GETGRENT_R, 1, [getgrent_r solaris function prototype]) - ],[],[ - #include - #include - ]) - -AC_VERIFY_C_PROTOTYPE([struct group *getgrent_r(struct group *src, char *buf, size_t buflen)], - [ - #ifndef HAVE_GETGRENT_R_DECL - #error missing getgrent_r prototype - #endif - return NULL; - ],[ - AC_DEFINE(SOLARIS_GETGRENT_R, 1, [getgrent_r irix (similar to solaris) function prototype]) - ],[],[ - #include - #include - ]) -AC_CHECK_FUNCS(getgrouplist) - -# locale -AC_CHECK_HEADERS(ctype.h locale.h langinfo.h) - -# glob -AC_CHECK_HEADERS(fnmatch.h) - -# shmem -AC_CHECK_HEADERS(sys/ipc.h sys/mman.h sys/shm.h ) - -# terminal -AC_CHECK_HEADERS(termios.h termio.h sys/termio.h ) diff --git a/bundled/replace/system/dir.h b/bundled/replace/system/dir.h deleted file mode 100644 index dec2d546..00000000 --- a/bundled/replace/system/dir.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef _system_dir_h -#define _system_dir_h -/* - Unix SMB/CIFS implementation. - - directory system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#if HAVE_DIRENT_H -# include -# define NAMLEN(dirent) strlen((dirent)->d_name) -#else -# define dirent direct -# define NAMLEN(dirent) (dirent)->d_namlen -# if HAVE_SYS_NDIR_H -# include -# endif -# if HAVE_SYS_DIR_H -# include -# endif -# if HAVE_NDIR_H -# include -# endif -#endif - -#ifndef HAVE_MKDIR_MODE -#define mkdir(dir, mode) mkdir(dir) -#endif - -/* Test whether a file name is the "." or ".." directory entries. - * These really should be inline functions. - */ -#ifndef ISDOT -#define ISDOT(path) ( \ - *((const char *)(path)) == '.' && \ - *(((const char *)(path)) + 1) == '\0' \ - ) -#endif - -#ifndef ISDOTDOT -#define ISDOTDOT(path) ( \ - *((const char *)(path)) == '.' && \ - *(((const char *)(path)) + 1) == '.' && \ - *(((const char *)(path)) + 2) == '\0' \ - ) -#endif - -#endif diff --git a/bundled/replace/system/filesys.h b/bundled/replace/system/filesys.h deleted file mode 100644 index 6cf2dd28..00000000 --- a/bundled/replace/system/filesys.h +++ /dev/null @@ -1,188 +0,0 @@ -#ifndef _system_filesys_h -#define _system_filesys_h -/* - Unix SMB/CIFS implementation. - - filesystem system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#include -#include - -#ifdef HAVE_SYS_PARAM_H -#include -#endif - -#ifdef HAVE_SYS_MOUNT_H -#include -#endif - -#ifdef HAVE_MNTENT_H -#include -#endif - -#ifdef HAVE_SYS_VFS_H -#include -#endif - -#ifdef HAVE_SYS_ACL_H -#include -#endif - -#ifdef HAVE_ACL_LIBACL_H -#include -#endif - -#ifdef HAVE_SYS_FS_S5PARAM_H -#include -#endif - -#if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY) -#include -#endif - -#ifdef HAVE_SYS_STATFS_H -# include -#endif - -#ifdef HAVE_DUSTAT_H -#include -#endif - -#ifdef HAVE_SYS_STATVFS_H -#include -#endif - -#ifdef HAVE_SYS_FILIO_H -#include -#endif - -#ifdef HAVE_SYS_FILE_H -#include -#endif - -#ifdef HAVE_FCNTL_H -#include -#else -#ifdef HAVE_SYS_FCNTL_H -#include -#endif -#endif - -#ifdef HAVE_SYS_MODE_H -/* apparently AIX needs this for S_ISLNK */ -#ifndef S_ISLNK -#include -#endif -#endif - -#ifdef HAVE_SYS_IOCTL_H -#include -#endif - -/* - * Veritas File System. Often in addition to native. - * Quotas different. - */ -#if defined(HAVE_SYS_FS_VX_QUOTA_H) -#define VXFS_QUOTA -#endif - -#if HAVE_SYS_ATTRIBUTES_H -#include -#endif - -/* mutually exclusive (SuSE 8.2) */ -#if HAVE_ATTR_XATTR_H -#include -#elif HAVE_SYS_XATTR_H -#include -#endif - - -#ifdef HAVE_SYS_RESOURCE_H -#include -#endif - -/* Some POSIX definitions for those without */ - -#ifndef S_IFDIR -#define S_IFDIR 0x4000 -#endif -#ifndef S_ISDIR -#define S_ISDIR(mode) ((mode & 0xF000) == S_IFDIR) -#endif -#ifndef S_IRWXU -#define S_IRWXU 00700 /* read, write, execute: owner */ -#endif -#ifndef S_IRUSR -#define S_IRUSR 00400 /* read permission: owner */ -#endif -#ifndef S_IWUSR -#define S_IWUSR 00200 /* write permission: owner */ -#endif -#ifndef S_IXUSR -#define S_IXUSR 00100 /* execute permission: owner */ -#endif -#ifndef S_IRWXG -#define S_IRWXG 00070 /* read, write, execute: group */ -#endif -#ifndef S_IRGRP -#define S_IRGRP 00040 /* read permission: group */ -#endif -#ifndef S_IWGRP -#define S_IWGRP 00020 /* write permission: group */ -#endif -#ifndef S_IXGRP -#define S_IXGRP 00010 /* execute permission: group */ -#endif -#ifndef S_IRWXO -#define S_IRWXO 00007 /* read, write, execute: other */ -#endif -#ifndef S_IROTH -#define S_IROTH 00004 /* read permission: other */ -#endif -#ifndef S_IWOTH -#define S_IWOTH 00002 /* write permission: other */ -#endif -#ifndef S_IXOTH -#define S_IXOTH 00001 /* execute permission: other */ -#endif - -#ifndef O_ACCMODE -#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) -#endif - -#ifndef MAXPATHLEN -#define MAXPATHLEN 256 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -#ifdef _WIN32 -#define mkdir(d,m) _mkdir(d) -#endif - -#endif diff --git a/bundled/replace/system/glob.h b/bundled/replace/system/glob.h deleted file mode 100644 index 3e23db68..00000000 --- a/bundled/replace/system/glob.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _system_glob_h -#define _system_glob_h -/* - Unix SMB/CIFS implementation. - - glob system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#ifdef HAVE_GLOB_H -#include -#endif - -#ifdef HAVE_FNMATCH_H -#include -#endif - -#endif diff --git a/bundled/replace/system/iconv.h b/bundled/replace/system/iconv.h deleted file mode 100644 index 3c8a71f2..00000000 --- a/bundled/replace/system/iconv.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _system_iconv_h -#define _system_iconv_h -/* - Unix SMB/CIFS implementation. - - iconv memory system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#if !defined(HAVE_ICONV) && defined(HAVE_ICONV_H) -#define HAVE_ICONV -#endif - -#if !defined(HAVE_GICONV) && defined(HAVE_GICONV_H) -#define HAVE_GICONV -#endif - -#if !defined(HAVE_BICONV) && defined(HAVE_BICONV_H) -#define HAVE_BICONV -#endif - -#ifdef HAVE_NATIVE_ICONV -#if defined(HAVE_ICONV) -#include -#elif defined(HAVE_GICONV) -#include -#elif defined(HAVE_BICONV) -#include -#endif -#endif /* HAVE_NATIVE_ICONV */ - -/* needed for some systems without iconv. Doesn't really matter - what error code we use */ -#ifndef EILSEQ -#define EILSEQ EIO -#endif - -#endif diff --git a/bundled/replace/system/kerberos.h b/bundled/replace/system/kerberos.h deleted file mode 100644 index a1685ad3..00000000 --- a/bundled/replace/system/kerberos.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef _system_kerberos_h -#define _system_kerberos_h - -/* - Unix SMB/CIFS implementation. - - kerberos system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#ifdef HAVE_KRB5 -/* Whether the krb5_address struct has a addrtype property */ -/* #undef HAVE_ADDRTYPE_IN_KRB5_ADDRESS */ -/* Whether the krb5_address struct has a addr_type property */ -#define HAVE_ADDR_TYPE_IN_KRB5_ADDRESS 1 -/* Define to 1 if you have the `gsskrb5_extract_authz_data_from_sec_context' */ -#define HAVE_GSSKRB5_EXTRACT_AUTHZ_DATA_FROM_SEC_CONTEXT 1 -/* Define to 1 if you have the `gsskrb5_get_initiator_subkey' function. */ -#define HAVE_GSSKRB5_GET_INITIATOR_SUBKEY 1 -/* Define to 1 if you have the `gsskrb5_register_acceptor_identity' function. */ -#define HAVE_GSSKRB5_REGISTER_ACCEPTOR_IDENTITY 1 -/* Define to 1 if you have the `gss_krb5_ccache_name' function. */ -#define HAVE_GSS_KRB5_CCACHE_NAME 1 -/* Define to 1 if you have the `krb5_addlog_func' function. */ -#define HAVE_KRB5_ADDLOG_FUNC 1 -/* Define to 1 if you have the `krb5_auth_con_setkey' function. */ -#define HAVE_KRB5_AUTH_CON_SETKEY 1 -/* Define to 1 if you have the `krb5_auth_con_setuseruserkey' function. */ -/* #undef HAVE_KRB5_AUTH_CON_SETUSERUSERKEY */ -/* Define to 1 if you have the `krb5_c_enctype_compare' function. */ -#define HAVE_KRB5_C_ENCTYPE_COMPARE 1 -/* Define to 1 if you have the `krb5_c_verify_checksum' function. */ -#define HAVE_KRB5_C_VERIFY_CHECKSUM 1 -/* Whether the type krb5_encrypt_block exists */ -/* #undef HAVE_KRB5_ENCRYPT_BLOCK */ -/* Define to 1 if you have the `krb5_encrypt_data' function. */ -/* #undef HAVE_KRB5_ENCRYPT_DATA */ -/* Define to 1 if you have the `krb5_enctypes_compatible_keys' function. */ -#define HAVE_KRB5_ENCTYPES_COMPATIBLE_KEYS 1 -/* Define to 1 if you have the `krb5_free_data_contents' function. */ -#define HAVE_KRB5_FREE_DATA_CONTENTS 1 -/* Define to 1 if you have the `krb5_free_error_string' function. */ -/* #undef HAVE_KRB5_FREE_ERROR_STRING */ -/* Define to 1 if you have the `krb5_free_error_message' function. */ -#define HAVE_KRB5_FREE_ERROR_MESSAGE 1 -/* Define to 1 if you have the `krb5_free_keytab_entry_contents' function. */ -/* #undef HAVE_KRB5_FREE_KEYTAB_ENTRY_CONTENTS */ -/* Define to 1 if you have the `krb5_free_ktypes' function. */ -/* #undef HAVE_KRB5_FREE_KTYPES */ -/* Define to 1 if you have the `krb5_free_unparsed_name' function. */ -/* #undef HAVE_KRB5_FREE_UNPARSED_NAME */ -/* Define to 1 if you have the `krb5_get_default_in_tkt_etypes' function. */ -#define HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES 1 -/* Define to 1 if you have the `krb5_get_error_string' function. */ -#define HAVE_KRB5_GET_ERROR_STRING 1 -/* Define to 1 if you have the `krb5_get_error_message' function. */ -#define HAVE_KRB5_GET_ERROR_MESSAGE 1 -/* Define to 1 if you have the `krb5_get_permitted_enctypes' function. */ -/* #undef HAVE_KRB5_GET_PERMITTED_ENCTYPES */ -/* Define to 1 if you have the `krb5_get_pw_salt' function. */ -#define HAVE_KRB5_GET_PW_SALT 1 -/* Define to 1 if you have the header file. */ -#define HAVE_KRB5_H 1 -/* Define to 1 if you have the `krb5_initlog' function. */ -#define HAVE_KRB5_INITLOG 1 -/* Define to 1 if you have the `krb5_kdc_default_config' function. */ -#define HAVE_KRB5_KDC_DEFAULT_CONFIG 1 -/* Whether the krb5_creds struct has a keyblock property */ -/* #undef HAVE_KRB5_KEYBLOCK_IN_CREDS */ -/* Whether the krb5_keyblock struct has a keyvalue property */ -#define HAVE_KRB5_KEYBLOCK_KEYVALUE 1 -/* Whether krb5_keytab_entry has key member */ -/* #undef HAVE_KRB5_KEYTAB_ENTRY_KEY */ -/* Whether krb5_keytab_entry has keyblock member */ -#define HAVE_KRB5_KEYTAB_ENTRY_KEYBLOCK 1 -/* Define to 1 if you have the `krb5_krbhst_get_addrinfo' function. */ -#define HAVE_KRB5_KRBHST_GET_ADDRINFO 1 -/* Define to 1 if you have the `krb5_kt_compare' function. */ -#define HAVE_KRB5_KT_COMPARE 1 -/* Define to 1 if you have the `krb5_kt_free_entry' function. */ -#define HAVE_KRB5_KT_FREE_ENTRY 1 -/* Whether the type krb5_log_facility exists */ -#define HAVE_KRB5_LOG_FACILITY 1 -/* Define to 1 if you have the `krb5_mk_req_extended' function. */ -#define HAVE_KRB5_MK_REQ_EXTENDED 1 -/* Define to 1 if you have the `krb5_principal2salt' function. */ -/* #undef HAVE_KRB5_PRINCIPAL2SALT */ -/* Define to 1 if you have the `krb5_principal_get_comp_string' function. */ -#define HAVE_KRB5_PRINCIPAL_GET_COMP_STRING 1 -/* Whether krb5_princ_component is available */ -/* #undef HAVE_KRB5_PRINC_COMPONENT */ -/* Whether the krb5_creds struct has a session property */ -#define HAVE_KRB5_SESSION_IN_CREDS 1 -/* Define to 1 if you have the `krb5_set_default_in_tkt_etypes' function. */ -#define HAVE_KRB5_SET_DEFAULT_IN_TKT_ETYPES 1 -/* Define to 1 if you have the `krb5_set_default_tgs_ktypes' function. */ -/* #undef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES */ -/* Define to 1 if you have the `krb5_set_real_time' function. */ -#define HAVE_KRB5_SET_REAL_TIME 1 -/* Define to 1 if you have the `krb5_set_warn_dest' function. */ -#define HAVE_KRB5_SET_WARN_DEST 1 -/* Define to 1 if you have the `krb5_string_to_key' function. */ -#define HAVE_KRB5_STRING_TO_KEY 1 -/* Define to 1 if you have the `krb5_string_to_key_salt' function. */ -#define HAVE_KRB5_STRING_TO_KEY_SALT 1 -/* Define to 1 if you have the `krb5_ticket_get_authorization_data_type' */ -#define HAVE_KRB5_TICKET_GET_AUTHORIZATION_DATA_TYPE 1 -/* Whether the krb5_ticket struct has a enc_part2 property */ -/* #undef HAVE_KRB5_TKT_ENC_PART2 */ -/* Define to 1 if you have the `krb5_use_enctype' function. */ -/* #undef HAVE_KRB5_USE_ENCTYPE */ -/* Define to 1 if you have the `krb5_verify_checksum' function. */ -#define HAVE_KRB5_VERIFY_CHECKSUM 1 -/* Whether krb5_princ_realm returns krb5_realm or krb5_data */ -#define KRB5_PRINC_REALM_RETURNS_REALM 1 - -#include -#include - -#endif - -#endif diff --git a/bundled/replace/system/locale.h b/bundled/replace/system/locale.h deleted file mode 100644 index 504a3bb4..00000000 --- a/bundled/replace/system/locale.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _system_locale_h -#define _system_locale_h - -/* - Unix SMB/CIFS implementation. - - locale include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#ifdef HAVE_CTYPE_H -#include -#endif - -#ifdef HAVE_LOCALE_H -#include -#endif - -#ifdef HAVE_LANGINFO_H -#include -#endif - -#endif diff --git a/bundled/replace/system/network.h b/bundled/replace/system/network.h deleted file mode 100644 index 93d533c9..00000000 --- a/bundled/replace/system/network.h +++ /dev/null @@ -1,379 +0,0 @@ -#ifndef _system_network_h -#define _system_network_h -/* - Unix SMB/CIFS implementation. - - networking system include wrappers - - Copyright (C) Andrew Tridgell 2004 - Copyright (C) Jelmer Vernooij 2007 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#ifndef LIBREPLACE_NETWORK_CHECKS -#error "AC_LIBREPLACE_NETWORK_CHECKS missing in configure" -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - -#ifdef HAVE_UNIXSOCKET -#include -#endif - -#ifdef HAVE_NETINET_IN_H -#include -#endif -#ifdef HAVE_ARPA_INET_H -#include -#endif - -#ifdef HAVE_NETDB_H -#include -#endif - -#ifdef HAVE_NETINET_TCP_H -#include -#endif - -/* - * The next three defines are needed to access the IPTOS_* options - * on some systems. - */ - -#ifdef HAVE_NETINET_IN_SYSTM_H -#include -#endif - -#ifdef HAVE_NETINET_IN_IP_H -#include -#endif - -#ifdef HAVE_NETINET_IP_H -#include -#endif - -#ifdef HAVE_NET_IF_H -#include -#endif - -#ifdef HAVE_UNISTD_H -#include -#endif - -#ifdef HAVE_SYS_IOCTL_H -#include -#endif - -#ifdef HAVE_SYS_UIO_H -#include -#endif - -#ifdef HAVE_STROPTS_H -#include -#endif - -#ifndef HAVE_SOCKLEN_T -#define HAVE_SOCKLEN_T -typedef int socklen_t; -#endif - -#if !defined (HAVE_INET_NTOA) || defined(REPLACE_INET_NTOA) -/* define is in "replace.h" */ -char *rep_inet_ntoa(struct in_addr ip); -#endif - -#ifndef HAVE_INET_PTON -/* define is in "replace.h" */ -int rep_inet_pton(int af, const char *src, void *dst); -#endif - -#ifndef HAVE_INET_NTOP -/* define is in "replace.h" */ -const char *rep_inet_ntop(int af, const void *src, char *dst, socklen_t size); -#endif - -#ifndef HAVE_INET_ATON -/* define is in "replace.h" */ -int rep_inet_aton(const char *src, struct in_addr *dst); -#endif - -#ifndef HAVE_CONNECT -/* define is in "replace.h" */ -int rep_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); -#endif - -#ifndef HAVE_GETHOSTBYNAME -/* define is in "replace.h" */ -struct hostent *rep_gethostbyname(const char *name); -#endif - -#ifdef HAVE_IFADDRS_H -#include -#endif - -#ifndef HAVE_STRUCT_IFADDRS -struct ifaddrs { - struct ifaddrs *ifa_next; /* Pointer to next struct */ - char *ifa_name; /* Interface name */ - unsigned int ifa_flags; /* Interface flags */ - struct sockaddr *ifa_addr; /* Interface address */ - struct sockaddr *ifa_netmask; /* Interface netmask */ -#undef ifa_dstaddr - struct sockaddr *ifa_dstaddr; /* P2P interface destination */ - void *ifa_data; /* Address specific data */ -}; -#endif - -#ifndef HAVE_GETIFADDRS -int rep_getifaddrs(struct ifaddrs **); -#endif - -#ifndef HAVE_FREEIFADDRS -void rep_freeifaddrs(struct ifaddrs *); -#endif - -#ifndef HAVE_SOCKETPAIR -/* define is in "replace.h" */ -int rep_socketpair(int d, int type, int protocol, int sv[2]); -#endif - -/* - * Some systems have getaddrinfo but not the - * defines needed to use it. - */ - -/* Various macros that ought to be in , but might not be */ - -#ifndef EAI_FAIL -#define EAI_BADFLAGS (-1) -#define EAI_NONAME (-2) -#define EAI_AGAIN (-3) -#define EAI_FAIL (-4) -#define EAI_FAMILY (-6) -#define EAI_SOCKTYPE (-7) -#define EAI_SERVICE (-8) -#define EAI_MEMORY (-10) -#define EAI_SYSTEM (-11) -#endif /* !EAI_FAIL */ - -#ifndef AI_PASSIVE -#define AI_PASSIVE 0x0001 -#endif - -#ifndef AI_CANONNAME -#define AI_CANONNAME 0x0002 -#endif - -#ifndef AI_NUMERICHOST -/* - * some platforms don't support AI_NUMERICHOST; define as zero if using - * the system version of getaddrinfo... - */ -#if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO) -#define AI_NUMERICHOST 0 -#else -#define AI_NUMERICHOST 0x0004 -#endif -#endif - -/* - * Some of the functions in source3/lib/util_sock.c use AI_ADDRCONFIG. On QNX - * 6.3.0, this macro is defined but, if it's used, getaddrinfo will fail. This - * prevents smbd from opening any sockets. - * - * If I undefine AI_ADDRCONFIG on such systems and define it to be 0, - * this works around the issue. - */ -#ifdef __QNX__ -#include -#if _NTO_VERSION == 630 -#undef AI_ADDRCONFIG -#endif -#endif -#ifndef AI_ADDRCONFIG -/* - * logic copied from AI_NUMERICHOST - */ -#if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO) -#define AI_ADDRCONFIG 0 -#else -#define AI_ADDRCONFIG 0x0020 -#endif -#endif - -#ifndef AI_NUMERICSERV -/* - * logic copied from AI_NUMERICHOST - */ -#if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO) -#define AI_NUMERICSERV 0 -#else -#define AI_NUMERICSERV 0x0400 -#endif -#endif - -#ifndef NI_NUMERICHOST -#define NI_NUMERICHOST 1 -#endif - -#ifndef NI_NUMERICSERV -#define NI_NUMERICSERV 2 -#endif - -#ifndef NI_NOFQDN -#define NI_NOFQDN 4 -#endif - -#ifndef NI_NAMEREQD -#define NI_NAMEREQD 8 -#endif - -#ifndef NI_DGRAM -#define NI_DGRAM 16 -#endif - - -#ifndef NI_MAXHOST -#define NI_MAXHOST 1025 -#endif - -#ifndef NI_MAXSERV -#define NI_MAXSERV 32 -#endif - -/* - * glibc on linux doesn't seem to have MSG_WAITALL - * defined. I think the kernel has it though.. - */ -#ifndef MSG_WAITALL -#define MSG_WAITALL 0 -#endif - -#ifndef INADDR_LOOPBACK -#define INADDR_LOOPBACK 0x7f000001 -#endif - -#ifndef INADDR_NONE -#define INADDR_NONE 0xffffffff -#endif - -#ifndef EAFNOSUPPORT -#define EAFNOSUPPORT EINVAL -#endif - -#ifndef INET_ADDRSTRLEN -#define INET_ADDRSTRLEN 16 -#endif - -#ifndef INET6_ADDRSTRLEN -#define INET6_ADDRSTRLEN 46 -#endif - -#ifndef HOST_NAME_MAX -#define HOST_NAME_MAX 255 -#endif - -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN HOST_NAME_MAX -#endif - -#ifndef HAVE_SA_FAMILY_T -#define HAVE_SA_FAMILY_T -typedef unsigned short int sa_family_t; -#endif - -#ifndef HAVE_STRUCT_SOCKADDR_STORAGE -#define HAVE_STRUCT_SOCKADDR_STORAGE -#ifdef HAVE_STRUCT_SOCKADDR_IN6 -#define sockaddr_storage sockaddr_in6 -#define ss_family sin6_family -#define HAVE_SS_FAMILY 1 -#else -#define sockaddr_storage sockaddr_in -#define ss_family sin_family -#define HAVE_SS_FAMILY 1 -#endif -#endif - -#ifndef HAVE_SS_FAMILY -#ifdef HAVE___SS_FAMILY -#define ss_family __ss_family -#define HAVE_SS_FAMILY 1 -#endif -#endif - -#ifndef IOV_MAX -# ifdef UIO_MAXIOV -# define IOV_MAX UIO_MAXIOV -# else -# ifdef __sgi - /* - * IRIX 6.5 has sysconf(_SC_IOV_MAX) - * which might return 512 or bigger - */ -# define IOV_MAX 512 -# else -# error IOV_MAX and UIO_MAXIOV undefined -# endif -# endif -#endif - -#ifndef HAVE_STRUCT_ADDRINFO -#define HAVE_STRUCT_ADDRINFO -struct addrinfo { - int ai_flags; - int ai_family; - int ai_socktype; - int ai_protocol; - socklen_t ai_addrlen; - struct sockaddr *ai_addr; - char *ai_canonname; - struct addrinfo *ai_next; -}; -#endif /* HAVE_STRUCT_ADDRINFO */ - -#if !defined(HAVE_GETADDRINFO) -#include "getaddrinfo.h" -#endif - -/* Needed for some systems that don't define it (Solaris). */ -#ifndef ifr_netmask -#define ifr_netmask ifr_addr -#endif - -/* Some old Linux systems have broken header files */ -#ifdef HAVE_IPV6 -#ifdef HAVE_LINUX_IPV6_V6ONLY_26 -#define IPV6_V6ONLY 26 -#endif /* HAVE_LINUX_IPV6_V6ONLY_26 */ -#endif /* HAVE_IPV6 */ - -#ifdef SOCKET_WRAPPER -#ifndef SOCKET_WRAPPER_DISABLE -#ifndef SOCKET_WRAPPER_NOT_REPLACE -#define SOCKET_WRAPPER_REPLACE -#endif /* SOCKET_WRAPPER_NOT_REPLACE */ -#include "../socket_wrapper/socket_wrapper.h" -#endif /* SOCKET_WRAPPER_DISABLE */ -#endif /* SOCKET_WRAPPER */ - -#endif diff --git a/bundled/replace/system/passwd.h b/bundled/replace/system/passwd.h deleted file mode 100644 index aaea9c83..00000000 --- a/bundled/replace/system/passwd.h +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef _system_passwd_h -#define _system_passwd_h - -/* - Unix SMB/CIFS implementation. - - passwd system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -/* this needs to be included before nss_wrapper.h on some systems */ -#include - -#ifdef HAVE_PWD_H -#include -#endif -#ifdef HAVE_GRP_H -#include -#endif -#ifdef HAVE_SYS_PRIV_H -#include -#endif -#ifdef HAVE_SYS_ID_H -#include -#endif - -#ifdef HAVE_CRYPT_H -#include -#endif - -#ifdef HAVE_SHADOW_H -#include -#endif - -#ifdef HAVE_SYS_SECURITY_H -#include -#include -#define PASSWORD_LENGTH 16 -#endif /* HAVE_SYS_SECURITY_H */ - -#ifdef HAVE_GETPWANAM -#include -#include -#include -#endif - -#ifdef HAVE_COMPAT_H -#include -#endif - -#ifdef REPLACE_GETPASS -#if defined(REPLACE_GETPASS_BY_GETPASSPHRASE) -#define getpass(prompt) getpassphrase(prompt) -#else -#define getpass(prompt) rep_getpass(prompt) -char *rep_getpass(const char *prompt); -#endif -#endif - -#ifndef NGROUPS_MAX -#define NGROUPS_MAX 32 /* Guess... */ -#endif - -/* what is the longest significant password available on your system? - Knowing this speeds up password searches a lot */ -#ifndef PASSWORD_LENGTH -#define PASSWORD_LENGTH 8 -#endif - -#if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS) -#define OSF1_ENH_SEC 1 -#endif - -#ifndef ALLOW_CHANGE_PASSWORD -#if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID)) -#define ALLOW_CHANGE_PASSWORD 1 -#endif -#endif - -#if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID) -#define ULTRIX_AUTH 1 -#endif - -#ifdef NSS_WRAPPER -#ifndef NSS_WRAPPER_DISABLE -#ifndef NSS_WRAPPER_NOT_REPLACE -#define NSS_WRAPPER_REPLACE -#endif /* NSS_WRAPPER_NOT_REPLACE */ -#include "../nss_wrapper/nss_wrapper.h" -#endif /* NSS_WRAPPER_DISABLE */ -#endif /* NSS_WRAPPER */ - -#endif diff --git a/bundled/replace/system/readline.h b/bundled/replace/system/readline.h deleted file mode 100644 index e6b8fb91..00000000 --- a/bundled/replace/system/readline.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef _system_readline_h -#define _system_readline_h -/* - Unix SMB/CIFS implementation. - - Readline wrappers - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#ifdef HAVE_LIBREADLINE -# ifdef HAVE_READLINE_READLINE_H -# include -# ifdef HAVE_READLINE_HISTORY_H -# include -# endif -# else -# ifdef HAVE_READLINE_H -# include -# ifdef HAVE_HISTORY_H -# include -# endif -# else -# undef HAVE_LIBREADLINE -# endif -# endif -#endif - -#ifdef HAVE_NEW_LIBREADLINE -#ifdef HAVE_CPPFUNCTION -# define RL_COMPLETION_CAST (CPPFunction *) -#elif HAVE_RL_COMPLETION_T -# define RL_COMPLETION_CAST (rl_completion_t *) -#else -# define RL_COMPLETION_CAST -#endif -#else -/* This type is missing from libreadline<4.0 (approximately) */ -# define RL_COMPLETION_CAST -#endif /* HAVE_NEW_LIBREADLINE */ - -#endif diff --git a/bundled/replace/system/select.h b/bundled/replace/system/select.h deleted file mode 100644 index da18de0c..00000000 --- a/bundled/replace/system/select.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _system_select_h -#define _system_select_h -/* - Unix SMB/CIFS implementation. - - select system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#ifdef HAVE_SYS_SELECT_H -#include -#endif - -#ifdef HAVE_SYS_EPOLL_H -#include -#endif - -#ifndef SELECT_CAST -#define SELECT_CAST -#endif - -#endif diff --git a/bundled/replace/system/shmem.h b/bundled/replace/system/shmem.h deleted file mode 100644 index 64fe39b6..00000000 --- a/bundled/replace/system/shmem.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef _system_shmem_h -#define _system_shmem_h -/* - Unix SMB/CIFS implementation. - - shared memory system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#if defined(HAVE_SYS_IPC_H) -#include -#endif /* HAVE_SYS_IPC_H */ - -#if defined(HAVE_SYS_SHM_H) -#include -#endif /* HAVE_SYS_SHM_H */ - -#ifdef HAVE_SYS_MMAN_H -#include -#endif - -/* NetBSD doesn't have these */ -#ifndef SHM_R -#define SHM_R 0400 -#endif - -#ifndef SHM_W -#define SHM_W 0200 -#endif - - -#ifndef MAP_FILE -#define MAP_FILE 0 -#endif - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *)-1) -#endif - -#endif diff --git a/bundled/replace/system/syslog.h b/bundled/replace/system/syslog.h deleted file mode 100644 index 104be1df..00000000 --- a/bundled/replace/system/syslog.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _system_syslog_h -#define _system_syslog_h -/* - Unix SMB/CIFS implementation. - - syslog system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#ifdef HAVE_SYSLOG_H -#include -#else -#ifdef HAVE_SYS_SYSLOG_H -#include -#endif -#endif - -/* For sys_adminlog(). */ -#ifndef LOG_EMERG -#define LOG_EMERG 0 /* system is unusable */ -#endif - -#ifndef LOG_ALERT -#define LOG_ALERT 1 /* action must be taken immediately */ -#endif - -#ifndef LOG_CRIT -#define LOG_CRIT 2 /* critical conditions */ -#endif - -#ifndef LOG_ERR -#define LOG_ERR 3 /* error conditions */ -#endif - -#ifndef LOG_WARNING -#define LOG_WARNING 4 /* warning conditions */ -#endif - -#ifndef LOG_NOTICE -#define LOG_NOTICE 5 /* normal but significant condition */ -#endif - -#ifndef LOG_INFO -#define LOG_INFO 6 /* informational */ -#endif - -#ifndef LOG_DEBUG -#define LOG_DEBUG 7 /* debug-level messages */ -#endif - -#endif diff --git a/bundled/replace/system/terminal.h b/bundled/replace/system/terminal.h deleted file mode 100644 index 9ad601ac..00000000 --- a/bundled/replace/system/terminal.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef _system_terminal_h -#define _system_terminal_h -/* - Unix SMB/CIFS implementation. - - terminal system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#ifdef SUNOS4 -/* on SUNOS4 termios.h conflicts with sys/ioctl.h */ -#undef HAVE_TERMIOS_H -#endif - - -#if defined(HAVE_TERMIOS_H) -/* POSIX terminal handling. */ -#include -#elif defined(HAVE_TERMIO_H) -/* Older SYSV terminal handling - don't use if we can avoid it. */ -#include -#elif defined(HAVE_SYS_TERMIO_H) -/* Older SYSV terminal handling - don't use if we can avoid it. */ -#include -#endif - -#endif diff --git a/bundled/replace/system/time.h b/bundled/replace/system/time.h deleted file mode 100644 index 4abf295d..00000000 --- a/bundled/replace/system/time.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _system_time_h -#define _system_time_h -/* - Unix SMB/CIFS implementation. - - time system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#ifdef TIME_WITH_SYS_TIME -#include -#include -#else -#ifdef HAVE_SYS_TIME_H -#include -#else -#include -#endif -#endif - -#ifdef HAVE_UTIME_H -#include -#else -struct utimbuf { - time_t actime; /* access time */ - time_t modtime; /* modification time */ -}; -#endif - -#ifndef HAVE_MKTIME -/* define is in "replace.h" */ -time_t rep_mktime(struct tm *t); -#endif - -#ifndef HAVE_TIMEGM -/* define is in "replace.h" */ -time_t rep_timegm(struct tm *tm); -#endif - -#ifndef HAVE_UTIME -/* define is in "replace.h" */ -int rep_utime(const char *filename, const struct utimbuf *buf); -#endif - -#ifndef HAVE_UTIMES -/* define is in "replace.h" */ -int rep_utimes(const char *filename, const struct timeval tv[2]); -#endif - -#endif diff --git a/bundled/replace/system/wait.h b/bundled/replace/system/wait.h deleted file mode 100644 index 41db1806..00000000 --- a/bundled/replace/system/wait.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _system_wait_h -#define _system_wait_h -/* - Unix SMB/CIFS implementation. - - waitpid system include wrappers - - Copyright (C) Andrew Tridgell 2004 - - ** NOTE! The following LGPL license applies to the replace - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - -*/ - -#ifdef HAVE_SYS_WAIT_H -#include -#endif - -#include - -#ifndef SIGCLD -#define SIGCLD SIGCHLD -#endif - -#ifdef HAVE_SETJMP_H -#include -#endif - -#ifndef SA_RESETHAND -#define SA_RESETHAND SA_ONESHOT -#endif - -#if !defined(HAVE_SIG_ATOMIC_T_TYPE) -typedef int sig_atomic_t; -#endif - -#if !defined(HAVE_WAITPID) && defined(HAVE_WAIT4) -int rep_waitpid(pid_t pid,int *status,int options) -#endif - -#endif diff --git a/bundled/replace/system/wscript_configure b/bundled/replace/system/wscript_configure deleted file mode 100644 index 2035474b..00000000 --- a/bundled/replace/system/wscript_configure +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python - -conf.CHECK_HEADERS('sys/capability.h') -conf.CHECK_FUNCS('getpwnam_r getpwuid_r getpwent_r') - -# solaris varients of getXXent_r -conf.CHECK_C_PROTOTYPE('getpwent_r', - 'struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)', - define='SOLARIS_GETPWENT_R', headers='pwd.h') -conf.CHECK_C_PROTOTYPE('getgrent_r', - 'struct group *getgrent_r(struct group *src, char *buf, int buflen)', - define='SOLARIS_GETGRENT_R', headers='grp.h') - -# the irix varients -conf.CHECK_C_PROTOTYPE('getpwent_r', - 'struct passwd *getpwent_r(struct passwd *src, char *buf, size_t buflen)', - define='SOLARIS_GETPWENT_R', headers='pwd.h') -conf.CHECK_C_PROTOTYPE('getgrent_r', - 'struct group *getgrent_r(struct group *src, char *buf, size_t buflen)', - define='SOLARIS_GETGRENT_R', headers='grp.h') - -conf.CHECK_FUNCS('getgrouplist') -conf.CHECK_HEADERS('ctype.h locale.h langinfo.h') -conf.CHECK_HEADERS('fnmatch.h locale.h langinfo.h') -conf.CHECK_HEADERS('sys/ipc.h sys/mman.h sys/shm.h') -conf.CHECK_HEADERS('termios.h termio.h sys/termio.h') diff --git a/bundled/replace/test/getifaddrs.c b/bundled/replace/test/getifaddrs.c deleted file mode 100644 index 8b00ac2f..00000000 --- a/bundled/replace/test/getifaddrs.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * - * libreplace getifaddrs test - * - * Copyright (C) Michael Adam 2008 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef AUTOCONF_TEST -#include "replace.h" -#include "system/network.h" -#endif - -#ifdef HAVE_INET_NTOP -#define rep_inet_ntop inet_ntop -#endif - -static const char *format_sockaddr(struct sockaddr *addr, - char *addrstring, - socklen_t addrlen) -{ - const char *result = NULL; - - if (addr->sa_family == AF_INET) { - result = rep_inet_ntop(AF_INET, - &((struct sockaddr_in *)addr)->sin_addr, - addrstring, - addrlen); -#ifdef HAVE_STRUCT_SOCKADDR_IN6 - } else if (addr->sa_family == AF_INET6) { - result = rep_inet_ntop(AF_INET6, - &((struct sockaddr_in6 *)addr)->sin6_addr, - addrstring, - addrlen); -#endif - } - return result; -} - -int getifaddrs_test(void) -{ - struct ifaddrs *ifs = NULL; - struct ifaddrs *ifs_head = NULL; - int ret; - - ret = getifaddrs(&ifs); - ifs_head = ifs; - if (ret != 0) { - fprintf(stderr, "getifaddrs() failed: %s\n", strerror(errno)); - return 1; - } - - while (ifs) { - printf("%-10s ", ifs->ifa_name); - if (ifs->ifa_addr != NULL) { - char addrstring[INET6_ADDRSTRLEN]; - const char *result; - - result = format_sockaddr(ifs->ifa_addr, - addrstring, - sizeof(addrstring)); - if (result != NULL) { - printf("IP=%s ", addrstring); - } - - if (ifs->ifa_netmask != NULL) { - result = format_sockaddr(ifs->ifa_netmask, - addrstring, - sizeof(addrstring)); - if (result != NULL) { - printf("NETMASK=%s", addrstring); - } - } else { - printf("AF=%d ", ifs->ifa_addr->sa_family); - } - } else { - printf(""); - } - - printf("\n"); - ifs = ifs->ifa_next; - } - - freeifaddrs(ifs_head); - - return 0; -} diff --git a/bundled/replace/test/main.c b/bundled/replace/test/main.c deleted file mode 100644 index 9bd12840..00000000 --- a/bundled/replace/test/main.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - libreplace tests - - Copyright (C) Jelmer Vernooij 2006 - - ** NOTE! The following LGPL license applies to the talloc - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "replace.h" - -struct torture_context; -bool torture_local_replace(struct torture_context *ctx); - -int main(void) -{ - bool ret = torture_local_replace(NULL); - if (ret) - return 0; - return -1; -} diff --git a/bundled/replace/test/os2_delete.c b/bundled/replace/test/os2_delete.c deleted file mode 100644 index 8b528370..00000000 --- a/bundled/replace/test/os2_delete.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - test readdir/unlink pattern that OS/2 uses - tridge@samba.org July 2005 -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define NUM_FILES 700 -#define READDIR_SIZE 100 -#define DELETE_SIZE 4 - -#define TESTDIR "test.dir" - -static int test_readdir_os2_delete_ret; - -#define FAILED(d) (printf("failure: readdir [\nFailed for %s - %d = %s\n]\n", d, errno, strerror(errno)), test_readdir_os2_delete_ret = 1, 1) - -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif - -#ifdef _WIN32 -#define mkdir(d,m) _mkdir(d) -#endif - -static void cleanup(void) -{ - /* I'm a lazy bastard */ - if (system("rm -rf " TESTDIR)) { - FAILED("system"); - } - mkdir(TESTDIR, 0700) == 0 || FAILED("mkdir"); -} - -static void create_files(void) -{ - int i; - for (i=0;id_name); - } - - if (i == 0) { - return 0; - } - - /* delete the first few */ - for (j=0; jd_name, ".") == 0 || FAILED("match ."); - de = readdir(d); - strcmp(de->d_name, "..") == 0 || FAILED("match .."); - - while (1) { - int n = os2_delete(d); - if (n == 0) break; - total_deleted += n; - } - closedir(d); - - fprintf(stderr, "Deleted %d files of %d\n", total_deleted, NUM_FILES); - - rmdir(TESTDIR) == 0 || FAILED("rmdir"); - - if (system("rm -rf " TESTDIR) == -1) { - FAILED("system"); - } - - return test_readdir_os2_delete_ret; -} diff --git a/bundled/replace/test/shared_mmap.c b/bundled/replace/test/shared_mmap.c deleted file mode 100644 index 50dad8d6..00000000 --- a/bundled/replace/test/shared_mmap.c +++ /dev/null @@ -1,68 +0,0 @@ -/* this tests whether we can use a shared writeable mmap on a file - - as needed for the mmap variant of FAST_SHARE_MODES */ - -#if defined(HAVE_UNISTD_H) -#include -#endif -#include -#include -#include -#include - -#define DATA "conftest.mmap" - -#ifndef MAP_FILE -#define MAP_FILE 0 -#endif - -main() -{ - int *buf; - int i; - int fd = open(DATA,O_RDWR|O_CREAT|O_TRUNC,0666); - int count=7; - - if (fd == -1) exit(1); - - for (i=0;i<10000;i++) { - write(fd,&i,sizeof(i)); - } - - close(fd); - - if (fork() == 0) { - fd = open(DATA,O_RDWR); - if (fd == -1) exit(1); - - buf = (int *)mmap(NULL, 10000*sizeof(int), - (PROT_READ | PROT_WRITE), - MAP_FILE | MAP_SHARED, - fd, 0); - - while (count-- && buf[9124] != 55732) sleep(1); - - if (count <= 0) exit(1); - - buf[1763] = 7268; - exit(0); - } - - fd = open(DATA,O_RDWR); - if (fd == -1) exit(1); - - buf = (int *)mmap(NULL, 10000*sizeof(int), - (PROT_READ | PROT_WRITE), - MAP_FILE | MAP_SHARED, - fd, 0); - - if (buf == (int *)-1) exit(1); - - buf[9124] = 55732; - - while (count-- && buf[1763] != 7268) sleep(1); - - unlink(DATA); - - if (count > 0) exit(0); - exit(1); -} diff --git a/bundled/replace/test/snprintf.c b/bundled/replace/test/snprintf.c deleted file mode 100644 index d06630bc..00000000 --- a/bundled/replace/test/snprintf.c +++ /dev/null @@ -1,29 +0,0 @@ -void foo(const char *format, ...) -{ - va_list ap; - int len; - char buf[20]; - long long l = 1234567890; - l *= 100; - - va_start(ap, format); - len = vsnprintf(buf, 0, format, ap); - va_end(ap); - if (len != 5) exit(1); - - va_start(ap, format); - len = vsnprintf(0, 0, format, ap); - va_end(ap); - if (len != 5) exit(2); - - if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3); - - if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4); - if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5); - if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6); - if (snprintf(buf, 20, "%s", 0) < 3) exit(7); - - printf("1"); - exit(0); -} -main() { foo("hello"); } diff --git a/bundled/replace/test/strptime.c b/bundled/replace/test/strptime.c deleted file mode 100644 index fade3ecc..00000000 --- a/bundled/replace/test/strptime.c +++ /dev/null @@ -1,172 +0,0 @@ - -#ifdef LIBREPLACE_CONFIGURE_TEST_STRPTIME - -#include -#include -#include - -#define true 1 -#define false 0 - -#ifndef __STRING -#define __STRING(x) #x -#endif - -/* make printf a no-op */ -#define printf if(0) printf - -#else /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */ - -#include "replace.h" -#include "system/time.h" - -#endif /* LIBREPLACE_CONFIGURE_TEST_STRPTIME */ - -int libreplace_test_strptime(void) -{ - const char *s = "20070414101546Z"; - char *ret; - struct tm t, t2; - - memset(&t, 0, sizeof(t)); - memset(&t2, 0, sizeof(t2)); - - printf("test: strptime\n"); - - ret = strptime(s, "%Y%m%d%H%M%S", &t); - if ( ret == NULL ) { - printf("failure: strptime [\n" - "returned NULL\n" - "]\n"); - return false; - } - - if ( *ret != 'Z' ) { - printf("failure: strptime [\n" - "ret doesn't point to 'Z'\n" - "]\n"); - return false; - } - - ret = strptime(s, "%Y%m%d%H%M%SZ", &t2); - if ( ret == NULL ) { - printf("failure: strptime [\n" - "returned NULL with Z\n" - "]\n"); - return false; - } - - if ( *ret != '\0' ) { - printf("failure: strptime [\n" - "ret doesn't point to '\\0'\n" - "]\n"); - return false; - } - -#define CMP_TM_ELEMENT(t1,t2,elem) \ - if (t1.elem != t2.elem) { \ - printf("failure: strptime [\n" \ - "result differs if the format string has a 'Z' at the end\n" \ - "element: %s %d != %d\n" \ - "]\n", \ - __STRING(elen), t1.elem, t2.elem); \ - return false; \ - } - - CMP_TM_ELEMENT(t,t2,tm_sec); - CMP_TM_ELEMENT(t,t2,tm_min); - CMP_TM_ELEMENT(t,t2,tm_hour); - CMP_TM_ELEMENT(t,t2,tm_mday); - CMP_TM_ELEMENT(t,t2,tm_mon); - CMP_TM_ELEMENT(t,t2,tm_year); - CMP_TM_ELEMENT(t,t2,tm_wday); - CMP_TM_ELEMENT(t,t2,tm_yday); - CMP_TM_ELEMENT(t,t2,tm_isdst); - - if (t.tm_sec != 46) { - printf("failure: strptime [\n" - "tm_sec: expected: 46, got: %d\n" - "]\n", - t.tm_sec); - return false; - } - - if (t.tm_min != 15) { - printf("failure: strptime [\n" - "tm_min: expected: 15, got: %d\n" - "]\n", - t.tm_min); - return false; - } - - if (t.tm_hour != 10) { - printf("failure: strptime [\n" - "tm_hour: expected: 10, got: %d\n" - "]\n", - t.tm_hour); - return false; - } - - if (t.tm_mday != 14) { - printf("failure: strptime [\n" - "tm_mday: expected: 14, got: %d\n" - "]\n", - t.tm_mday); - return false; - } - - if (t.tm_mon != 3) { - printf("failure: strptime [\n" - "tm_mon: expected: 3, got: %d\n" - "]\n", - t.tm_mon); - return false; - } - - if (t.tm_year != 107) { - printf("failure: strptime [\n" - "tm_year: expected: 107, got: %d\n" - "]\n", - t.tm_year); - return false; - } - - if (t.tm_wday != 6) { /* saturday */ - printf("failure: strptime [\n" - "tm_wday: expected: 6, got: %d\n" - "]\n", - t.tm_wday); - return false; - } - - if (t.tm_yday != 103) { - printf("failure: strptime [\n" - "tm_yday: expected: 103, got: %d\n" - "]\n", - t.tm_yday); - return false; - } - - /* we don't test this as it depends on the host configuration - if (t.tm_isdst != 0) { - printf("failure: strptime [\n" - "tm_isdst: expected: 0, got: %d\n" - "]\n", - t.tm_isdst); - return false; - }*/ - - printf("success: strptime\n"); - - return true; -} - -#ifdef LIBREPLACE_CONFIGURE_TEST_STRPTIME -int main (void) -{ - int ret; - ret = libreplace_test_strptime(); - if (ret == false) return 1; - return 0; -} -#endif diff --git a/bundled/replace/test/testsuite.c b/bundled/replace/test/testsuite.c deleted file mode 100644 index 1f242eb2..00000000 --- a/bundled/replace/test/testsuite.c +++ /dev/null @@ -1,1108 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - libreplace tests - - Copyright (C) Jelmer Vernooij 2006 - - ** NOTE! The following LGPL license applies to the talloc - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "replace.h" - -/* - we include all the system/ include files here so that libreplace tests - them in the build farm -*/ -#include "system/capability.h" -#include "system/dir.h" -#include "system/filesys.h" -#include "system/glob.h" -#include "system/iconv.h" -#include "system/locale.h" -#include "system/network.h" -#include "system/passwd.h" -#include "system/readline.h" -#include "system/select.h" -#include "system/shmem.h" -#include "system/syslog.h" -#include "system/terminal.h" -#include "system/time.h" -#include "system/wait.h" -#include "system/aio.h" - -#define TESTFILE "testfile.dat" - -/* - test ftruncate() function - */ -static int test_ftruncate(void) -{ - struct stat st; - int fd; - const int size = 1234; - printf("test: ftruncate\n"); - unlink(TESTFILE); - fd = open(TESTFILE, O_RDWR|O_CREAT, 0600); - if (fd == -1) { - printf("failure: ftruncate [\n" - "creating '%s' failed - %s\n]\n", TESTFILE, strerror(errno)); - return false; - } - if (ftruncate(fd, size) != 0) { - printf("failure: ftruncate [\n%s\n]\n", strerror(errno)); - return false; - } - if (fstat(fd, &st) != 0) { - printf("failure: ftruncate [\nfstat failed - %s\n]\n", strerror(errno)); - return false; - } - if (st.st_size != size) { - printf("failure: ftruncate [\ngave wrong size %d - expected %d\n]\n", - (int)st.st_size, size); - return false; - } - unlink(TESTFILE); - printf("success: ftruncate\n"); - return true; -} - -/* - test strlcpy() function. - see http://www.gratisoft.us/todd/papers/strlcpy.html - */ -static int test_strlcpy(void) -{ - char buf[4]; - const struct { - const char *src; - size_t result; - } tests[] = { - { "abc", 3 }, - { "abcdef", 6 }, - { "abcd", 4 }, - { "", 0 }, - { NULL, 0 } - }; - int i; - printf("test: strlcpy\n"); - for (i=0;tests[i].src;i++) { - if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) { - printf("failure: strlcpy [\ntest %d failed\n]\n", i); - return false; - } - } - printf("success: strlcpy\n"); - return true; -} - -static int test_strlcat(void) -{ - char tmp[10]; - printf("test: strlcat\n"); - strlcpy(tmp, "", sizeof(tmp)); - if (strlcat(tmp, "bla", 3) != 3) { - printf("failure: strlcat [\ninvalid return code\n]\n"); - return false; - } - if (strcmp(tmp, "bl") != 0) { - printf("failure: strlcat [\nexpected \"bl\", got \"%s\"\n]\n", - tmp); - return false; - } - - strlcpy(tmp, "da", sizeof(tmp)); - if (strlcat(tmp, "me", 4) != 4) { - printf("failure: strlcat [\nexpected \"dam\", got \"%s\"\n]\n", - tmp); - return false; - } - - printf("success: strlcat\n"); - return true; -} - -static int test_mktime(void) -{ - /* FIXME */ - return true; -} - -static int test_initgroups(void) -{ - /* FIXME */ - return true; -} - -static int test_memmove(void) -{ - /* FIXME */ - return true; -} - -static int test_strdup(void) -{ - char *x; - printf("test: strdup\n"); - x = strdup("bla"); - if (strcmp("bla", x) != 0) { - printf("failure: strdup [\nfailed: expected \"bla\", got \"%s\"\n]\n", - x); - return false; - } - free(x); - printf("success: strdup\n"); - return true; -} - -static int test_setlinebuf(void) -{ - printf("test: setlinebuf\n"); - setlinebuf(stdout); - printf("success: setlinebuf\n"); - return true; -} - -static int test_vsyslog(void) -{ - /* FIXME */ - return true; -} - -static int test_timegm(void) -{ - /* FIXME */ - return true; -} - -static int test_setenv(void) -{ -#define TEST_SETENV(key, value, overwrite, result) do { \ - int _ret; \ - char *_v; \ - _ret = setenv(key, value, overwrite); \ - if (_ret != 0) { \ - printf("failure: setenv [\n" \ - "setenv(%s, %s, %d) failed\n" \ - "]\n", \ - key, value, overwrite); \ - return false; \ - } \ - _v=getenv(key); \ - if (!_v) { \ - printf("failure: setenv [\n" \ - "getenv(%s) returned NULL\n" \ - "]\n", \ - key); \ - return false; \ - } \ - if (strcmp(result, _v) != 0) { \ - printf("failure: setenv [\n" \ - "getenv(%s): '%s' != '%s'\n" \ - "]\n", \ - key, result, _v); \ - return false; \ - } \ -} while(0) - -#define TEST_UNSETENV(key) do { \ - char *_v; \ - unsetenv(key); \ - _v=getenv(key); \ - if (_v) { \ - printf("failure: setenv [\n" \ - "getenv(%s): NULL != '%s'\n" \ - "]\n", \ - SETENVTEST_KEY, _v); \ - return false; \ - } \ -} while (0) - -#define SETENVTEST_KEY "SETENVTESTKEY" -#define SETENVTEST_VAL "SETENVTESTVAL" - - printf("test: setenv\n"); - TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"1", 0, SETENVTEST_VAL"1"); - TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"2", 0, SETENVTEST_VAL"1"); - TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"3", 1, SETENVTEST_VAL"3"); - TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"4", 1, SETENVTEST_VAL"4"); - TEST_UNSETENV(SETENVTEST_KEY); - TEST_UNSETENV(SETENVTEST_KEY); - TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"5", 0, SETENVTEST_VAL"5"); - TEST_UNSETENV(SETENVTEST_KEY); - TEST_UNSETENV(SETENVTEST_KEY); - printf("success: setenv\n"); - return true; -} - -static int test_strndup(void) -{ - char *x; - printf("test: strndup\n"); - x = strndup("bla", 0); - if (strcmp(x, "") != 0) { - printf("failure: strndup [\ninvalid\n]\n"); - return false; - } - free(x); - x = strndup("bla", 2); - if (strcmp(x, "bl") != 0) { - printf("failure: strndup [\ninvalid\n]\n"); - return false; - } - free(x); - x = strndup("bla", 10); - if (strcmp(x, "bla") != 0) { - printf("failure: strndup [\ninvalid\n]\n"); - return false; - } - free(x); - printf("success: strndup\n"); - return true; -} - -static int test_strnlen(void) -{ - printf("test: strnlen\n"); - if (strnlen("bla", 2) != 2) { - printf("failure: strnlen [\nunexpected length\n]\n"); - return false; - } - - if (strnlen("some text\n", 0) != 0) { - printf("failure: strnlen [\nunexpected length\n]\n"); - return false; - } - - if (strnlen("some text", 20) != 9) { - printf("failure: strnlen [\nunexpected length\n]\n"); - return false; - } - - printf("success: strnlen\n"); - return true; -} - -static int test_waitpid(void) -{ - /* FIXME */ - return true; -} - -static int test_seteuid(void) -{ - /* FIXME */ - return true; -} - -static int test_setegid(void) -{ - /* FIXME */ - return true; -} - -static int test_asprintf(void) -{ - char *x; - printf("test: asprintf\n"); - if (asprintf(&x, "%d", 9) != 1) { - printf("failure: asprintf [\ngenerate asprintf\n]\n"); - return false; - } - if (strcmp(x, "9") != 0) { - printf("failure: asprintf [\ngenerate asprintf\n]\n"); - return false; - } - if (asprintf(&x, "dat%s", "a") != 4) { - printf("failure: asprintf [\ngenerate asprintf\n]\n"); - return false; - } - if (strcmp(x, "data") != 0) { - printf("failure: asprintf [\ngenerate asprintf\n]\n"); - return false; - } - printf("success: asprintf\n"); - return true; -} - -static int test_snprintf(void) -{ - char tmp[10]; - printf("test: snprintf\n"); - if (snprintf(tmp, 3, "foo%d", 9) != 4) { - printf("failure: snprintf [\nsnprintf return code failed\n]\n"); - return false; - } - - if (strcmp(tmp, "fo") != 0) { - printf("failure: snprintf [\nsnprintf failed\n]\n"); - return false; - } - - printf("success: snprintf\n"); - return true; -} - -static int test_vasprintf(void) -{ - /* FIXME */ - return true; -} - -static int test_vsnprintf(void) -{ - /* FIXME */ - return true; -} - -static int test_opendir(void) -{ - /* FIXME */ - return true; -} - -extern int test_readdir_os2_delete(void); - -static int test_readdir(void) -{ - printf("test: readdir\n"); - if (test_readdir_os2_delete() != 0) { - return false; - } - printf("success: readdir\n"); - return true; -} - -static int test_telldir(void) -{ - /* FIXME */ - return true; -} - -static int test_seekdir(void) -{ - /* FIXME */ - return true; -} - -static int test_dlopen(void) -{ - /* FIXME: test dlopen, dlsym, dlclose, dlerror */ - return true; -} - - -static int test_chroot(void) -{ - /* FIXME: chroot() */ - return true; -} - -static int test_bzero(void) -{ - /* FIXME: bzero */ - return true; -} - -static int test_strerror(void) -{ - /* FIXME */ - return true; -} - -static int test_errno(void) -{ - printf("test: errno\n"); - errno = 3; - if (errno != 3) { - printf("failure: errno [\nerrno failed\n]\n"); - return false; - } - - printf("success: errno\n"); - return true; -} - -static int test_mkdtemp(void) -{ - /* FIXME */ - return true; -} - -static int test_mkstemp(void) -{ - /* FIXME */ - return true; -} - -static int test_pread(void) -{ - /* FIXME */ - return true; -} - -static int test_pwrite(void) -{ - /* FIXME */ - return true; -} - -static int test_getpass(void) -{ - /* FIXME */ - return true; -} - -static int test_inet_ntoa(void) -{ - /* FIXME */ - return true; -} - -#define TEST_STRTO_X(type,fmt,func,str,base,res,diff,rrnoo) do {\ - type _v; \ - char _s[64]; \ - char *_p = NULL;\ - char *_ep = NULL; \ - strlcpy(_s, str, sizeof(_s));\ - if (diff >= 0) { \ - _ep = &_s[diff]; \ - } \ - errno = 0; \ - _v = func(_s, &_p, base); \ - if (errno != rrnoo) { \ - printf("failure: %s [\n" \ - "\t%s\n" \ - "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \ - "\terrno: %d != %d\n" \ - "]\n", \ - __STRING(func), __location__, __STRING(func), \ - str, diff, base, res, _v, rrnoo, errno); \ - return false; \ - } else if (_v != res) { \ - printf("failure: %s [\n" \ - "\t%s\n" \ - "\t%s(\"%s\",%d,%d): " fmt " != " fmt "\n" \ - "]\n", \ - __STRING(func), __location__, __STRING(func), \ - str, diff, base, res, _v); \ - return false; \ - } else if (_p != _ep) { \ - printf("failure: %s [\n" \ - "\t%s\n" \ - "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \ - "\tptr: %p - %p = %d != %d\n" \ - "]\n", \ - __STRING(func), __location__, __STRING(func), \ - str, diff, base, res, _v, _ep, _p, (int)(diff - (_ep - _p)), diff); \ - return false; \ - } \ -} while (0) - -static int test_strtoll(void) -{ - printf("test: strtoll\n"); - -#define TEST_STRTOLL(str,base,res,diff,errnoo) TEST_STRTO_X(long long int, "%lld", strtoll,str,base,res,diff,errnoo) - - TEST_STRTOLL("15", 10, 15LL, 2, 0); - TEST_STRTOLL(" 15", 10, 15LL, 4, 0); - TEST_STRTOLL("15", 0, 15LL, 2, 0); - TEST_STRTOLL(" 15 ", 0, 15LL, 3, 0); - TEST_STRTOLL("+15", 10, 15LL, 3, 0); - TEST_STRTOLL(" +15", 10, 15LL, 5, 0); - TEST_STRTOLL("+15", 0, 15LL, 3, 0); - TEST_STRTOLL(" +15 ", 0, 15LL, 4, 0); - TEST_STRTOLL("-15", 10, -15LL, 3, 0); - TEST_STRTOLL(" -15", 10, -15LL, 5, 0); - TEST_STRTOLL("-15", 0, -15LL, 3, 0); - TEST_STRTOLL(" -15 ", 0, -15LL, 4, 0); - TEST_STRTOLL("015", 10, 15LL, 3, 0); - TEST_STRTOLL(" 015", 10, 15LL, 5, 0); - TEST_STRTOLL("015", 0, 13LL, 3, 0); - TEST_STRTOLL(" 015", 0, 13LL, 5, 0); - TEST_STRTOLL("0x15", 10, 0LL, 1, 0); - TEST_STRTOLL(" 0x15", 10, 0LL, 3, 0); - TEST_STRTOLL("0x15", 0, 21LL, 4, 0); - TEST_STRTOLL(" 0x15", 0, 21LL, 6, 0); - - TEST_STRTOLL("10", 16, 16LL, 2, 0); - TEST_STRTOLL(" 10 ", 16, 16LL, 4, 0); - TEST_STRTOLL("0x10", 16, 16LL, 4, 0); - TEST_STRTOLL("0x10", 0, 16LL, 4, 0); - TEST_STRTOLL(" 0x10 ", 0, 16LL, 5, 0); - TEST_STRTOLL("+10", 16, 16LL, 3, 0); - TEST_STRTOLL(" +10 ", 16, 16LL, 5, 0); - TEST_STRTOLL("+0x10", 16, 16LL, 5, 0); - TEST_STRTOLL("+0x10", 0, 16LL, 5, 0); - TEST_STRTOLL(" +0x10 ", 0, 16LL, 6, 0); - TEST_STRTOLL("-10", 16, -16LL, 3, 0); - TEST_STRTOLL(" -10 ", 16, -16LL, 5, 0); - TEST_STRTOLL("-0x10", 16, -16LL, 5, 0); - TEST_STRTOLL("-0x10", 0, -16LL, 5, 0); - TEST_STRTOLL(" -0x10 ", 0, -16LL, 6, 0); - TEST_STRTOLL("010", 16, 16LL, 3, 0); - TEST_STRTOLL(" 010 ", 16, 16LL, 5, 0); - TEST_STRTOLL("-010", 16, -16LL, 4, 0); - - TEST_STRTOLL("11", 8, 9LL, 2, 0); - TEST_STRTOLL("011", 8, 9LL, 3, 0); - TEST_STRTOLL("011", 0, 9LL, 3, 0); - TEST_STRTOLL("-11", 8, -9LL, 3, 0); - TEST_STRTOLL("-011", 8, -9LL, 4, 0); - TEST_STRTOLL("-011", 0, -9LL, 4, 0); - - TEST_STRTOLL("011", 8, 9LL, 3, 0); - TEST_STRTOLL("011", 0, 9LL, 3, 0); - TEST_STRTOLL("-11", 8, -9LL, 3, 0); - TEST_STRTOLL("-011", 8, -9LL, 4, 0); - TEST_STRTOLL("-011", 0, -9LL, 4, 0); - - TEST_STRTOLL("Text", 0, 0LL, 0, 0); - - TEST_STRTOLL("9223372036854775807", 10, 9223372036854775807LL, 19, 0); - TEST_STRTOLL("9223372036854775807", 0, 9223372036854775807LL, 19, 0); - TEST_STRTOLL("9223372036854775808", 0, 9223372036854775807LL, 19, ERANGE); - TEST_STRTOLL("9223372036854775808", 10, 9223372036854775807LL, 19, ERANGE); - TEST_STRTOLL("0x7FFFFFFFFFFFFFFF", 0, 9223372036854775807LL, 18, 0); - TEST_STRTOLL("0x7FFFFFFFFFFFFFFF", 16, 9223372036854775807LL, 18, 0); - TEST_STRTOLL("7FFFFFFFFFFFFFFF", 16, 9223372036854775807LL, 16, 0); - TEST_STRTOLL("0x8000000000000000", 0, 9223372036854775807LL, 18, ERANGE); - TEST_STRTOLL("0x8000000000000000", 16, 9223372036854775807LL, 18, ERANGE); - TEST_STRTOLL("80000000000000000", 16, 9223372036854775807LL, 17, ERANGE); - TEST_STRTOLL("0777777777777777777777", 0, 9223372036854775807LL, 22, 0); - TEST_STRTOLL("0777777777777777777777", 8, 9223372036854775807LL, 22, 0); - TEST_STRTOLL("777777777777777777777", 8, 9223372036854775807LL, 21, 0); - TEST_STRTOLL("01000000000000000000000", 0, 9223372036854775807LL, 23, ERANGE); - TEST_STRTOLL("01000000000000000000000", 8, 9223372036854775807LL, 23, ERANGE); - TEST_STRTOLL("1000000000000000000000", 8, 9223372036854775807LL, 22, ERANGE); - - TEST_STRTOLL("-9223372036854775808", 10, -9223372036854775807LL -1, 20, 0); - TEST_STRTOLL("-9223372036854775808", 0, -9223372036854775807LL -1, 20, 0); - TEST_STRTOLL("-9223372036854775809", 0, -9223372036854775807LL -1, 20, ERANGE); - TEST_STRTOLL("-9223372036854775809", 10, -9223372036854775807LL -1, 20, ERANGE); - TEST_STRTOLL("-0x8000000000000000", 0, -9223372036854775807LL -1, 19, 0); - TEST_STRTOLL("-0x8000000000000000", 16, -9223372036854775807LL -1, 19, 0); - TEST_STRTOLL("-8000000000000000", 16, -9223372036854775807LL -1, 17, 0); - TEST_STRTOLL("-0x8000000000000001", 0, -9223372036854775807LL -1, 19, ERANGE); - TEST_STRTOLL("-0x8000000000000001", 16, -9223372036854775807LL -1, 19, ERANGE); - TEST_STRTOLL("-80000000000000001", 16, -9223372036854775807LL -1, 18, ERANGE); - TEST_STRTOLL("-01000000000000000000000",0, -9223372036854775807LL -1, 24, 0); - TEST_STRTOLL("-01000000000000000000000",8, -9223372036854775807LL -1, 24, 0); - TEST_STRTOLL("-1000000000000000000000", 8, -9223372036854775807LL -1, 23, 0); - TEST_STRTOLL("-01000000000000000000001",0, -9223372036854775807LL -1, 24, ERANGE); - TEST_STRTOLL("-01000000000000000000001",8, -9223372036854775807LL -1, 24, ERANGE); - TEST_STRTOLL("-1000000000000000000001", 8, -9223372036854775807LL -1, 23, ERANGE); - - printf("success: strtoll\n"); - return true; -} - -static int test_strtoull(void) -{ - printf("test: strtoull\n"); - -#define TEST_STRTOULL(str,base,res,diff,errnoo) TEST_STRTO_X(long long unsigned int,"%llu",strtoull,str,base,res,diff,errnoo) - - TEST_STRTOULL("15", 10, 15LLU, 2, 0); - TEST_STRTOULL(" 15", 10, 15LLU, 4, 0); - TEST_STRTOULL("15", 0, 15LLU, 2, 0); - TEST_STRTOULL(" 15 ", 0, 15LLU, 3, 0); - TEST_STRTOULL("+15", 10, 15LLU, 3, 0); - TEST_STRTOULL(" +15", 10, 15LLU, 5, 0); - TEST_STRTOULL("+15", 0, 15LLU, 3, 0); - TEST_STRTOULL(" +15 ", 0, 15LLU, 4, 0); - TEST_STRTOULL("-15", 10, 18446744073709551601LLU, 3, 0); - TEST_STRTOULL(" -15", 10, 18446744073709551601LLU, 5, 0); - TEST_STRTOULL("-15", 0, 18446744073709551601LLU, 3, 0); - TEST_STRTOULL(" -15 ", 0, 18446744073709551601LLU, 4, 0); - TEST_STRTOULL("015", 10, 15LLU, 3, 0); - TEST_STRTOULL(" 015", 10, 15LLU, 5, 0); - TEST_STRTOULL("015", 0, 13LLU, 3, 0); - TEST_STRTOULL(" 015", 0, 13LLU, 5, 0); - TEST_STRTOULL("0x15", 10, 0LLU, 1, 0); - TEST_STRTOULL(" 0x15", 10, 0LLU, 3, 0); - TEST_STRTOULL("0x15", 0, 21LLU, 4, 0); - TEST_STRTOULL(" 0x15", 0, 21LLU, 6, 0); - - TEST_STRTOULL("10", 16, 16LLU, 2, 0); - TEST_STRTOULL(" 10 ", 16, 16LLU, 4, 0); - TEST_STRTOULL("0x10", 16, 16LLU, 4, 0); - TEST_STRTOULL("0x10", 0, 16LLU, 4, 0); - TEST_STRTOULL(" 0x10 ", 0, 16LLU, 5, 0); - TEST_STRTOULL("+10", 16, 16LLU, 3, 0); - TEST_STRTOULL(" +10 ", 16, 16LLU, 5, 0); - TEST_STRTOULL("+0x10", 16, 16LLU, 5, 0); - TEST_STRTOULL("+0x10", 0, 16LLU, 5, 0); - TEST_STRTOULL(" +0x10 ", 0, 16LLU, 6, 0); - TEST_STRTOULL("-10", 16, -16LLU, 3, 0); - TEST_STRTOULL(" -10 ", 16, -16LLU, 5, 0); - TEST_STRTOULL("-0x10", 16, -16LLU, 5, 0); - TEST_STRTOULL("-0x10", 0, -16LLU, 5, 0); - TEST_STRTOULL(" -0x10 ", 0, -16LLU, 6, 0); - TEST_STRTOULL("010", 16, 16LLU, 3, 0); - TEST_STRTOULL(" 010 ", 16, 16LLU, 5, 0); - TEST_STRTOULL("-010", 16, -16LLU, 4, 0); - - TEST_STRTOULL("11", 8, 9LLU, 2, 0); - TEST_STRTOULL("011", 8, 9LLU, 3, 0); - TEST_STRTOULL("011", 0, 9LLU, 3, 0); - TEST_STRTOULL("-11", 8, -9LLU, 3, 0); - TEST_STRTOULL("-011", 8, -9LLU, 4, 0); - TEST_STRTOULL("-011", 0, -9LLU, 4, 0); - - TEST_STRTOULL("011", 8, 9LLU, 3, 0); - TEST_STRTOULL("011", 0, 9LLU, 3, 0); - TEST_STRTOULL("-11", 8, -9LLU, 3, 0); - TEST_STRTOULL("-011", 8, -9LLU, 4, 0); - TEST_STRTOULL("-011", 0, -9LLU, 4, 0); - - TEST_STRTOULL("Text", 0, 0LLU, 0, 0); - - TEST_STRTOULL("9223372036854775807", 10, 9223372036854775807LLU, 19, 0); - TEST_STRTOULL("9223372036854775807", 0, 9223372036854775807LLU, 19, 0); - TEST_STRTOULL("9223372036854775808", 0, 9223372036854775808LLU, 19, 0); - TEST_STRTOULL("9223372036854775808", 10, 9223372036854775808LLU, 19, 0); - TEST_STRTOULL("0x7FFFFFFFFFFFFFFF", 0, 9223372036854775807LLU, 18, 0); - TEST_STRTOULL("0x7FFFFFFFFFFFFFFF", 16, 9223372036854775807LLU, 18, 0); - TEST_STRTOULL("7FFFFFFFFFFFFFFF", 16, 9223372036854775807LLU, 16, 0); - TEST_STRTOULL("0x8000000000000000", 0, 9223372036854775808LLU, 18, 0); - TEST_STRTOULL("0x8000000000000000", 16, 9223372036854775808LLU, 18, 0); - TEST_STRTOULL("8000000000000000", 16, 9223372036854775808LLU, 16, 0); - TEST_STRTOULL("0777777777777777777777", 0, 9223372036854775807LLU, 22, 0); - TEST_STRTOULL("0777777777777777777777", 8, 9223372036854775807LLU, 22, 0); - TEST_STRTOULL("777777777777777777777", 8, 9223372036854775807LLU, 21, 0); - TEST_STRTOULL("01000000000000000000000",0, 9223372036854775808LLU, 23, 0); - TEST_STRTOULL("01000000000000000000000",8, 9223372036854775808LLU, 23, 0); - TEST_STRTOULL("1000000000000000000000", 8, 9223372036854775808LLU, 22, 0); - - TEST_STRTOULL("-9223372036854775808", 10, 9223372036854775808LLU, 20, 0); - TEST_STRTOULL("-9223372036854775808", 0, 9223372036854775808LLU, 20, 0); - TEST_STRTOULL("-9223372036854775809", 0, 9223372036854775807LLU, 20, 0); - TEST_STRTOULL("-9223372036854775809", 10, 9223372036854775807LLU, 20, 0); - TEST_STRTOULL("-0x8000000000000000", 0, 9223372036854775808LLU, 19, 0); - TEST_STRTOULL("-0x8000000000000000", 16, 9223372036854775808LLU, 19, 0); - TEST_STRTOULL("-8000000000000000", 16, 9223372036854775808LLU, 17, 0); - TEST_STRTOULL("-0x8000000000000001", 0, 9223372036854775807LLU, 19, 0); - TEST_STRTOULL("-0x8000000000000001", 16, 9223372036854775807LLU, 19, 0); - TEST_STRTOULL("-8000000000000001", 16, 9223372036854775807LLU, 17, 0); - TEST_STRTOULL("-01000000000000000000000",0, 9223372036854775808LLU, 24, 0); - TEST_STRTOULL("-01000000000000000000000",8, 9223372036854775808LLU, 24, 0); - TEST_STRTOULL("-1000000000000000000000",8, 9223372036854775808LLU, 23, 0); - TEST_STRTOULL("-01000000000000000000001",0, 9223372036854775807LLU, 24, 0); - TEST_STRTOULL("-01000000000000000000001",8, 9223372036854775807LLU, 24, 0); - TEST_STRTOULL("-1000000000000000000001",8, 9223372036854775807LLU, 23, 0); - - TEST_STRTOULL("18446744073709551615", 0, 18446744073709551615LLU, 20, 0); - TEST_STRTOULL("18446744073709551615", 10, 18446744073709551615LLU, 20, 0); - TEST_STRTOULL("18446744073709551616", 0, 18446744073709551615LLU, 20, ERANGE); - TEST_STRTOULL("18446744073709551616", 10, 18446744073709551615LLU, 20, ERANGE); - TEST_STRTOULL("0xFFFFFFFFFFFFFFFF", 0, 18446744073709551615LLU, 18, 0); - TEST_STRTOULL("0xFFFFFFFFFFFFFFFF", 16, 18446744073709551615LLU, 18, 0); - TEST_STRTOULL("FFFFFFFFFFFFFFFF", 16, 18446744073709551615LLU, 16, 0); - TEST_STRTOULL("0x10000000000000000", 0, 18446744073709551615LLU, 19, ERANGE); - TEST_STRTOULL("0x10000000000000000", 16, 18446744073709551615LLU, 19, ERANGE); - TEST_STRTOULL("10000000000000000", 16, 18446744073709551615LLU, 17, ERANGE); - TEST_STRTOULL("01777777777777777777777",0, 18446744073709551615LLU, 23, 0); - TEST_STRTOULL("01777777777777777777777",8, 18446744073709551615LLU, 23, 0); - TEST_STRTOULL("1777777777777777777777", 8, 18446744073709551615LLU, 22, 0); - TEST_STRTOULL("02000000000000000000000",0, 18446744073709551615LLU, 23, ERANGE); - TEST_STRTOULL("02000000000000000000000",8, 18446744073709551615LLU, 23, ERANGE); - TEST_STRTOULL("2000000000000000000000", 8, 18446744073709551615LLU, 22, ERANGE); - - TEST_STRTOULL("-18446744073709551615", 0, 1LLU, 21, 0); - TEST_STRTOULL("-18446744073709551615", 10, 1LLU, 21, 0); - TEST_STRTOULL("-18446744073709551616", 0, 18446744073709551615LLU, 21, ERANGE); - TEST_STRTOULL("-18446744073709551616", 10, 18446744073709551615LLU, 21, ERANGE); - TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF", 0, 1LLU, 19, 0); - TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF", 16, 1LLU, 19, 0); - TEST_STRTOULL("-FFFFFFFFFFFFFFFF", 16, 1LLU, 17, 0); - TEST_STRTOULL("-0x10000000000000000", 0, 18446744073709551615LLU, 20, ERANGE); - TEST_STRTOULL("-0x10000000000000000", 16, 18446744073709551615LLU, 20, ERANGE); - TEST_STRTOULL("-10000000000000000", 16, 18446744073709551615LLU, 18, ERANGE); - TEST_STRTOULL("-01777777777777777777777",0, 1LLU, 24, 0); - TEST_STRTOULL("-01777777777777777777777",8, 1LLU, 24, 0); - TEST_STRTOULL("-1777777777777777777777",8, 1LLU, 23, 0); - TEST_STRTOULL("-02000000000000000000000",0, 18446744073709551615LLU, 24, ERANGE); - TEST_STRTOULL("-02000000000000000000000",8, 18446744073709551615LLU, 24, ERANGE); - TEST_STRTOULL("-2000000000000000000000",8, 18446744073709551615LLU, 23, ERANGE); - - printf("success: strtoull\n"); - return true; -} - -/* -FIXME: -Types: -bool -socklen_t -uint{8,16,32,64}_t -int{8,16,32,64}_t -intptr_t - -Constants: -PATH_NAME_MAX -UINT{16,32,64}_MAX -INT32_MAX -*/ - -static int test_va_copy(void) -{ - /* FIXME */ - return true; -} - -static int test_FUNCTION(void) -{ - printf("test: FUNCTION\n"); - if (strcmp(__FUNCTION__, "test_FUNCTION") != 0) { - printf("failure: FAILURE [\nFAILURE invalid\n]\n"); - return false; - } - printf("success: FUNCTION\n"); - return true; -} - -static int test_MIN(void) -{ - printf("test: MIN\n"); - if (MIN(20, 1) != 1) { - printf("failure: MIN [\nMIN invalid\n]\n"); - return false; - } - if (MIN(1, 20) != 1) { - printf("failure: MIN [\nMIN invalid\n]\n"); - return false; - } - printf("success: MIN\n"); - return true; -} - -static int test_MAX(void) -{ - printf("test: MAX\n"); - if (MAX(20, 1) != 20) { - printf("failure: MAX [\nMAX invalid\n]\n"); - return false; - } - if (MAX(1, 20) != 20) { - printf("failure: MAX [\nMAX invalid\n]\n"); - return false; - } - printf("success: MAX\n"); - return true; -} - -static int test_socketpair(void) -{ - int sock[2]; - char buf[20]; - - printf("test: socketpair\n"); - - if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) { - printf("failure: socketpair [\n" - "socketpair() failed\n" - "]\n"); - return false; - } - - if (write(sock[1], "automatisch", 12) == -1) { - printf("failure: socketpair [\n" - "write() failed: %s\n" - "]\n", strerror(errno)); - return false; - } - - if (read(sock[0], buf, 12) == -1) { - printf("failure: socketpair [\n" - "read() failed: %s\n" - "]\n", strerror(errno)); - return false; - } - - if (strcmp(buf, "automatisch") != 0) { - printf("failure: socketpair [\n" - "expected: automatisch, got: %s\n" - "]\n", buf); - return false; - } - - printf("success: socketpair\n"); - - return true; -} - -extern int libreplace_test_strptime(void); - -static int test_strptime(void) -{ - return libreplace_test_strptime(); -} - -extern int getifaddrs_test(void); - -static int test_getifaddrs(void) -{ - - printf("test: getifaddrs\n"); - - if (getifaddrs_test() != 0) { - printf("failure: getifaddrs\n"); - return false; - } - - printf("success: getifaddrs\n"); - return true; -} - -static int test_utime(void) -{ - struct utimbuf u; - struct stat st1, st2, st3; - int fd; - - printf("test: utime\n"); - unlink(TESTFILE); - - fd = open(TESTFILE, O_RDWR|O_CREAT, 0600); - if (fd == -1) { - printf("failure: utime [\n" - "creating '%s' failed - %s\n]\n", - TESTFILE, strerror(errno)); - return false; - } - - if (fstat(fd, &st1) != 0) { - printf("failure: utime [\n" - "fstat (1) failed - %s\n]\n", - strerror(errno)); - return false; - } - - u.actime = st1.st_atime + 300; - u.modtime = st1.st_mtime - 300; - if (utime(TESTFILE, &u) != 0) { - printf("failure: utime [\n" - "utime(&u) failed - %s\n]\n", - strerror(errno)); - return false; - } - - if (fstat(fd, &st2) != 0) { - printf("failure: utime [\n" - "fstat (2) failed - %s\n]\n", - strerror(errno)); - return false; - } - - if (utime(TESTFILE, NULL) != 0) { - printf("failure: utime [\n" - "utime(NULL) failed - %s\n]\n", - strerror(errno)); - return false; - } - - if (fstat(fd, &st3) != 0) { - printf("failure: utime [\n" - "fstat (3) failed - %s\n]\n", - strerror(errno)); - return false; - } - -#define CMP_VAL(a,c,b) do { \ - if (a c b) { \ - printf("failure: utime [\n" \ - "%s: %s(%d) %s %s(%d)\n]\n", \ - __location__, \ - #a, (int)a, #c, #b, (int)b); \ - return false; \ - } \ -} while(0) -#define EQUAL_VAL(a,b) CMP_VAL(a,!=,b) -#define GREATER_VAL(a,b) CMP_VAL(a,<=,b) -#define LESSER_VAL(a,b) CMP_VAL(a,>=,b) - - EQUAL_VAL(st2.st_atime, st1.st_atime + 300); - EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300); - LESSER_VAL(st3.st_atime, st2.st_atime); - GREATER_VAL(st3.st_mtime, st2.st_mtime); - -#undef CMP_VAL -#undef EQUAL_VAL -#undef GREATER_VAL -#undef LESSER_VAL - - unlink(TESTFILE); - printf("success: utime\n"); - return true; -} - -static int test_utimes(void) -{ - struct timeval tv[2]; - struct stat st1, st2; - int fd; - - printf("test: utimes\n"); - unlink(TESTFILE); - - fd = open(TESTFILE, O_RDWR|O_CREAT, 0600); - if (fd == -1) { - printf("failure: utimes [\n" - "creating '%s' failed - %s\n]\n", - TESTFILE, strerror(errno)); - return false; - } - - if (fstat(fd, &st1) != 0) { - printf("failure: utimes [\n" - "fstat (1) failed - %s\n]\n", - strerror(errno)); - return false; - } - - ZERO_STRUCT(tv); - tv[0].tv_sec = st1.st_atime + 300; - tv[1].tv_sec = st1.st_mtime - 300; - if (utimes(TESTFILE, tv) != 0) { - printf("failure: utimes [\n" - "utimes(tv) failed - %s\n]\n", - strerror(errno)); - return false; - } - - if (fstat(fd, &st2) != 0) { - printf("failure: utimes [\n" - "fstat (2) failed - %s\n]\n", - strerror(errno)); - return false; - } - -#define EQUAL_VAL(a,b) do { \ - if (a != b) { \ - printf("failure: utimes [\n" \ - "%s: %s(%d) != %s(%d)\n]\n", \ - __location__, \ - #a, (int)a, #b, (int)b); \ - return false; \ - } \ -} while(0) - - EQUAL_VAL(st2.st_atime, st1.st_atime + 300); - EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300); - -#undef EQUAL_VAL - - unlink(TESTFILE); - printf("success: utimes\n"); - return true; -} - -static int test_memmem(void) -{ - char *s; - - printf("test: memmem\n"); - - s = (char *)memmem("foo", 3, "fo", 2); - if (strcmp(s, "foo") != 0) { - printf(__location__ ": Failed memmem\n"); - return false; - } - - s = (char *)memmem("foo", 3, "", 0); - /* it is allowable for this to return NULL (as happens on - FreeBSD) */ - if (s && strcmp(s, "foo") != 0) { - printf(__location__ ": Failed memmem\n"); - return false; - } - - s = (char *)memmem("foo", 4, "o", 1); - if (strcmp(s, "oo") != 0) { - printf(__location__ ": Failed memmem\n"); - return false; - } - - s = (char *)memmem("foobarfodx", 11, "fod", 3); - if (strcmp(s, "fodx") != 0) { - printf(__location__ ": Failed memmem\n"); - return false; - } - - printf("success: memmem\n"); - - return true; -} - - -struct torture_context; -bool torture_local_replace(struct torture_context *ctx) -{ - bool ret = true; - ret &= test_ftruncate(); - ret &= test_strlcpy(); - ret &= test_strlcat(); - ret &= test_mktime(); - ret &= test_initgroups(); - ret &= test_memmove(); - ret &= test_strdup(); - ret &= test_setlinebuf(); - ret &= test_vsyslog(); - ret &= test_timegm(); - ret &= test_setenv(); - ret &= test_strndup(); - ret &= test_strnlen(); - ret &= test_waitpid(); - ret &= test_seteuid(); - ret &= test_setegid(); - ret &= test_asprintf(); - ret &= test_snprintf(); - ret &= test_vasprintf(); - ret &= test_vsnprintf(); - ret &= test_opendir(); - ret &= test_readdir(); - ret &= test_telldir(); - ret &= test_seekdir(); - ret &= test_dlopen(); - ret &= test_chroot(); - ret &= test_bzero(); - ret &= test_strerror(); - ret &= test_errno(); - ret &= test_mkdtemp(); - ret &= test_mkstemp(); - ret &= test_pread(); - ret &= test_pwrite(); - ret &= test_getpass(); - ret &= test_inet_ntoa(); - ret &= test_strtoll(); - ret &= test_strtoull(); - ret &= test_va_copy(); - ret &= test_FUNCTION(); - ret &= test_MIN(); - ret &= test_MAX(); - ret &= test_socketpair(); - ret &= test_strptime(); - ret &= test_getifaddrs(); - ret &= test_utime(); - ret &= test_utimes(); - ret &= test_memmem(); - - return ret; -} diff --git a/bundled/replace/timegm.c b/bundled/replace/timegm.c deleted file mode 100644 index 395c684e..00000000 --- a/bundled/replace/timegm.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 1997 Kungliga Tekniska Högskolan - * (Royal Institute of Technology, Stockholm, Sweden). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - adapted for Samba4 by Andrew Tridgell -*/ - -#include "replace.h" -#include "system/time.h" - -static int is_leap(unsigned y) -{ - y += 1900; - return (y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0); -} - -time_t rep_timegm(struct tm *tm) -{ - static const unsigned ndays[2][12] ={ - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, - {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}; - time_t res = 0; - unsigned i; - - if (tm->tm_mon > 12 || - tm->tm_mon < 0 || - tm->tm_mday > 31 || - tm->tm_min > 60 || - tm->tm_sec > 60 || - tm->tm_hour > 24) { - /* invalid tm structure */ - return 0; - } - - for (i = 70; i < tm->tm_year; ++i) - res += is_leap(i) ? 366 : 365; - - for (i = 0; i < tm->tm_mon; ++i) - res += ndays[is_leap(tm->tm_year)][i]; - res += tm->tm_mday - 1; - res *= 24; - res += tm->tm_hour; - res *= 60; - res += tm->tm_min; - res *= 60; - res += tm->tm_sec; - return res; -} diff --git a/bundled/replace/timegm.m4 b/bundled/replace/timegm.m4 deleted file mode 100644 index 9b76d0c7..00000000 --- a/bundled/replace/timegm.m4 +++ /dev/null @@ -1 +0,0 @@ -AC_CHECK_FUNCS(timegm,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/timegm.o"]) diff --git a/bundled/replace/win32.m4 b/bundled/replace/win32.m4 deleted file mode 100644 index eb364e2c..00000000 --- a/bundled/replace/win32.m4 +++ /dev/null @@ -1,20 +0,0 @@ -AC_CHECK_HEADERS(direct.h windows.h winsock2.h ws2tcpip.h) - -####################################### -# Check for mkdir mode -AC_CACHE_CHECK( [whether mkdir supports mode], libreplace_cv_mkdir_has_mode, - AC_TRY_COMPILE([ - #include - #ifdef HAVE_DIRECT_H - #include - #endif],[ - mkdir("foo",0777); - return 0; - ], - libreplace_cv_mkdir_has_mode="yes", - libreplace_cv_mkdir_has_mode="no") ) - -if test "$libreplace_cv_mkdir_has_mode" = "yes" -then - AC_DEFINE(HAVE_MKDIR_MODE, 1, [Define if target mkdir supports mode option]) -fi diff --git a/bundled/replace/win32_replace.h b/bundled/replace/win32_replace.h deleted file mode 100644 index 9901e72f..00000000 --- a/bundled/replace/win32_replace.h +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef _WIN32_REPLACE_H -#define _WIN32_REPLACE_H - -#ifdef HAVE_WINSOCK2_H -#include -#endif - -#ifdef HAVE_WS2TCPIP_H -#include -#endif - -#ifdef HAVE_WINDOWS_H -#include -#endif - -/* Map BSD Socket errorcodes to the WSA errorcodes (if possible) */ - -#define EAFNOSUPPORT WSAEAFNOSUPPORT -#define ECONNREFUSED WSAECONNREFUSED -#define EINPROGRESS WSAEINPROGRESS -#define EMSGSIZE WSAEMSGSIZE -#define ENOBUFS WSAENOBUFS -#define ENOTSOCK WSAENOTSOCK -#define ENETUNREACH WSAENETUNREACH -#define ENOPROTOOPT WSAENOPROTOOPT -#define ENOTCONN WSAENOTCONN -#define ENOTSUP 134 - -/* We undefine the following constants due to conflicts with the w32api headers - * and the Windows Platform SDK/DDK. - */ - -#undef interface - -#undef ERROR_INVALID_PARAMETER -#undef ERROR_INSUFFICIENT_BUFFER -#undef ERROR_INVALID_DATATYPE - -#undef FILE_GENERIC_READ -#undef FILE_GENERIC_WRITE -#undef FILE_GENERIC_EXECUTE -#undef FILE_ATTRIBUTE_READONLY -#undef FILE_ATTRIBUTE_HIDDEN -#undef FILE_ATTRIBUTE_SYSTEM -#undef FILE_ATTRIBUTE_DIRECTORY -#undef FILE_ATTRIBUTE_ARCHIVE -#undef FILE_ATTRIBUTE_DEVICE -#undef FILE_ATTRIBUTE_NORMAL -#undef FILE_ATTRIBUTE_TEMPORARY -#undef FILE_ATTRIBUTE_REPARSE_POINT -#undef FILE_ATTRIBUTE_COMPRESSED -#undef FILE_ATTRIBUTE_OFFLINE -#undef FILE_ATTRIBUTE_ENCRYPTED -#undef FILE_FLAG_WRITE_THROUGH -#undef FILE_FLAG_NO_BUFFERING -#undef FILE_FLAG_RANDOM_ACCESS -#undef FILE_FLAG_SEQUENTIAL_SCAN -#undef FILE_FLAG_DELETE_ON_CLOSE -#undef FILE_FLAG_BACKUP_SEMANTICS -#undef FILE_FLAG_POSIX_SEMANTICS -#undef FILE_TYPE_DISK -#undef FILE_TYPE_UNKNOWN -#undef FILE_CASE_SENSITIVE_SEARCH -#undef FILE_CASE_PRESERVED_NAMES -#undef FILE_UNICODE_ON_DISK -#undef FILE_PERSISTENT_ACLS -#undef FILE_FILE_COMPRESSION -#undef FILE_VOLUME_QUOTAS -#undef FILE_VOLUME_IS_COMPRESSED -#undef FILE_NOTIFY_CHANGE_FILE_NAME -#undef FILE_NOTIFY_CHANGE_DIR_NAME -#undef FILE_NOTIFY_CHANGE_ATTRIBUTES -#undef FILE_NOTIFY_CHANGE_SIZE -#undef FILE_NOTIFY_CHANGE_LAST_WRITE -#undef FILE_NOTIFY_CHANGE_LAST_ACCESS -#undef FILE_NOTIFY_CHANGE_CREATION -#undef FILE_NOTIFY_CHANGE_EA -#undef FILE_NOTIFY_CHANGE_SECURITY -#undef FILE_NOTIFY_CHANGE_STREAM_NAME -#undef FILE_NOTIFY_CHANGE_STREAM_SIZE -#undef FILE_NOTIFY_CHANGE_STREAM_WRITE -#undef FILE_NOTIFY_CHANGE_NAME - -#undef PRINTER_ATTRIBUTE_QUEUED -#undef PRINTER_ATTRIBUTE_DIRECT -#undef PRINTER_ATTRIBUTE_DEFAULT -#undef PRINTER_ATTRIBUTE_SHARED -#undef PRINTER_ATTRIBUTE_NETWORK -#undef PRINTER_ATTRIBUTE_HIDDEN -#undef PRINTER_ATTRIBUTE_LOCAL -#undef PRINTER_ATTRIBUTE_ENABLE_DEVQ -#undef PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS -#undef PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST -#undef PRINTER_ATTRIBUTE_WORK_OFFLINE -#undef PRINTER_ATTRIBUTE_ENABLE_BIDI -#undef PRINTER_ATTRIBUTE_RAW_ONLY -#undef PRINTER_ATTRIBUTE_PUBLISHED -#undef PRINTER_ENUM_DEFAULT -#undef PRINTER_ENUM_LOCAL -#undef PRINTER_ENUM_CONNECTIONS -#undef PRINTER_ENUM_FAVORITE -#undef PRINTER_ENUM_NAME -#undef PRINTER_ENUM_REMOTE -#undef PRINTER_ENUM_SHARED -#undef PRINTER_ENUM_NETWORK -#undef PRINTER_ENUM_EXPAND -#undef PRINTER_ENUM_CONTAINER -#undef PRINTER_ENUM_ICON1 -#undef PRINTER_ENUM_ICON2 -#undef PRINTER_ENUM_ICON3 -#undef PRINTER_ENUM_ICON4 -#undef PRINTER_ENUM_ICON5 -#undef PRINTER_ENUM_ICON6 -#undef PRINTER_ENUM_ICON7 -#undef PRINTER_ENUM_ICON8 -#undef PRINTER_STATUS_PAUSED -#undef PRINTER_STATUS_ERROR -#undef PRINTER_STATUS_PENDING_DELETION -#undef PRINTER_STATUS_PAPER_JAM -#undef PRINTER_STATUS_PAPER_OUT -#undef PRINTER_STATUS_MANUAL_FEED -#undef PRINTER_STATUS_PAPER_PROBLEM -#undef PRINTER_STATUS_OFFLINE -#undef PRINTER_STATUS_IO_ACTIVE -#undef PRINTER_STATUS_BUSY -#undef PRINTER_STATUS_PRINTING -#undef PRINTER_STATUS_OUTPUT_BIN_FULL -#undef PRINTER_STATUS_NOT_AVAILABLE -#undef PRINTER_STATUS_WAITING -#undef PRINTER_STATUS_PROCESSING -#undef PRINTER_STATUS_INITIALIZING -#undef PRINTER_STATUS_WARMING_UP -#undef PRINTER_STATUS_TONER_LOW -#undef PRINTER_STATUS_NO_TONER -#undef PRINTER_STATUS_PAGE_PUNT -#undef PRINTER_STATUS_USER_INTERVENTION -#undef PRINTER_STATUS_OUT_OF_MEMORY -#undef PRINTER_STATUS_DOOR_OPEN -#undef PRINTER_STATUS_SERVER_UNKNOWN -#undef PRINTER_STATUS_POWER_SAVE - -#undef DWORD -#undef HKEY_CLASSES_ROOT -#undef HKEY_CURRENT_USER -#undef HKEY_LOCAL_MACHINE -#undef HKEY_USERS -#undef HKEY_PERFORMANCE_DATA -#undef HKEY_CURRENT_CONFIG -#undef HKEY_DYN_DATA -#undef REG_DWORD -#undef REG_QWORD - -#undef SERVICE_STATE_ALL - -#undef SE_GROUP_MANDATORY -#undef SE_GROUP_ENABLED_BY_DEFAULT -#undef SE_GROUP_ENABLED - -#endif /* _WIN32_REPLACE_H */ diff --git a/bundled/replace/wscript b/bundled/replace/wscript deleted file mode 100644 index 66b0e87d..00000000 --- a/bundled/replace/wscript +++ /dev/null @@ -1,391 +0,0 @@ -#!/usr/bin/env python - -APPNAME = 'libreplace' -VERSION = '1.2.1' - -blddir = 'bin' - -import sys, os, Utils - -# find the buildtools directory -srcdir = '.' -while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5: - srcdir = '../' + srcdir -sys.path.insert(0, srcdir + '/buildtools/wafsamba') - -import wafsamba, samba_dist -import Options, os, preproc - -samba_dist.DIST_DIRS('lib/replace buildtools:buildtools') - -def set_options(opt): - opt.BUILTIN_DEFAULT('NONE') - opt.BUNDLED_EXTENSION_DEFAULT('') - opt.RECURSE('buildtools/wafsamba') - -@wafsamba.runonce -def configure(conf): - conf.RECURSE('buildtools/wafsamba') - - conf.DEFINE('LIBREPLACE_NETWORK_CHECKS', 1) - - # on Tru64 certain features are only available with _OSF_SOURCE - if conf.env['SYSTEM_UNAME_SYSNAME'] == 'OSF1': - conf.DEFINE('_OSF_SOURCE', 1, add_to_cflags=True) - - conf.CHECK_HEADERS('crypt.h locale.h acl/libacl.h compat.h') - conf.CHECK_HEADERS('acl/libacl.h attr/xattr.h compat.h ctype.h dustat.h') - conf.CHECK_HEADERS('fcntl.h fnmatch.h glob.h history.h krb5.h langinfo.h') - conf.CHECK_HEADERS('libaio.h locale.h ndir.h pwd.h') - conf.CHECK_HEADERS('shadow.h sys/acl.h') - conf.CHECK_HEADERS('sys/attributes.h sys/capability.h sys/dir.h sys/epoll.h') - conf.CHECK_HEADERS('sys/fcntl.h sys/filio.h sys/filsys.h sys/fs/s5param.h sys/fs/vx/quota.h') - conf.CHECK_HEADERS('sys/id.h sys/ioctl.h sys/ipc.h sys/mman.h sys/mode.h sys/ndir.h sys/priv.h') - conf.CHECK_HEADERS('sys/resource.h sys/security.h sys/shm.h sys/statfs.h sys/statvfs.h sys/termio.h') - conf.CHECK_HEADERS('sys/vfs.h sys/xattr.h termio.h termios.h sys/file.h') - conf.CHECK_HEADERS('sys/wait.h sys/stat.h malloc.h grp.h') - conf.CHECK_HEADERS('sys/select.h setjmp.h utime.h sys/syslog.h syslog.h') - conf.CHECK_HEADERS('stdarg.h vararg.h sys/mount.h mntent.h') - conf.CHECK_HEADERS('stropts.h unix.h string.h strings.h sys/param.h limits.h') - conf.CHECK_HEADERS('''sys/socket.h netinet/in.h netdb.h arpa/inet.h netinet/in_systm.h - netinet/ip.h netinet/tcp.h netinet/in_ip.h - sys/sockio.h sys/un.h''', together=True) - conf.CHECK_HEADERS('sys/uio.h ifaddrs.h direct.h dirent.h') - conf.CHECK_HEADERS('windows.h winsock2.h ws2tcpip.h') - conf.CHECK_HEADERS('libintl.h errno.h') - conf.CHECK_HEADERS('gcrypt.h getopt.h iconv.h') - conf.CHECK_HEADERS('sys/inotify.h memory.h nss.h sasl/sasl.h') - conf.CHECK_HEADERS('security/pam_appl.h sys/inotify.h zlib.h asm/unistd.h') - conf.CHECK_HEADERS('aio.h sys/unistd.h rpc/rpc.h rpc/nettype.h alloca.h float.h') - - conf.CHECK_HEADERS('rpcsvc/nis.h rpcsvc/ypclnt.h sys/prctl.h sys/sysctl.h') - conf.CHECK_HEADERS('sys/fileio.h sys/filesys.h sys/dustat.h sys/sysmacros.h') - conf.CHECK_HEADERS('xfs/libxfs.h netgroup.h rpcsvc/yp_prot.h') - conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h') - conf.CHECK_HEADERS('nss_common.h nsswitch.h ns_api.h') - conf.CHECK_HEADERS('sys/extattr.h sys/ea.h sys/proplist.h sys/cdefs.h') - conf.CHECK_HEADERS('utmp.h utmpx.h lastlog.h') - conf.CHECK_HEADERS('syscall.h sys/syscall.h inttypes.h') - - conf.CHECK_TYPES('"long long" intptr_t uintptr_t ptrdiff_t') - conf.CHECK_TYPES('comparison_fn_t bool') - conf.CHECK_TYPE('_Bool', define='HAVE__Bool') - - conf.CHECK_TYPE('int8_t', 'char') - conf.CHECK_TYPE('int16_t', 'short') - conf.CHECK_TYPE('uint16_t', 'unsigned short') - conf.CHECK_TYPE('int32_t', 'int') - conf.CHECK_TYPE('uint32_t', 'unsigned') - conf.CHECK_TYPE('int64_t', 'long long') - conf.CHECK_TYPE('uint64_t', 'unsigned long long') - conf.CHECK_TYPE('size_t', 'unsigned int') - conf.CHECK_TYPE('ssize_t', 'int') - conf.CHECK_TYPE('ino_t', 'unsigned') - conf.CHECK_TYPE('loff_t', 'off_t') - conf.CHECK_TYPE('bool', 'off_t') - conf.CHECK_TYPE('offset_t', 'loff_t') - conf.CHECK_TYPE('volatile int', define='HAVE_VOLATILE') - conf.CHECK_TYPE('uint_t', 'unsigned int') - - conf.CHECK_TYPES('socklen_t', headers='sys/socket.h') - conf.CHECK_TYPE_IN('struct ifaddrs', 'ifaddrs.h') - conf.CHECK_TYPE_IN('struct addrinfo', 'netdb.h') - conf.CHECK_TYPE_IN('struct sockaddr', 'sys/socket.h') - conf.CHECK_CODE('struct sockaddr_in6 x', define='HAVE_STRUCT_SOCKADDR_IN6', - headers='sys/socket.h netdb.h netinet/in.h') - conf.CHECK_TYPE_IN('struct sockaddr_storage', 'sys/socket.h') - conf.CHECK_TYPE_IN('sa_family_t', 'sys/socket.h') - - conf.CHECK_TYPE_IN('sig_atomic_t', 'signal.h', define='HAVE_SIG_ATOMIC_T_TYPE') - - conf.CHECK_FUNCS_IN('''inet_ntoa inet_aton inet_ntop inet_pton connect gethostbyname - getaddrinfo getnameinfo freeaddrinfo gai_strerror socketpair''', - 'socket nsl', checklibc=True, - headers='sys/socket.h netinet/in.h arpa/inet.h netdb.h') - - # Some old Linux systems have broken header files and - # miss the IPV6_V6ONLY define in netinet/in.h, - # but have it in linux/in6.h. - # We can't include both files so we just check if the value - # if defined and do the replacement in system/network.h - if not conf.CHECK_VARIABLE('IPV6_V6ONLY', - headers='sys/socket.h netdb.h netinet/in.h'): - conf.CHECK_CODE(''' - #include - #if (IPV6_V6ONLY != 26) - #error no IPV6_V6ONLY support on linux - #endif - int main(void) { return IPV6_V6ONLY; } - ''', - define='HAVE_LINUX_IPV6_V6ONLY_26', - addmain=False, - msg='Checking for IPV6_V6ONLY in linux/in6.h', - local_include=False) - - conf.CHECK_CODE(''' - struct sockaddr_storage sa_store; - struct addrinfo *ai = NULL; - struct in6_addr in6addr; - int idx = if_nametoindex("iface1"); - int s = socket(AF_INET6, SOCK_STREAM, 0); - int ret = getaddrinfo(NULL, NULL, NULL, &ai); - if (ret != 0) { - const char *es = gai_strerror(ret); - } - freeaddrinfo(ai); - { - int val = 1; - #ifdef HAVE_LINUX_IPV6_V6ONLY_26 - #define IPV6_V6ONLY 26 - #endif - ret = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, - (const void *)&val, sizeof(val)); - } - ''', - define='HAVE_IPV6', - lib='nsl socket', - headers='sys/socket.h netdb.h netinet/in.h') - - # these may be builtins, so we need the link=False strategy - conf.CHECK_FUNCS('strdup memmem printf memset memcpy memmove strcpy strncpy bzero', link=False) - - conf.CHECK_FUNCS('shl_load shl_unload shl_findsym') - conf.CHECK_FUNCS('pipe strftime srandom random srand rand usleep setbuffer') - conf.CHECK_FUNCS('lstat getpgrp utime utimes seteuid setresuid setegid') - conf.CHECK_FUNCS('setresgid chroot strerror vsyslog setlinebuf mktime') - conf.CHECK_FUNCS('ftruncate chsize rename waitpid wait4 strlcpy strlcat') - conf.CHECK_FUNCS('initgroups pread pwrite strndup strcasestr') - conf.CHECK_FUNCS('strtok_r mkdtemp dup2 dprintf vdprintf isatty chown lchown') - conf.CHECK_FUNCS('link readlink symlink realpath snprintf vsnprintf') - conf.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull') - conf.CHECK_FUNCS('strtouq strtoll __strtoll strtoq') - conf.CHECK_FUNCS('if_nametoindex strerror_r') - conf.CHECK_FUNCS('getdirentries getdents syslog') - conf.CHECK_FUNCS('gai_strerror get_current_dir_name') - conf.CHECK_FUNCS('timegm getifaddrs freeifaddrs mmap setgroups setsid') - conf.CHECK_FUNCS('getgrent_r getgrgid_r getgrnam_r getgrouplist getpagesize') - conf.CHECK_FUNCS('getpwent_r getpwnam_r getpwuid_r epoll_create') - - conf.CHECK_FUNCS_IN('dlopen dlsym dlerror dlclose', 'dl', - checklibc=True, headers='dlfcn.h dl.h') - - conf.CHECK_C_PROTOTYPE('dlopen', 'void *dlopen(const char* filename, unsigned int flags)', - define='DLOPEN_TAKES_UNSIGNED_FLAGS', headers='dlfcn.h dl.h') - - conf.CHECK_FUNCS_IN('fdatasync', 'rt', checklibc=True) - - # these headers need to be tested as a group on freebsd - conf.CHECK_HEADERS(headers='sys/socket.h net/if.h', together=True) - conf.CHECK_HEADERS(headers='netinet/in.h arpa/nameser.h resolv.h', together=True) - conf.CHECK_FUNCS_IN('res_search', 'resolv', checklibc=True, - headers='netinet/in.h arpa/nameser.h resolv.h') - - conf.CHECK_FUNCS_IN('gettext', 'intl', checklibc=True, headers='libintl.h') - conf.CHECK_FUNCS_IN('pthread_create', 'pthread', checklibc=True, headers='pthread.h') - - conf.CHECK_FUNCS_IN('crypt', 'crypt', checklibc=True) - - conf.CHECK_VARIABLE('rl_event_hook', define='HAVE_DECL_RL_EVENT_HOOK', always=True, - headers='readline.h readline/readline.h readline/history.h') - - conf.CHECK_DECLS('snprintf vsnprintf asprintf vasprintf') - - conf.CHECK_DECLS('errno', headers='errno.h', reverse=True) - conf.CHECK_DECLS('environ getgrent_r getpwent_r', reverse=True, headers='pwd.h grp.h') - conf.CHECK_DECLS('pread pwrite setenv setresgid setresuid', reverse=True) - - conf.CHECK_SIZEOF('char int "long long" long off_t short size_t ssize_t') - conf.CHECK_SIZEOF('dev_t ino_t time_t') - conf.CHECK_SIZEOF('void*', define='SIZEOF_VOID_P') - - if conf.CONFIG_SET('HAVE_EPOLL_CREATE') and conf.CONFIG_SET('HAVE_SYS_EPOLL_H'): - conf.DEFINE('HAVE_EPOLL', 1) - - if not conf.CHECK_CODE('''#define LIBREPLACE_CONFIGURE_TEST_STRPTIME - #include "test/strptime.c"''', - define='HAVE_STRPTIME', - addmain=False, - msg='Checking for working strptime'): - conf.DEFINE('REPLACE_STRPTIME', 1) - - if conf.CONFIG_SET('HAVE_KRB5_H'): - # Check for KRB5_DEPRECATED handling - conf.CHECK_CODE('''#define KRB5_DEPRECATED 1 -#include ''', - 'HAVE_KRB5_DEPRECATED_WITH_IDENTIFIER', addmain=False, - link=False, - msg="Checking for KRB5_DEPRECATED define taking an identifier") - - conf.CHECK_CODE('gettimeofday(NULL, NULL)', 'HAVE_GETTIMEOFDAY_TZ', execute=False) - - conf.CHECK_CODE('#include "test/snprintf.c"', - define="HAVE_C99_VSNPRINTF", - execute=1, - addmain=False, - msg="Checking for C99 vsnprintf") - - conf.SAMBA_BUILD_ENV() - - conf.CHECK_CODE(''' - typedef struct {unsigned x;} FOOBAR; - #define X_FOOBAR(x) ((FOOBAR) { x }) - #define FOO_ONE X_FOOBAR(1) - FOOBAR f = FOO_ONE; - static const struct { - FOOBAR y; - } f2[] = { - {FOO_ONE} - }; - static const FOOBAR f3[] = {FOO_ONE}; - ''', - define='HAVE_IMMEDIATE_STRUCTURES') - - conf.CHECK_CODE('mkdir("foo",0777)', define='HAVE_MKDIR_MODE', headers='sys/stat.h') - - conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_mtim.tv_nsec', define='HAVE_STAT_TV_NSEC', - headers='sys/stat.h') - # we need the st_rdev test under two names - conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', - define='HAVE_STRUCT_STAT_ST_RDEV', - headers='sys/stat.h') - conf.CHECK_STRUCTURE_MEMBER('struct stat', 'st_rdev', define='HAVE_ST_RDEV', - headers='sys/stat.h') - conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_storage', 'ss_family', - headers='sys/socket.h netinet/in.h') - - - if conf.CHECK_STRUCTURE_MEMBER('struct sockaddr', 'sa_len', - headers='sys/socket.h netinet/in.h', - define='HAVE_SOCKADDR_SA_LEN'): - # the old build system produced both defines - conf.DEFINE('HAVE_STRUCT_SOCKADDR_SA_LEN', 1) - - conf.CHECK_STRUCTURE_MEMBER('struct sockaddr_in', 'sin_len', - headers='sys/socket.h netinet/in.h', - define='HAVE_SOCK_SIN_LEN') - - conf.CHECK_CODE('struct sockaddr_un sunaddr; sunaddr.sun_family = AF_UNIX;', - define='HAVE_UNIXSOCKET', headers='sys/socket.h sys/un.h') - - - conf.CHECK_CODE(''' - struct stat st; - char tpl[20]="/tmp/test.XXXXXX"; - int fd = mkstemp(tpl); - if (fd == -1) exit(1); - unlink(tpl); - if (fstat(fd, &st) != 0) exit(1); - if ((st.st_mode & 0777) != 0600) exit(1); - exit(0); - ''', - define='HAVE_SECURE_MKSTEMP', - execute=True, - mandatory=True) # lets see if we get a mandatory failure for this one - - if conf.CHECK_CFLAGS('-fvisibility=hidden'): - conf.env.VISIBILITY_CFLAGS = '-fvisibility=hidden' - conf.CHECK_CODE('''void vis_foo1(void) {} - __attribute__((visibility("default"))) void vis_foo2(void) {}''', - cflags=conf.env.VISIBILITY_CFLAGS, - define='HAVE_VISIBILITY_ATTR') - - # look for a method of finding the list of network interfaces - for method in ['HAVE_IFACE_GETIFADDRS', 'HAVE_IFACE_AIX', 'HAVE_IFACE_IFCONF', 'HAVE_IFACE_IFREQ']: - if conf.CHECK_CODE(''' - #define %s 1 - #define NO_CONFIG_H 1 - #define AUTOCONF_TEST 1 - #define SOCKET_WRAPPER_NOT_REPLACE - #include "replace.c" - #include "inet_ntop.c" - #include "snprintf.c" - #include "getifaddrs.c" - #define getifaddrs_test main - #include "test/getifaddrs.c" - ''' % method, - method, - lib='nsl socket', - addmain=False, - execute=True): - break - - if conf.CHECK_FUNCS('getpass getpassphrase'): - # if we have both, then we prefer getpassphrase - conf.DEFINE('REPLACE_GETPASS_BY_GETPASSPHRASE', 1) - conf.DEFINE('REPLACE_GETPASS', 1) - else: - conf.CHECK_CODE('''#include "getpass.c" - int main(void) { return 0; }''', - addmain=False, - define='REPLACE_GETPASS', - cflags='-DNO_CONFIG_H') - - conf.RECURSE('system') - conf.SAMBA_CONFIG_H() - - -def build(bld): - bld.RECURSE('buildtools/wafsamba') - - REPLACE_HOSTCC_SOURCE = 'replace.c snprintf.c' - - if bld.CONFIG_SET('REPLACE_STRPTIME'): REPLACE_HOSTCC_SOURCE += ' strptime.c' - if not bld.CONFIG_SET('HAVE_TIMEGM'): REPLACE_HOSTCC_SOURCE += ' timegm.c' - - bld.SAMBA_SUBSYSTEM('LIBREPLACE_HOSTCC', - REPLACE_HOSTCC_SOURCE, - use_hostcc=True, - use_global_deps=False, - cflags='-DSOCKET_WRAPPER_DISABLE=1 -DNSS_WRAPPER_DISABLE=1 -D_SAMBA_HOSTCC_', - group='compiler_libraries' - ) - - REPLACE_SOURCE = REPLACE_HOSTCC_SOURCE - - if bld.CONFIG_SET('REPLACE_GETPASS'): REPLACE_SOURCE += ' getpass.c' - if not bld.CONFIG_SET('HAVE_CRYPT'): REPLACE_SOURCE += ' crypt.c' - if not bld.CONFIG_SET('HAVE_DLOPEN'): REPLACE_SOURCE += ' dlfcn.c' - - if not bld.CONFIG_SET('HAVE_SOCKETPAIR'): REPLACE_SOURCE += ' socketpair.c' - if not bld.CONFIG_SET('HAVE_CONNECT'): REPLACE_SOURCE += ' socket.c' - if not bld.CONFIG_SET('HAVE_GETIFADDRS'): REPLACE_SOURCE += ' getifaddrs.c' - if not bld.CONFIG_SET('HAVE_GETADDRINFO'): REPLACE_SOURCE += ' getaddrinfo.c' - if not bld.CONFIG_SET('HAVE_INET_NTOA'): REPLACE_SOURCE += ' inet_ntoa.c' - if not bld.CONFIG_SET('HAVE_INET_ATON'): REPLACE_SOURCE += ' inet_aton.c' - if not bld.CONFIG_SET('HAVE_INET_NTOP'): REPLACE_SOURCE += ' inet_ntop.c' - if not bld.CONFIG_SET('HAVE_INET_PTON'): REPLACE_SOURCE += ' inet_pton.c' - - bld.SAMBA_LIBRARY('replace', - source=REPLACE_SOURCE, - group='base_libraries', - # FIXME: Ideally symbols should be hidden here so they - # don't appear in the global namespace when Samba - # libraries are loaded, but this doesn't appear to work - # at the moment: - # hide_symbols=bld.BUILTIN_LIBRARY('replace'), - deps='crypt dl nsl socket') - - TEST_SOURCES = '''test/testsuite.c test/main.c test/strptime.c - test/os2_delete.c test/getifaddrs.c''' - - - bld.SAMBA_BINARY('replace_testsuite', - TEST_SOURCES, - deps='replace', - install=False) - - # build replacements for stdint.h and stdbool.h if needed - bld.SAMBA_GENERATOR('replace_stdint_h', - rule='cp ${SRC} ${TGT}', - source='hdr_replace.h', - target='stdint.h', - enabled = not bld.CONFIG_SET('HAVE_STDINT_H')) - bld.SAMBA_GENERATOR('replace_stdbool_h', - rule='cp ${SRC} ${TGT}', - source='hdr_replace.h', - target='stdbool.h', - enabled = not bld.CONFIG_SET('HAVE_STDBOOL_H')) - -def dist(): - '''makes a tarball for distribution''' - samba_dist.dist() diff --git a/bundled/tdb/.revinfo.git b/bundled/tdb/.revinfo.git deleted file mode 100644 index bc276c42..00000000 --- a/bundled/tdb/.revinfo.git +++ /dev/null @@ -1,8 +0,0 @@ -3dc7203 -1282478758 -3dc720371368b670635f986f9a7bd412b00255a8 -Sun Aug 22 14:05:58 2010 +0200 - lib/tdb/manpages/tdbbackup.8.xml | 2 +- - lib/tdb/manpages/tdbdump.8.xml | 2 +- - lib/tdb/manpages/tdbtool.8.xml | 2 +- - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bundled/tdb/.tmp_waflock b/bundled/tdb/.tmp_waflock deleted file mode 100644 index e69de29b..00000000 diff --git a/bundled/tdb/ABI/tdb-1.2.1.sigs b/bundled/tdb/ABI/tdb-1.2.1.sigs deleted file mode 100644 index 84f20074..00000000 --- a/bundled/tdb/ABI/tdb-1.2.1.sigs +++ /dev/null @@ -1,95 +0,0 @@ -tdb_add_flags: void (struct tdb_context *, unsigned int) -tdb_alloc_read: unsigned char *(struct tdb_context *, tdb_off_t, tdb_len_t) -tdb_allocate: tdb_off_t (struct tdb_context *, tdb_len_t, struct tdb_record *) -tdb_allrecord_lock: int (struct tdb_context *, int, enum tdb_lock_flags, bool) -tdb_allrecord_unlock: int (struct tdb_context *, int, bool) -tdb_allrecord_upgrade: int (struct tdb_context *) -tdb_append: int (struct tdb_context *, TDB_DATA, TDB_DATA) -tdb_brlock: int (struct tdb_context *, int, tdb_off_t, size_t, enum tdb_lock_flags) -tdb_brunlock: int (struct tdb_context *, int, tdb_off_t, size_t) -tdb_chainlock: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_mark: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_nonblock: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_read: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_unmark: int (struct tdb_context *, TDB_DATA) -tdb_chainunlock: int (struct tdb_context *, TDB_DATA) -tdb_chainunlock_read: int (struct tdb_context *, TDB_DATA) -tdb_check: int (struct tdb_context *, int (*)(TDB_DATA, TDB_DATA, void *), void *) -tdb_close: int (struct tdb_context *) -tdb_convert: void *(void *, uint32_t) -tdb_delete: int (struct tdb_context *, TDB_DATA) -tdb_do_delete: int (struct tdb_context *, tdb_off_t, struct tdb_record *) -tdb_dump_all: void (struct tdb_context *) -tdb_enable_seqnum: void (struct tdb_context *) -tdb_error: enum TDB_ERROR (struct tdb_context *) -tdb_errorstr: const char *(struct tdb_context *) -tdb_exists: int (struct tdb_context *, TDB_DATA) -tdb_expand: int (struct tdb_context *, tdb_off_t) -tdb_fd: int (struct tdb_context *) -tdb_fetch: TDB_DATA (struct tdb_context *, TDB_DATA) -tdb_find_lock_hash: tdb_off_t (struct tdb_context *, TDB_DATA, uint32_t, int, struct tdb_record *) -tdb_firstkey: TDB_DATA (struct tdb_context *) -tdb_free: int (struct tdb_context *, tdb_off_t, struct tdb_record *) -tdb_freelist_size: int (struct tdb_context *) -tdb_get_flags: int (struct tdb_context *) -tdb_get_logging_private: void *(struct tdb_context *) -tdb_get_seqnum: int (struct tdb_context *) -tdb_hash_size: int (struct tdb_context *) -tdb_have_extra_locks: bool (struct tdb_context *) -tdb_increment_seqnum_nonblock: void (struct tdb_context *) -tdb_io_init: void (struct tdb_context *) -tdb_lock: int (struct tdb_context *, int, int) -tdb_lock_nonblock: int (struct tdb_context *, int, int) -tdb_lock_record: int (struct tdb_context *, tdb_off_t) -tdb_lockall: int (struct tdb_context *) -tdb_lockall_mark: int (struct tdb_context *) -tdb_lockall_nonblock: int (struct tdb_context *) -tdb_lockall_read: int (struct tdb_context *) -tdb_lockall_read_nonblock: int (struct tdb_context *) -tdb_lockall_unmark: int (struct tdb_context *) -tdb_log_fn: tdb_log_func (struct tdb_context *) -tdb_map_size: size_t (struct tdb_context *) -tdb_mmap: void (struct tdb_context *) -tdb_munmap: int (struct tdb_context *) -tdb_name: const char *(struct tdb_context *) -tdb_needs_recovery: bool (struct tdb_context *) -tdb_nest_lock: int (struct tdb_context *, uint32_t, int, enum tdb_lock_flags) -tdb_nest_unlock: int (struct tdb_context *, uint32_t, int, bool) -tdb_nextkey: TDB_DATA (struct tdb_context *, TDB_DATA) -tdb_ofs_read: int (struct tdb_context *, tdb_off_t, tdb_off_t *) -tdb_ofs_write: int (struct tdb_context *, tdb_off_t, tdb_off_t *) -tdb_open: struct tdb_context *(const char *, int, int, int, mode_t) -tdb_open_ex: struct tdb_context *(const char *, int, int, int, mode_t, const struct tdb_logging_context *, tdb_hash_func) -tdb_parse_data: int (struct tdb_context *, TDB_DATA, tdb_off_t, tdb_len_t, int (*)(TDB_DATA, TDB_DATA, void *), void *) -tdb_parse_record: int (struct tdb_context *, TDB_DATA, int (*)(TDB_DATA, TDB_DATA, void *), void *) -tdb_printfreelist: int (struct tdb_context *) -tdb_rec_free_read: int (struct tdb_context *, tdb_off_t, struct tdb_record *) -tdb_rec_read: int (struct tdb_context *, tdb_off_t, struct tdb_record *) -tdb_rec_write: int (struct tdb_context *, tdb_off_t, struct tdb_record *) -tdb_release_transaction_locks: void (struct tdb_context *) -tdb_remove_flags: void (struct tdb_context *, unsigned int) -tdb_reopen: int (struct tdb_context *) -tdb_reopen_all: int (int) -tdb_repack: int (struct tdb_context *) -tdb_set_logging_function: void (struct tdb_context *, const struct tdb_logging_context *) -tdb_set_max_dead: void (struct tdb_context *, int) -tdb_setalarm_sigptr: void (struct tdb_context *, volatile sig_atomic_t *) -tdb_store: int (struct tdb_context *, TDB_DATA, TDB_DATA, int) -tdb_transaction_cancel: int (struct tdb_context *) -tdb_transaction_commit: int (struct tdb_context *) -tdb_transaction_lock: int (struct tdb_context *, int, enum tdb_lock_flags) -tdb_transaction_prepare_commit: int (struct tdb_context *) -tdb_transaction_recover: int (struct tdb_context *) -tdb_transaction_start: int (struct tdb_context *) -tdb_transaction_start_nonblock: int (struct tdb_context *) -tdb_transaction_unlock: int (struct tdb_context *, int) -tdb_traverse: int (struct tdb_context *, tdb_traverse_func, void *) -tdb_traverse_read: int (struct tdb_context *, tdb_traverse_func, void *) -tdb_unlock: int (struct tdb_context *, int, int) -tdb_unlock_record: int (struct tdb_context *, tdb_off_t) -tdb_unlockall: int (struct tdb_context *) -tdb_unlockall_read: int (struct tdb_context *) -tdb_validate_freelist: int (struct tdb_context *, int *) -tdb_wipe_all: int (struct tdb_context *) -tdb_write_lock_record: int (struct tdb_context *, tdb_off_t) -tdb_write_unlock_record: int (struct tdb_context *, tdb_off_t) diff --git a/bundled/tdb/ABI/tdb-1.2.2.sigs b/bundled/tdb/ABI/tdb-1.2.2.sigs deleted file mode 100644 index 043790d2..00000000 --- a/bundled/tdb/ABI/tdb-1.2.2.sigs +++ /dev/null @@ -1,60 +0,0 @@ -tdb_add_flags: void (struct tdb_context *, unsigned int) -tdb_append: int (struct tdb_context *, TDB_DATA, TDB_DATA) -tdb_chainlock: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_mark: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_nonblock: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_read: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_unmark: int (struct tdb_context *, TDB_DATA) -tdb_chainunlock: int (struct tdb_context *, TDB_DATA) -tdb_chainunlock_read: int (struct tdb_context *, TDB_DATA) -tdb_check: int (struct tdb_context *, int (*)(TDB_DATA, TDB_DATA, void *), void *) -tdb_close: int (struct tdb_context *) -tdb_delete: int (struct tdb_context *, TDB_DATA) -tdb_dump_all: void (struct tdb_context *) -tdb_enable_seqnum: void (struct tdb_context *) -tdb_error: enum TDB_ERROR (struct tdb_context *) -tdb_errorstr: const char *(struct tdb_context *) -tdb_exists: int (struct tdb_context *, TDB_DATA) -tdb_fd: int (struct tdb_context *) -tdb_fetch: TDB_DATA (struct tdb_context *, TDB_DATA) -tdb_firstkey: TDB_DATA (struct tdb_context *) -tdb_freelist_size: int (struct tdb_context *) -tdb_get_flags: int (struct tdb_context *) -tdb_get_logging_private: void *(struct tdb_context *) -tdb_get_seqnum: int (struct tdb_context *) -tdb_hash_size: int (struct tdb_context *) -tdb_increment_seqnum_nonblock: void (struct tdb_context *) -tdb_lockall: int (struct tdb_context *) -tdb_lockall_mark: int (struct tdb_context *) -tdb_lockall_nonblock: int (struct tdb_context *) -tdb_lockall_read: int (struct tdb_context *) -tdb_lockall_read_nonblock: int (struct tdb_context *) -tdb_lockall_unmark: int (struct tdb_context *) -tdb_log_fn: tdb_log_func (struct tdb_context *) -tdb_map_size: size_t (struct tdb_context *) -tdb_name: const char *(struct tdb_context *) -tdb_nextkey: TDB_DATA (struct tdb_context *, TDB_DATA) -tdb_null: dptr = 0xXXXX, dsize = 0 -tdb_open: struct tdb_context *(const char *, int, int, int, mode_t) -tdb_open_ex: struct tdb_context *(const char *, int, int, int, mode_t, const struct tdb_logging_context *, tdb_hash_func) -tdb_parse_record: int (struct tdb_context *, TDB_DATA, int (*)(TDB_DATA, TDB_DATA, void *), void *) -tdb_printfreelist: int (struct tdb_context *) -tdb_remove_flags: void (struct tdb_context *, unsigned int) -tdb_reopen: int (struct tdb_context *) -tdb_reopen_all: int (int) -tdb_repack: int (struct tdb_context *) -tdb_set_logging_function: void (struct tdb_context *, const struct tdb_logging_context *) -tdb_set_max_dead: void (struct tdb_context *, int) -tdb_setalarm_sigptr: void (struct tdb_context *, volatile sig_atomic_t *) -tdb_store: int (struct tdb_context *, TDB_DATA, TDB_DATA, int) -tdb_transaction_cancel: int (struct tdb_context *) -tdb_transaction_commit: int (struct tdb_context *) -tdb_transaction_prepare_commit: int (struct tdb_context *) -tdb_transaction_start: int (struct tdb_context *) -tdb_transaction_start_nonblock: int (struct tdb_context *) -tdb_traverse: int (struct tdb_context *, tdb_traverse_func, void *) -tdb_traverse_read: int (struct tdb_context *, tdb_traverse_func, void *) -tdb_unlockall: int (struct tdb_context *) -tdb_unlockall_read: int (struct tdb_context *) -tdb_validate_freelist: int (struct tdb_context *, int *) -tdb_wipe_all: int (struct tdb_context *) diff --git a/bundled/tdb/ABI/tdb-1.2.3.sigs b/bundled/tdb/ABI/tdb-1.2.3.sigs deleted file mode 100644 index 043790d2..00000000 --- a/bundled/tdb/ABI/tdb-1.2.3.sigs +++ /dev/null @@ -1,60 +0,0 @@ -tdb_add_flags: void (struct tdb_context *, unsigned int) -tdb_append: int (struct tdb_context *, TDB_DATA, TDB_DATA) -tdb_chainlock: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_mark: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_nonblock: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_read: int (struct tdb_context *, TDB_DATA) -tdb_chainlock_unmark: int (struct tdb_context *, TDB_DATA) -tdb_chainunlock: int (struct tdb_context *, TDB_DATA) -tdb_chainunlock_read: int (struct tdb_context *, TDB_DATA) -tdb_check: int (struct tdb_context *, int (*)(TDB_DATA, TDB_DATA, void *), void *) -tdb_close: int (struct tdb_context *) -tdb_delete: int (struct tdb_context *, TDB_DATA) -tdb_dump_all: void (struct tdb_context *) -tdb_enable_seqnum: void (struct tdb_context *) -tdb_error: enum TDB_ERROR (struct tdb_context *) -tdb_errorstr: const char *(struct tdb_context *) -tdb_exists: int (struct tdb_context *, TDB_DATA) -tdb_fd: int (struct tdb_context *) -tdb_fetch: TDB_DATA (struct tdb_context *, TDB_DATA) -tdb_firstkey: TDB_DATA (struct tdb_context *) -tdb_freelist_size: int (struct tdb_context *) -tdb_get_flags: int (struct tdb_context *) -tdb_get_logging_private: void *(struct tdb_context *) -tdb_get_seqnum: int (struct tdb_context *) -tdb_hash_size: int (struct tdb_context *) -tdb_increment_seqnum_nonblock: void (struct tdb_context *) -tdb_lockall: int (struct tdb_context *) -tdb_lockall_mark: int (struct tdb_context *) -tdb_lockall_nonblock: int (struct tdb_context *) -tdb_lockall_read: int (struct tdb_context *) -tdb_lockall_read_nonblock: int (struct tdb_context *) -tdb_lockall_unmark: int (struct tdb_context *) -tdb_log_fn: tdb_log_func (struct tdb_context *) -tdb_map_size: size_t (struct tdb_context *) -tdb_name: const char *(struct tdb_context *) -tdb_nextkey: TDB_DATA (struct tdb_context *, TDB_DATA) -tdb_null: dptr = 0xXXXX, dsize = 0 -tdb_open: struct tdb_context *(const char *, int, int, int, mode_t) -tdb_open_ex: struct tdb_context *(const char *, int, int, int, mode_t, const struct tdb_logging_context *, tdb_hash_func) -tdb_parse_record: int (struct tdb_context *, TDB_DATA, int (*)(TDB_DATA, TDB_DATA, void *), void *) -tdb_printfreelist: int (struct tdb_context *) -tdb_remove_flags: void (struct tdb_context *, unsigned int) -tdb_reopen: int (struct tdb_context *) -tdb_reopen_all: int (int) -tdb_repack: int (struct tdb_context *) -tdb_set_logging_function: void (struct tdb_context *, const struct tdb_logging_context *) -tdb_set_max_dead: void (struct tdb_context *, int) -tdb_setalarm_sigptr: void (struct tdb_context *, volatile sig_atomic_t *) -tdb_store: int (struct tdb_context *, TDB_DATA, TDB_DATA, int) -tdb_transaction_cancel: int (struct tdb_context *) -tdb_transaction_commit: int (struct tdb_context *) -tdb_transaction_prepare_commit: int (struct tdb_context *) -tdb_transaction_start: int (struct tdb_context *) -tdb_transaction_start_nonblock: int (struct tdb_context *) -tdb_traverse: int (struct tdb_context *, tdb_traverse_func, void *) -tdb_traverse_read: int (struct tdb_context *, tdb_traverse_func, void *) -tdb_unlockall: int (struct tdb_context *) -tdb_unlockall_read: int (struct tdb_context *) -tdb_validate_freelist: int (struct tdb_context *, int *) -tdb_wipe_all: int (struct tdb_context *) diff --git a/bundled/tdb/Makefile.in b/bundled/tdb/Makefile.in deleted file mode 100644 index f12a27a3..00000000 --- a/bundled/tdb/Makefile.in +++ /dev/null @@ -1,80 +0,0 @@ -#!gmake -# -# Makefile for tdb directory -# - -CC = @CC@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ -bindir = @bindir@ -includedir = @includedir@ -libdir = @libdir@ -mandir = @mandir@ -VPATH = @srcdir@:@libreplacedir@ -srcdir = @srcdir@ -builddir = @builddir@ -sharedbuilddir = @sharedbuilddir@ -INSTALLCMD = @INSTALL@ -CPPFLAGS = @CPPFLAGS@ -I$(srcdir)/include -Iinclude -CFLAGS = $(CPPFLAGS) @CFLAGS@ -LDFLAGS = @LDFLAGS@ -EXEEXT = @EXEEXT@ -SHLD = @SHLD@ -SHLD_FLAGS = @SHLD_FLAGS@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PICFLAG = @PICFLAG@ -SHLIBEXT = @SHLIBEXT@ -PYTHON = @PYTHON@ -PYTHON_CONFIG = @PYTHON_CONFIG@ -PYTHON_BUILD_TARGET = @PYTHON_BUILD_TARGET@ -PYTHON_INSTALL_TARGET = @PYTHON_INSTALL_TARGET@ -PYTHON_CHECK_TARGET = @PYTHON_CHECK_TARGET@ -LIB_PATH_VAR = @LIB_PATH_VAR@ -tdbdir = @tdbdir@ - -EXTRA_TARGETS = @DOC_TARGET@ - -TDB_OBJ = @TDB_OBJ@ @LIBREPLACEOBJ@ -TDB_DEPS = @TDB_DEPS@ - -SONAMEFLAG = @SONAMEFLAG@ -VERSIONSCRIPT = @VERSIONSCRIPT@ -EXPORTSFILE = @EXPORTSFILE@ - -XSLTPROC = @XSLTPROC@ - -default: all - -include $(tdbdir)/tdb.mk -include $(tdbdir)/rules.mk - -all:: showflags dirs $(PROGS) $(TDB_SOLIB) libtdb.a $(PYTHON_BUILD_TARGET) $(EXTRA_TARGETS) - -install:: all -$(TDB_SOLIB): $(TDB_OBJ) - $(SHLD) $(SHLD_FLAGS) -o $@ $(TDB_OBJ) $(VERSIONSCRIPT) $(EXPORTSFILE) $(TDB_DEPS) $(SONAMEFLAG)$(TDB_SONAME) - -shared-build: all - ${INSTALLCMD} -d $(sharedbuilddir)/lib - ${INSTALLCMD} -m 644 libtdb.a $(sharedbuilddir)/lib - ${INSTALLCMD} -m 755 $(TDB_SOLIB) $(sharedbuilddir)/lib - ln -sf $(TDB_SOLIB) $(sharedbuilddir)/lib/$(TDB_SONAME) - ln -sf $(TDB_SOLIB) $(sharedbuilddir)/lib/libtdb.so - ${INSTALLCMD} -d $(sharedbuilddir)/include - ${INSTALLCMD} -m 644 $(srcdir)/include/tdb.h $(sharedbuilddir)/include - -check: test - -test:: $(PYTHON_CHECK_TARGET) -installcheck:: test install - -clean:: - rm -f *.o *.a */*.o - rm -fr abi - -distclean:: clean - rm -f config.log config.status include/config.h config.cache - rm -f Makefile - -realdistclean:: distclean - rm -f configure include/config.h.in diff --git a/bundled/tdb/aclocal.m4 b/bundled/tdb/aclocal.m4 deleted file mode 100644 index 5605e476..00000000 --- a/bundled/tdb/aclocal.m4 +++ /dev/null @@ -1 +0,0 @@ -m4_include(libreplace.m4) diff --git a/bundled/tdb/autogen-waf.sh b/bundled/tdb/autogen-waf.sh deleted file mode 120000 index 99150f3a..00000000 --- a/bundled/tdb/autogen-waf.sh +++ /dev/null @@ -1 +0,0 @@ -../../buildtools/scripts/autogen-waf.sh \ No newline at end of file diff --git a/bundled/tdb/autogen.sh b/bundled/tdb/autogen.sh deleted file mode 100755 index bf84eeee..00000000 --- a/bundled/tdb/autogen.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -rm -rf autom4te.cache -rm -f configure config.h.in - -IPATHS="-I libreplace -I lib/replace -I ../libreplace -I ../replace" -autoconf $IPATHS || exit 1 -autoheader $IPATHS || exit 1 - -rm -rf autom4te.cache - -echo "Now run ./configure and then make." -exit 0 - diff --git a/bundled/tdb/build_macros.m4 b/bundled/tdb/build_macros.m4 deleted file mode 100644 index c036668c..00000000 --- a/bundled/tdb/build_macros.m4 +++ /dev/null @@ -1,14 +0,0 @@ -AC_DEFUN(BUILD_WITH_SHARED_BUILD_DIR, - [ AC_ARG_WITH([shared-build-dir], - [AC_HELP_STRING([--with-shared-build-dir=DIR], - [temporary build directory where libraries are installed [$srcdir/sharedbuild]])]) - - sharedbuilddir="$srcdir/sharedbuild" - if test x"$with_shared_build_dir" != x; then - sharedbuilddir=$with_shared_build_dir - CFLAGS="$CFLAGS -I$with_shared_build_dir/include" - LDFLAGS="$LDFLAGS -L$with_shared_build_dir/lib" - fi - AC_SUBST(sharedbuilddir) - ]) - diff --git a/bundled/tdb/common/check.c b/bundled/tdb/common/check.c deleted file mode 100644 index 2c640434..00000000 --- a/bundled/tdb/common/check.c +++ /dev/null @@ -1,423 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Rusty Russell 2009 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ -#include "tdb_private.h" - -/* Since we opened it, these shouldn't fail unless it's recent corruption. */ -static bool tdb_check_header(struct tdb_context *tdb, tdb_off_t *recovery) -{ - struct tdb_header hdr; - - if (tdb->methods->tdb_read(tdb, 0, &hdr, sizeof(hdr), DOCONV()) == -1) - return false; - if (strcmp(hdr.magic_food, TDB_MAGIC_FOOD) != 0) - goto corrupt; - - CONVERT(hdr); - if (hdr.version != TDB_VERSION) - goto corrupt; - - if (hdr.rwlocks != 0) - goto corrupt; - - if (hdr.hash_size == 0) - goto corrupt; - - if (hdr.hash_size != tdb->header.hash_size) - goto corrupt; - - if (hdr.recovery_start != 0 && - hdr.recovery_start < TDB_DATA_START(tdb->header.hash_size)) - goto corrupt; - - *recovery = hdr.recovery_start; - return true; - -corrupt: - tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_ERROR, "Header is corrupt\n")); - return false; -} - -/* Generic record header check. */ -static bool tdb_check_record(struct tdb_context *tdb, - tdb_off_t off, - const struct tdb_record *rec) -{ - tdb_off_t tailer; - - /* Check rec->next: 0 or points to record offset, aligned. */ - if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->header.hash_size)){ - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d too small next %d\n", - off, rec->next)); - goto corrupt; - } - if (rec->next + sizeof(*rec) < rec->next) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d too large next %d\n", - off, rec->next)); - goto corrupt; - } - if ((rec->next % TDB_ALIGNMENT) != 0) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d misaligned next %d\n", - off, rec->next)); - goto corrupt; - } - if (tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0)) - goto corrupt; - - /* Check rec_len: similar to rec->next, implies next record. */ - if ((rec->rec_len % TDB_ALIGNMENT) != 0) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d misaligned length %d\n", - off, rec->rec_len)); - goto corrupt; - } - /* Must fit tailer. */ - if (rec->rec_len < sizeof(tailer)) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d too short length %d\n", - off, rec->rec_len)); - goto corrupt; - } - /* OOB allows "right at the end" access, so this works for last rec. */ - if (tdb->methods->tdb_oob(tdb, off+sizeof(*rec)+rec->rec_len, 0)) - goto corrupt; - - /* Check tailer. */ - if (tdb_ofs_read(tdb, off+sizeof(*rec)+rec->rec_len-sizeof(tailer), - &tailer) == -1) - goto corrupt; - if (tailer != sizeof(*rec) + rec->rec_len) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d invalid tailer\n", off)); - goto corrupt; - } - - return true; - -corrupt: - tdb->ecode = TDB_ERR_CORRUPT; - return false; -} - -/* Grab some bytes: may copy if can't use mmap. - Caller has already done bounds check. */ -static TDB_DATA get_bytes(struct tdb_context *tdb, - tdb_off_t off, tdb_len_t len) -{ - TDB_DATA d; - - d.dsize = len; - - if (tdb->transaction == NULL && tdb->map_ptr != NULL) - d.dptr = (unsigned char *)tdb->map_ptr + off; - else - d.dptr = tdb_alloc_read(tdb, off, d.dsize); - return d; -} - -/* Frees data if we're not able to simply use mmap. */ -static void put_bytes(struct tdb_context *tdb, TDB_DATA d) -{ - if (tdb->transaction == NULL && tdb->map_ptr != NULL) - return; - free(d.dptr); -} - -/* We use the excellent Jenkins lookup3 hash; this is based on hash_word2. - * See: http://burtleburtle.net/bob/c/lookup3.c - */ -#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) -static void hash(uint32_t key, uint32_t *pc, uint32_t *pb) -{ - uint32_t a,b,c; - - /* Set up the internal state */ - a = b = c = 0xdeadbeef + *pc; - c += *pb; - a += key; - c ^= b; c -= rot(b,14); - a ^= c; a -= rot(c,11); - b ^= a; b -= rot(a,25); - c ^= b; c -= rot(b,16); - a ^= c; a -= rot(c,4); - b ^= a; b -= rot(a,14); - c ^= b; c -= rot(b,24); - *pc=c; *pb=b; -} - -/* - We want to check that all free records are in the free list - (only once), and all free list entries are free records. Similarly - for each hash chain of used records. - - Doing that naively (without walking hash chains, since we want to be - linear) means keeping a list of records which have been seen in each - hash chain, and another of records pointed to (ie. next pointers - from records and the initial hash chain heads). These two lists - should be equal. This will take 8 bytes per record, and require - sorting at the end. - - So instead, we record each offset in a bitmap such a way that - recording it twice will cancel out. Since each offset should appear - exactly twice, the bitmap should be zero at the end. - - The approach was inspired by Bloom Filters (see Wikipedia). For - each value, we flip K bits in a bitmap of size N. The number of - distinct arrangements is: - - N! / (K! * (N-K)!) - - Of course, not all arrangements are actually distinct, but testing - shows this formula to be close enough. - - So, if K == 8 and N == 256, the probability of two things flipping the same - bits is 1 in 409,663,695,276,000. - - Given that ldb uses a hash size of 10000, using 32 bytes per hash chain - (320k) seems reasonable. -*/ -#define NUM_HASHES 8 -#define BITMAP_BITS 256 - -static void bit_flip(unsigned char bits[], unsigned int idx) -{ - bits[idx / CHAR_BIT] ^= (1 << (idx % CHAR_BIT)); -} - -/* We record offsets in a bitmap for the particular chain it should be in. */ -static void record_offset(unsigned char bits[], tdb_off_t off) -{ - uint32_t h1 = off, h2 = 0; - unsigned int i; - - /* We get two good hash values out of jhash2, so we use both. Then - * we keep going to produce further hash values. */ - for (i = 0; i < NUM_HASHES / 2; i++) { - hash(off, &h1, &h2); - bit_flip(bits, h1 % BITMAP_BITS); - bit_flip(bits, h2 % BITMAP_BITS); - h2++; - } -} - -/* Check that an in-use record is valid. */ -static bool tdb_check_used_record(struct tdb_context *tdb, - tdb_off_t off, - const struct tdb_record *rec, - unsigned char **hashes, - int (*check)(TDB_DATA, TDB_DATA, void *), - void *private_data) -{ - TDB_DATA key, data; - - if (!tdb_check_record(tdb, off, rec)) - return false; - - /* key + data + tailer must fit in record */ - if (rec->key_len + rec->data_len + sizeof(tdb_off_t) > rec->rec_len) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d too short for contents\n", off)); - return false; - } - - key = get_bytes(tdb, off + sizeof(*rec), rec->key_len); - if (!key.dptr) - return false; - - if (tdb->hash_fn(&key) != rec->full_hash) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Record offset %d has incorrect hash\n", off)); - goto fail_put_key; - } - - /* Mark this offset as a known value for this hash bucket. */ - record_offset(hashes[BUCKET(rec->full_hash)+1], off); - /* And similarly if the next pointer is valid. */ - if (rec->next) - record_offset(hashes[BUCKET(rec->full_hash)+1], rec->next); - - /* If they supply a check function and this record isn't dead, - get data and feed it. */ - if (check && rec->magic != TDB_DEAD_MAGIC) { - data = get_bytes(tdb, off + sizeof(*rec) + rec->key_len, - rec->data_len); - if (!data.dptr) - goto fail_put_key; - - if (check(key, data, private_data) == -1) - goto fail_put_data; - put_bytes(tdb, data); - } - - put_bytes(tdb, key); - return true; - -fail_put_data: - put_bytes(tdb, data); -fail_put_key: - put_bytes(tdb, key); - return false; -} - -/* Check that an unused record is valid. */ -static bool tdb_check_free_record(struct tdb_context *tdb, - tdb_off_t off, - const struct tdb_record *rec, - unsigned char **hashes) -{ - if (!tdb_check_record(tdb, off, rec)) - return false; - - /* Mark this offset as a known value for the free list. */ - record_offset(hashes[0], off); - /* And similarly if the next pointer is valid. */ - if (rec->next) - record_offset(hashes[0], rec->next); - return true; -} - -int tdb_check(struct tdb_context *tdb, - int (*check)(TDB_DATA key, TDB_DATA data, void *private_data), - void *private_data) -{ - unsigned int h; - unsigned char **hashes; - tdb_off_t off, recovery_start; - struct tdb_record rec; - bool found_recovery = false; - - if (tdb_lockall_read(tdb) == -1) - return -1; - - /* Make sure we know true size of the underlying file. */ - tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1); - - /* Header must be OK: also gets us the recovery ptr, if any. */ - if (!tdb_check_header(tdb, &recovery_start)) - goto unlock; - - /* We should have the whole header, too. */ - if (tdb->map_size < TDB_DATA_START(tdb->header.hash_size)) { - tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_ERROR, "File too short for hashes\n")); - goto unlock; - } - - /* One big malloc: pointers then bit arrays. */ - hashes = (unsigned char **)calloc( - 1, sizeof(hashes[0]) * (1+tdb->header.hash_size) - + BITMAP_BITS / CHAR_BIT * (1+tdb->header.hash_size)); - if (!hashes) { - tdb->ecode = TDB_ERR_OOM; - goto unlock; - } - - /* Initialize pointers */ - hashes[0] = (unsigned char *)(&hashes[1+tdb->header.hash_size]); - for (h = 1; h < 1+tdb->header.hash_size; h++) - hashes[h] = hashes[h-1] + BITMAP_BITS / CHAR_BIT; - - /* Freelist and hash headers are all in a row: read them. */ - for (h = 0; h < 1+tdb->header.hash_size; h++) { - if (tdb_ofs_read(tdb, FREELIST_TOP + h*sizeof(tdb_off_t), - &off) == -1) - goto free; - if (off) - record_offset(hashes[h], off); - } - - /* For each record, read it in and check it's ok. */ - for (off = TDB_DATA_START(tdb->header.hash_size); - off < tdb->map_size; - off += sizeof(rec) + rec.rec_len) { - if (tdb->methods->tdb_read(tdb, off, &rec, sizeof(rec), - DOCONV()) == -1) - goto free; - switch (rec.magic) { - case TDB_MAGIC: - case TDB_DEAD_MAGIC: - if (!tdb_check_used_record(tdb, off, &rec, hashes, - check, private_data)) - goto free; - break; - case TDB_FREE_MAGIC: - if (!tdb_check_free_record(tdb, off, &rec, hashes)) - goto free; - break; - case TDB_RECOVERY_MAGIC: - case TDB_RECOVERY_INVALID_MAGIC: - if (recovery_start != off) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Unexpected recovery record at offset %d\n", - off)); - goto free; - } - found_recovery = true; - break; - default: - tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Bad magic 0x%x at offset %d\n", - rec.magic, off)); - goto free; - } - } - - /* Now, hashes should all be empty: each record exists and is referred - * to by one other. */ - for (h = 0; h < 1+tdb->header.hash_size; h++) { - unsigned int i; - for (i = 0; i < BITMAP_BITS / CHAR_BIT; i++) { - if (hashes[h][i] != 0) { - tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Hashes do not match records\n")); - goto free; - } - } - } - - /* We must have found recovery area if there was one. */ - if (recovery_start != 0 && !found_recovery) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "Expected %s recovery area, got %s\n", - recovery_start ? "a" : "no", - found_recovery ? "one" : "none")); - goto free; - } - - free(hashes); - tdb_unlockall_read(tdb); - return 0; - -free: - free(hashes); -unlock: - tdb_unlockall_read(tdb); - return -1; -} diff --git a/bundled/tdb/common/dump.c b/bundled/tdb/common/dump.c deleted file mode 100644 index 9f770f81..00000000 --- a/bundled/tdb/common/dump.c +++ /dev/null @@ -1,137 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Andrew Tridgell 1999-2005 - Copyright (C) Paul `Rusty' Russell 2000 - Copyright (C) Jeremy Allison 2000-2003 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "tdb_private.h" - -static tdb_off_t tdb_dump_record(struct tdb_context *tdb, int hash, - tdb_off_t offset) -{ - struct tdb_record rec; - tdb_off_t tailer_ofs, tailer; - - if (tdb->methods->tdb_read(tdb, offset, (char *)&rec, - sizeof(rec), DOCONV()) == -1) { - printf("ERROR: failed to read record at %u\n", offset); - return 0; - } - - printf(" rec: hash=%d offset=0x%08x next=0x%08x rec_len=%d " - "key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n", - hash, offset, rec.next, rec.rec_len, rec.key_len, rec.data_len, - rec.full_hash, rec.magic); - - tailer_ofs = offset + sizeof(rec) + rec.rec_len - sizeof(tdb_off_t); - - if (tdb_ofs_read(tdb, tailer_ofs, &tailer) == -1) { - printf("ERROR: failed to read tailer at %u\n", tailer_ofs); - return rec.next; - } - - if (tailer != rec.rec_len + sizeof(rec)) { - printf("ERROR: tailer does not match record! tailer=%u totalsize=%u\n", - (unsigned int)tailer, (unsigned int)(rec.rec_len + sizeof(rec))); - } - return rec.next; -} - -static int tdb_dump_chain(struct tdb_context *tdb, int i) -{ - tdb_off_t rec_ptr, top; - - top = TDB_HASH_TOP(i); - - if (tdb_lock(tdb, i, F_WRLCK) != 0) - return -1; - - if (tdb_ofs_read(tdb, top, &rec_ptr) == -1) - return tdb_unlock(tdb, i, F_WRLCK); - - if (rec_ptr) - printf("hash=%d\n", i); - - while (rec_ptr) { - rec_ptr = tdb_dump_record(tdb, i, rec_ptr); - } - - return tdb_unlock(tdb, i, F_WRLCK); -} - -void tdb_dump_all(struct tdb_context *tdb) -{ - int i; - for (i=0;iheader.hash_size;i++) { - tdb_dump_chain(tdb, i); - } - printf("freelist:\n"); - tdb_dump_chain(tdb, -1); -} - -int tdb_printfreelist(struct tdb_context *tdb) -{ - int ret; - long total_free = 0; - tdb_off_t offset, rec_ptr; - struct tdb_record rec; - - if ((ret = tdb_lock(tdb, -1, F_WRLCK)) != 0) - return ret; - - offset = FREELIST_TOP; - - /* read in the freelist top */ - if (tdb_ofs_read(tdb, offset, &rec_ptr) == -1) { - tdb_unlock(tdb, -1, F_WRLCK); - return 0; - } - - printf("freelist top=[0x%08x]\n", rec_ptr ); - while (rec_ptr) { - if (tdb->methods->tdb_read(tdb, rec_ptr, (char *)&rec, - sizeof(rec), DOCONV()) == -1) { - tdb_unlock(tdb, -1, F_WRLCK); - return -1; - } - - if (rec.magic != TDB_FREE_MAGIC) { - printf("bad magic 0x%08x in free list\n", rec.magic); - tdb_unlock(tdb, -1, F_WRLCK); - return -1; - } - - printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%d)] (end = 0x%08x)\n", - rec_ptr, rec.rec_len, rec.rec_len, rec_ptr + rec.rec_len); - total_free += rec.rec_len; - - /* move to the next record */ - rec_ptr = rec.next; - } - printf("total rec_len = [0x%08x (%d)]\n", (int)total_free, - (int)total_free); - - return tdb_unlock(tdb, -1, F_WRLCK); -} - diff --git a/bundled/tdb/common/error.c b/bundled/tdb/common/error.c deleted file mode 100644 index 9197918d..00000000 --- a/bundled/tdb/common/error.c +++ /dev/null @@ -1,57 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Andrew Tridgell 1999-2005 - Copyright (C) Paul `Rusty' Russell 2000 - Copyright (C) Jeremy Allison 2000-2003 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "tdb_private.h" - -enum TDB_ERROR tdb_error(struct tdb_context *tdb) -{ - return tdb->ecode; -} - -static struct tdb_errname { - enum TDB_ERROR ecode; const char *estring; -} emap[] = { {TDB_SUCCESS, "Success"}, - {TDB_ERR_CORRUPT, "Corrupt database"}, - {TDB_ERR_IO, "IO Error"}, - {TDB_ERR_LOCK, "Locking error"}, - {TDB_ERR_OOM, "Out of memory"}, - {TDB_ERR_EXISTS, "Record exists"}, - {TDB_ERR_NOLOCK, "Lock exists on other keys"}, - {TDB_ERR_EINVAL, "Invalid parameter"}, - {TDB_ERR_NOEXIST, "Record does not exist"}, - {TDB_ERR_RDONLY, "write not permitted"} }; - -/* Error string for the last tdb error */ -const char *tdb_errorstr(struct tdb_context *tdb) -{ - uint32_t i; - for (i = 0; i < sizeof(emap) / sizeof(struct tdb_errname); i++) - if (tdb->ecode == emap[i].ecode) - return emap[i].estring; - return "Invalid error code"; -} - diff --git a/bundled/tdb/common/freelist.c b/bundled/tdb/common/freelist.c deleted file mode 100644 index 79e3c344..00000000 --- a/bundled/tdb/common/freelist.c +++ /dev/null @@ -1,386 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Andrew Tridgell 1999-2005 - Copyright (C) Paul `Rusty' Russell 2000 - Copyright (C) Jeremy Allison 2000-2003 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "tdb_private.h" - -/* 'right' merges can involve O(n^2) cost when combined with a - traverse, so they are disabled until we find a way to do them in - O(1) time -*/ -#define USE_RIGHT_MERGES 0 - -/* read a freelist record and check for simple errors */ -int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct tdb_record *rec) -{ - if (tdb->methods->tdb_read(tdb, off, rec, sizeof(*rec),DOCONV()) == -1) - return -1; - - if (rec->magic == TDB_MAGIC) { - /* this happens when a app is showdown while deleting a record - we should - not completely fail when this happens */ - TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read non-free magic 0x%x at offset=%d - fixing\n", - rec->magic, off)); - rec->magic = TDB_FREE_MAGIC; - if (tdb->methods->tdb_write(tdb, off, rec, sizeof(*rec)) == -1) - return -1; - } - - if (rec->magic != TDB_FREE_MAGIC) { - /* Ensure ecode is set for log fn. */ - tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_rec_free_read bad magic 0x%x at offset=%d\n", - rec->magic, off)); - return -1; - } - if (tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0) != 0) - return -1; - return 0; -} - - -#if USE_RIGHT_MERGES -/* Remove an element from the freelist. Must have alloc lock. */ -static int remove_from_freelist(struct tdb_context *tdb, tdb_off_t off, tdb_off_t next) -{ - tdb_off_t last_ptr, i; - - /* read in the freelist top */ - last_ptr = FREELIST_TOP; - while (tdb_ofs_read(tdb, last_ptr, &i) != -1 && i != 0) { - if (i == off) { - /* We've found it! */ - return tdb_ofs_write(tdb, last_ptr, &next); - } - /* Follow chain (next offset is at start of record) */ - last_ptr = i; - } - tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"remove_from_freelist: not on list at off=%d\n", off)); - return -1; -} -#endif - - -/* update a record tailer (must hold allocation lock) */ -static int update_tailer(struct tdb_context *tdb, tdb_off_t offset, - const struct tdb_record *rec) -{ - tdb_off_t totalsize; - - /* Offset of tailer from record header */ - totalsize = sizeof(*rec) + rec->rec_len; - return tdb_ofs_write(tdb, offset + totalsize - sizeof(tdb_off_t), - &totalsize); -} - -/* Add an element into the freelist. Merge adjacent records if - necessary. */ -int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec) -{ - /* Allocation and tailer lock */ - if (tdb_lock(tdb, -1, F_WRLCK) != 0) - return -1; - - /* set an initial tailer, so if we fail we don't leave a bogus record */ - if (update_tailer(tdb, offset, rec) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_tailer failed!\n")); - goto fail; - } - -#if USE_RIGHT_MERGES - /* Look right first (I'm an Australian, dammit) */ - if (offset + sizeof(*rec) + rec->rec_len + sizeof(*rec) <= tdb->map_size) { - tdb_off_t right = offset + sizeof(*rec) + rec->rec_len; - struct tdb_record r; - - if (tdb->methods->tdb_read(tdb, right, &r, sizeof(r), DOCONV()) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right read failed at %u\n", right)); - goto left; - } - - /* If it's free, expand to include it. */ - if (r.magic == TDB_FREE_MAGIC) { - if (remove_from_freelist(tdb, right, r.next) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right free failed at %u\n", right)); - goto left; - } - rec->rec_len += sizeof(r) + r.rec_len; - if (update_tailer(tdb, offset, rec) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_tailer failed at %u\n", offset)); - goto fail; - } - } - } -left: -#endif - - /* Look left */ - if (offset - sizeof(tdb_off_t) > TDB_DATA_START(tdb->header.hash_size)) { - tdb_off_t left = offset - sizeof(tdb_off_t); - struct tdb_record l; - tdb_off_t leftsize; - - /* Read in tailer and jump back to header */ - if (tdb_ofs_read(tdb, left, &leftsize) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: left offset read failed at %u\n", left)); - goto update; - } - - /* it could be uninitialised data */ - if (leftsize == 0 || leftsize == TDB_PAD_U32) { - goto update; - } - - left = offset - leftsize; - - if (leftsize > offset || - left < TDB_DATA_START(tdb->header.hash_size)) { - goto update; - } - - /* Now read in the left record */ - if (tdb->methods->tdb_read(tdb, left, &l, sizeof(l), DOCONV()) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: left read failed at %u (%u)\n", left, leftsize)); - goto update; - } - - /* If it's free, expand to include it. */ - if (l.magic == TDB_FREE_MAGIC) { - /* we now merge the new record into the left record, rather than the other - way around. This makes the operation O(1) instead of O(n). This change - prevents traverse from being O(n^2) after a lot of deletes */ - l.rec_len += sizeof(*rec) + rec->rec_len; - if (tdb_rec_write(tdb, left, &l) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_left failed at %u\n", left)); - goto fail; - } - if (update_tailer(tdb, left, &l) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: update_tailer failed at %u\n", offset)); - goto fail; - } - tdb_unlock(tdb, -1, F_WRLCK); - return 0; - } - } - -update: - - /* Now, prepend to free list */ - rec->magic = TDB_FREE_MAGIC; - - if (tdb_ofs_read(tdb, FREELIST_TOP, &rec->next) == -1 || - tdb_rec_write(tdb, offset, rec) == -1 || - tdb_ofs_write(tdb, FREELIST_TOP, &offset) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free record write failed at offset=%d\n", offset)); - goto fail; - } - - /* And we're done. */ - tdb_unlock(tdb, -1, F_WRLCK); - return 0; - - fail: - tdb_unlock(tdb, -1, F_WRLCK); - return -1; -} - - - -/* - the core of tdb_allocate - called when we have decided which - free list entry to use - - Note that we try to allocate by grabbing data from the end of an existing record, - not the beginning. This is so the left merge in a free is more likely to be - able to free up the record without fragmentation - */ -static tdb_off_t tdb_allocate_ofs(struct tdb_context *tdb, - tdb_len_t length, tdb_off_t rec_ptr, - struct tdb_record *rec, tdb_off_t last_ptr) -{ -#define MIN_REC_SIZE (sizeof(struct tdb_record) + sizeof(tdb_off_t) + 8) - - if (rec->rec_len < length + MIN_REC_SIZE) { - /* we have to grab the whole record */ - - /* unlink it from the previous record */ - if (tdb_ofs_write(tdb, last_ptr, &rec->next) == -1) { - return 0; - } - - /* mark it not free */ - rec->magic = TDB_MAGIC; - if (tdb_rec_write(tdb, rec_ptr, rec) == -1) { - return 0; - } - return rec_ptr; - } - - /* we're going to just shorten the existing record */ - rec->rec_len -= (length + sizeof(*rec)); - if (tdb_rec_write(tdb, rec_ptr, rec) == -1) { - return 0; - } - if (update_tailer(tdb, rec_ptr, rec) == -1) { - return 0; - } - - /* and setup the new record */ - rec_ptr += sizeof(*rec) + rec->rec_len; - - memset(rec, '\0', sizeof(*rec)); - rec->rec_len = length; - rec->magic = TDB_MAGIC; - - if (tdb_rec_write(tdb, rec_ptr, rec) == -1) { - return 0; - } - - if (update_tailer(tdb, rec_ptr, rec) == -1) { - return 0; - } - - return rec_ptr; -} - -/* allocate some space from the free list. The offset returned points - to a unconnected tdb_record within the database with room for at - least length bytes of total data - - 0 is returned if the space could not be allocated - */ -tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct tdb_record *rec) -{ - tdb_off_t rec_ptr, last_ptr, newrec_ptr; - struct { - tdb_off_t rec_ptr, last_ptr; - tdb_len_t rec_len; - } bestfit; - float multiplier = 1.0; - - if (tdb_lock(tdb, -1, F_WRLCK) == -1) - return 0; - - /* over-allocate to reduce fragmentation */ - length *= 1.25; - - /* Extra bytes required for tailer */ - length += sizeof(tdb_off_t); - length = TDB_ALIGN(length, TDB_ALIGNMENT); - - again: - last_ptr = FREELIST_TOP; - - /* read in the freelist top */ - if (tdb_ofs_read(tdb, FREELIST_TOP, &rec_ptr) == -1) - goto fail; - - bestfit.rec_ptr = 0; - bestfit.last_ptr = 0; - bestfit.rec_len = 0; - - /* - this is a best fit allocation strategy. Originally we used - a first fit strategy, but it suffered from massive fragmentation - issues when faced with a slowly increasing record size. - */ - while (rec_ptr) { - if (tdb_rec_free_read(tdb, rec_ptr, rec) == -1) { - goto fail; - } - - if (rec->rec_len >= length) { - if (bestfit.rec_ptr == 0 || - rec->rec_len < bestfit.rec_len) { - bestfit.rec_len = rec->rec_len; - bestfit.rec_ptr = rec_ptr; - bestfit.last_ptr = last_ptr; - } - } - - /* move to the next record */ - last_ptr = rec_ptr; - rec_ptr = rec->next; - - /* if we've found a record that is big enough, then - stop searching if its also not too big. The - definition of 'too big' changes as we scan - through */ - if (bestfit.rec_len > 0 && - bestfit.rec_len < length * multiplier) { - break; - } - - /* this multiplier means we only extremely rarely - search more than 50 or so records. At 50 records we - accept records up to 11 times larger than what we - want */ - multiplier *= 1.05; - } - - if (bestfit.rec_ptr != 0) { - if (tdb_rec_free_read(tdb, bestfit.rec_ptr, rec) == -1) { - goto fail; - } - - newrec_ptr = tdb_allocate_ofs(tdb, length, bestfit.rec_ptr, - rec, bestfit.last_ptr); - tdb_unlock(tdb, -1, F_WRLCK); - return newrec_ptr; - } - - /* we didn't find enough space. See if we can expand the - database and if we can then try again */ - if (tdb_expand(tdb, length + sizeof(*rec)) == 0) - goto again; - fail: - tdb_unlock(tdb, -1, F_WRLCK); - return 0; -} - - - -/* - return the size of the freelist - used to decide if we should repack -*/ -int tdb_freelist_size(struct tdb_context *tdb) -{ - tdb_off_t ptr; - int count=0; - - if (tdb_lock(tdb, -1, F_RDLCK) == -1) { - return -1; - } - - ptr = FREELIST_TOP; - while (tdb_ofs_read(tdb, ptr, &ptr) == 0 && ptr != 0) { - count++; - } - - tdb_unlock(tdb, -1, F_RDLCK); - return count; -} diff --git a/bundled/tdb/common/freelistcheck.c b/bundled/tdb/common/freelistcheck.c deleted file mode 100644 index 8d1ebabe..00000000 --- a/bundled/tdb/common/freelistcheck.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Jeremy Allison 2006 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "tdb_private.h" - -/* Check the freelist is good and contains no loops. - Very memory intensive - only do this as a consistency - checker. Heh heh - uses an in memory tdb as the storage - for the "seen" record list. For some reason this strikes - me as extremely clever as I don't have to write another tree - data structure implementation :-). - */ - -static int seen_insert(struct tdb_context *mem_tdb, tdb_off_t rec_ptr) -{ - TDB_DATA key, data; - - memset(&data, '\0', sizeof(data)); - key.dptr = (unsigned char *)&rec_ptr; - key.dsize = sizeof(rec_ptr); - return tdb_store(mem_tdb, key, data, TDB_INSERT); -} - -int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries) -{ - struct tdb_context *mem_tdb = NULL; - struct tdb_record rec; - tdb_off_t rec_ptr, last_ptr; - int ret = -1; - - *pnum_entries = 0; - - mem_tdb = tdb_open("flval", tdb->header.hash_size, - TDB_INTERNAL, O_RDWR, 0600); - if (!mem_tdb) { - return -1; - } - - if (tdb_lock(tdb, -1, F_WRLCK) == -1) { - tdb_close(mem_tdb); - return 0; - } - - last_ptr = FREELIST_TOP; - - /* Store the FREELIST_TOP record. */ - if (seen_insert(mem_tdb, last_ptr) == -1) { - tdb->ecode = TDB_ERR_CORRUPT; - ret = -1; - goto fail; - } - - /* read in the freelist top */ - if (tdb_ofs_read(tdb, FREELIST_TOP, &rec_ptr) == -1) { - goto fail; - } - - while (rec_ptr) { - - /* If we can't store this record (we've seen it - before) then the free list has a loop and must - be corrupt. */ - - if (seen_insert(mem_tdb, rec_ptr)) { - tdb->ecode = TDB_ERR_CORRUPT; - ret = -1; - goto fail; - } - - if (tdb_rec_free_read(tdb, rec_ptr, &rec) == -1) { - goto fail; - } - - /* move to the next record */ - last_ptr = rec_ptr; - rec_ptr = rec.next; - *pnum_entries += 1; - } - - ret = 0; - - fail: - - tdb_close(mem_tdb); - tdb_unlock(tdb, -1, F_WRLCK); - return ret; -} diff --git a/bundled/tdb/common/io.c b/bundled/tdb/common/io.c deleted file mode 100644 index 058ca6c6..00000000 --- a/bundled/tdb/common/io.c +++ /dev/null @@ -1,472 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Andrew Tridgell 1999-2005 - Copyright (C) Paul `Rusty' Russell 2000 - Copyright (C) Jeremy Allison 2000-2003 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - - -#include "tdb_private.h" - -/* check for an out of bounds access - if it is out of bounds then - see if the database has been expanded by someone else and expand - if necessary - note that "len" is the minimum length needed for the db -*/ -static int tdb_oob(struct tdb_context *tdb, tdb_off_t len, int probe) -{ - struct stat st; - if (len <= tdb->map_size) - return 0; - if (tdb->flags & TDB_INTERNAL) { - if (!probe) { - /* Ensure ecode is set for log fn. */ - tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_oob len %d beyond internal malloc size %d\n", - (int)len, (int)tdb->map_size)); - } - return -1; - } - - if (fstat(tdb->fd, &st) == -1) { - tdb->ecode = TDB_ERR_IO; - return -1; - } - - if (st.st_size < (size_t)len) { - if (!probe) { - /* Ensure ecode is set for log fn. */ - tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_oob len %d beyond eof at %d\n", - (int)len, (int)st.st_size)); - } - return -1; - } - - /* Unmap, update size, remap */ - if (tdb_munmap(tdb) == -1) { - tdb->ecode = TDB_ERR_IO; - return -1; - } - tdb->map_size = st.st_size; - tdb_mmap(tdb); - return 0; -} - -/* write a lump of data at a specified offset */ -static int tdb_write(struct tdb_context *tdb, tdb_off_t off, - const void *buf, tdb_len_t len) -{ - if (len == 0) { - return 0; - } - - if (tdb->read_only || tdb->traverse_read) { - tdb->ecode = TDB_ERR_RDONLY; - return -1; - } - - if (tdb->methods->tdb_oob(tdb, off + len, 0) != 0) - return -1; - - if (tdb->map_ptr) { - memcpy(off + (char *)tdb->map_ptr, buf, len); - } else { - ssize_t written = pwrite(tdb->fd, buf, len, off); - if ((written != (ssize_t)len) && (written != -1)) { - /* try once more */ - tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: wrote only " - "%d of %d bytes at %d, trying once more\n", - (int)written, len, off)); - written = pwrite(tdb->fd, (const char *)buf+written, - len-written, - off+written); - } - if (written == -1) { - /* Ensure ecode is set for log fn. */ - tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d " - "len=%d (%s)\n", off, len, strerror(errno))); - return -1; - } else if (written != (ssize_t)len) { - tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_write: failed to " - "write %d bytes at %d in two attempts\n", - len, off)); - return -1; - } - } - return 0; -} - -/* Endian conversion: we only ever deal with 4 byte quantities */ -void *tdb_convert(void *buf, uint32_t size) -{ - uint32_t i, *p = (uint32_t *)buf; - for (i = 0; i < size / 4; i++) - p[i] = TDB_BYTEREV(p[i]); - return buf; -} - - -/* read a lump of data at a specified offset, maybe convert */ -static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf, - tdb_len_t len, int cv) -{ - if (tdb->methods->tdb_oob(tdb, off + len, 0) != 0) { - return -1; - } - - if (tdb->map_ptr) { - memcpy(buf, off + (char *)tdb->map_ptr, len); - } else { - ssize_t ret = pread(tdb->fd, buf, len, off); - if (ret != (ssize_t)len) { - /* Ensure ecode is set for log fn. */ - tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_read failed at %d " - "len=%d ret=%d (%s) map_size=%d\n", - (int)off, (int)len, (int)ret, strerror(errno), - (int)tdb->map_size)); - return -1; - } - } - if (cv) { - tdb_convert(buf, len); - } - return 0; -} - - - -/* - do an unlocked scan of the hash table heads to find the next non-zero head. The value - will then be confirmed with the lock held -*/ -static void tdb_next_hash_chain(struct tdb_context *tdb, uint32_t *chain) -{ - uint32_t h = *chain; - if (tdb->map_ptr) { - for (;h < tdb->header.hash_size;h++) { - if (0 != *(uint32_t *)(TDB_HASH_TOP(h) + (unsigned char *)tdb->map_ptr)) { - break; - } - } - } else { - uint32_t off=0; - for (;h < tdb->header.hash_size;h++) { - if (tdb_ofs_read(tdb, TDB_HASH_TOP(h), &off) != 0 || off != 0) { - break; - } - } - } - (*chain) = h; -} - - -int tdb_munmap(struct tdb_context *tdb) -{ - if (tdb->flags & TDB_INTERNAL) - return 0; - -#ifdef HAVE_MMAP - if (tdb->map_ptr) { - int ret; - - ret = munmap(tdb->map_ptr, tdb->map_size); - if (ret != 0) - return ret; - } -#endif - tdb->map_ptr = NULL; - return 0; -} - -void tdb_mmap(struct tdb_context *tdb) -{ - if (tdb->flags & TDB_INTERNAL) - return; - -#ifdef HAVE_MMAP - if (!(tdb->flags & TDB_NOMMAP)) { - tdb->map_ptr = mmap(NULL, tdb->map_size, - PROT_READ|(tdb->read_only? 0:PROT_WRITE), - MAP_SHARED|MAP_FILE, tdb->fd, 0); - - /* - * NB. When mmap fails it returns MAP_FAILED *NOT* NULL !!!! - */ - - if (tdb->map_ptr == MAP_FAILED) { - tdb->map_ptr = NULL; - TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_mmap failed for size %d (%s)\n", - tdb->map_size, strerror(errno))); - } - } else { - tdb->map_ptr = NULL; - } -#else - tdb->map_ptr = NULL; -#endif -} - -/* expand a file. we prefer to use ftruncate, as that is what posix - says to use for mmap expansion */ -static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t addition) -{ - char buf[8192]; - - if (tdb->read_only || tdb->traverse_read) { - tdb->ecode = TDB_ERR_RDONLY; - return -1; - } - - if (ftruncate(tdb->fd, size+addition) == -1) { - char b = 0; - ssize_t written = pwrite(tdb->fd, &b, 1, (size+addition) - 1); - if (written == 0) { - /* try once more, potentially revealing errno */ - written = pwrite(tdb->fd, &b, 1, (size+addition) - 1); - } - if (written == 0) { - /* again - give up, guessing errno */ - errno = ENOSPC; - } - if (written != 1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file to %d failed (%s)\n", - size+addition, strerror(errno))); - return -1; - } - } - - /* now fill the file with something. This ensures that the - file isn't sparse, which would be very bad if we ran out of - disk. This must be done with write, not via mmap */ - memset(buf, TDB_PAD_BYTE, sizeof(buf)); - while (addition) { - size_t n = addition>sizeof(buf)?sizeof(buf):addition; - ssize_t written = pwrite(tdb->fd, buf, n, size); - if (written == 0) { - /* prevent infinite loops: try _once_ more */ - written = pwrite(tdb->fd, buf, n, size); - } - if (written == 0) { - /* give up, trying to provide a useful errno */ - TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write " - "returned 0 twice: giving up!\n")); - errno = ENOSPC; - return -1; - } else if (written == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "expand_file write of " - "%d bytes failed (%s)\n", (int)n, - strerror(errno))); - return -1; - } else if (written != n) { - TDB_LOG((tdb, TDB_DEBUG_WARNING, "expand_file: wrote " - "only %d of %d bytes - retrying\n", (int)written, - (int)n)); - } - addition -= written; - size += written; - } - return 0; -} - - -/* expand the database at least size bytes by expanding the underlying - file and doing the mmap again if necessary */ -int tdb_expand(struct tdb_context *tdb, tdb_off_t size) -{ - struct tdb_record rec; - tdb_off_t offset, new_size; - - if (tdb_lock(tdb, -1, F_WRLCK) == -1) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "lock failed in tdb_expand\n")); - return -1; - } - - /* must know about any previous expansions by another process */ - tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1); - - /* always make room for at least 100 more records, and at - least 25% more space. Round the database up to a multiple - of the page size */ - new_size = MAX(tdb->map_size + size*100, tdb->map_size * 1.25); - size = TDB_ALIGN(new_size, tdb->page_size) - tdb->map_size; - - if (!(tdb->flags & TDB_INTERNAL)) - tdb_munmap(tdb); - - /* - * We must ensure the file is unmapped before doing this - * to ensure consistency with systems like OpenBSD where - * writes and mmaps are not consistent. - */ - - /* expand the file itself */ - if (!(tdb->flags & TDB_INTERNAL)) { - if (tdb->methods->tdb_expand_file(tdb, tdb->map_size, size) != 0) - goto fail; - } - - tdb->map_size += size; - - if (tdb->flags & TDB_INTERNAL) { - char *new_map_ptr = (char *)realloc(tdb->map_ptr, - tdb->map_size); - if (!new_map_ptr) { - tdb->map_size -= size; - goto fail; - } - tdb->map_ptr = new_map_ptr; - } else { - /* - * We must ensure the file is remapped before adding the space - * to ensure consistency with systems like OpenBSD where - * writes and mmaps are not consistent. - */ - - /* We're ok if the mmap fails as we'll fallback to read/write */ - tdb_mmap(tdb); - } - - /* form a new freelist record */ - memset(&rec,'\0',sizeof(rec)); - rec.rec_len = size - sizeof(rec); - - /* link it into the free list */ - offset = tdb->map_size - size; - if (tdb_free(tdb, offset, &rec) == -1) - goto fail; - - tdb_unlock(tdb, -1, F_WRLCK); - return 0; - fail: - tdb_unlock(tdb, -1, F_WRLCK); - return -1; -} - -/* read/write a tdb_off_t */ -int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d) -{ - return tdb->methods->tdb_read(tdb, offset, (char*)d, sizeof(*d), DOCONV()); -} - -int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d) -{ - tdb_off_t off = *d; - return tdb->methods->tdb_write(tdb, offset, CONVERT(off), sizeof(*d)); -} - - -/* read a lump of data, allocating the space for it */ -unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len) -{ - unsigned char *buf; - - /* some systems don't like zero length malloc */ - - if (!(buf = (unsigned char *)malloc(len ? len : 1))) { - /* Ensure ecode is set for log fn. */ - tdb->ecode = TDB_ERR_OOM; - TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_alloc_read malloc failed len=%d (%s)\n", - len, strerror(errno))); - return NULL; - } - if (tdb->methods->tdb_read(tdb, offset, buf, len, 0) == -1) { - SAFE_FREE(buf); - return NULL; - } - return buf; -} - -/* Give a piece of tdb data to a parser */ - -int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key, - tdb_off_t offset, tdb_len_t len, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data) -{ - TDB_DATA data; - int result; - - data.dsize = len; - - if ((tdb->transaction == NULL) && (tdb->map_ptr != NULL)) { - /* - * Optimize by avoiding the malloc/memcpy/free, point the - * parser directly at the mmap area. - */ - if (tdb->methods->tdb_oob(tdb, offset+len, 0) != 0) { - return -1; - } - data.dptr = offset + (unsigned char *)tdb->map_ptr; - return parser(key, data, private_data); - } - - if (!(data.dptr = tdb_alloc_read(tdb, offset, len))) { - return -1; - } - - result = parser(key, data, private_data); - free(data.dptr); - return result; -} - -/* read/write a record */ -int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec) -{ - if (tdb->methods->tdb_read(tdb, offset, rec, sizeof(*rec),DOCONV()) == -1) - return -1; - if (TDB_BAD_MAGIC(rec)) { - /* Ensure ecode is set for log fn. */ - tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_rec_read bad magic 0x%x at offset=%d\n", rec->magic, offset)); - return -1; - } - return tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0); -} - -int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec) -{ - struct tdb_record r = *rec; - return tdb->methods->tdb_write(tdb, offset, CONVERT(r), sizeof(r)); -} - -static const struct tdb_methods io_methods = { - tdb_read, - tdb_write, - tdb_next_hash_chain, - tdb_oob, - tdb_expand_file, -}; - -/* - initialise the default methods table -*/ -void tdb_io_init(struct tdb_context *tdb) -{ - tdb->methods = &io_methods; -} diff --git a/bundled/tdb/common/lock.c b/bundled/tdb/common/lock.c deleted file mode 100644 index 803feeec..00000000 --- a/bundled/tdb/common/lock.c +++ /dev/null @@ -1,863 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Andrew Tridgell 1999-2005 - Copyright (C) Paul `Rusty' Russell 2000 - Copyright (C) Jeremy Allison 2000-2003 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "tdb_private.h" - -void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *ptr) -{ - tdb->interrupt_sig_ptr = ptr; -} - -static int fcntl_lock(struct tdb_context *tdb, - int rw, off_t off, off_t len, bool waitflag) -{ - struct flock fl; - - fl.l_type = rw; - fl.l_whence = SEEK_SET; - fl.l_start = off; - fl.l_len = len; - fl.l_pid = 0; - - if (waitflag) - return fcntl(tdb->fd, F_SETLKW, &fl); - else - return fcntl(tdb->fd, F_SETLK, &fl); -} - -static int fcntl_unlock(struct tdb_context *tdb, int rw, off_t off, off_t len) -{ - struct flock fl; -#if 0 /* Check they matched up locks and unlocks correctly. */ - char line[80]; - FILE *locks; - bool found = false; - - locks = fopen("/proc/locks", "r"); - - while (fgets(line, 80, locks)) { - char *p; - int type, start, l; - - /* eg. 1: FLOCK ADVISORY WRITE 2440 08:01:2180826 0 EOF */ - p = strchr(line, ':') + 1; - if (strncmp(p, " POSIX ADVISORY ", strlen(" POSIX ADVISORY "))) - continue; - p += strlen(" FLOCK ADVISORY "); - if (strncmp(p, "READ ", strlen("READ ")) == 0) - type = F_RDLCK; - else if (strncmp(p, "WRITE ", strlen("WRITE ")) == 0) - type = F_WRLCK; - else - abort(); - p += 6; - if (atoi(p) != getpid()) - continue; - p = strchr(strchr(p, ' ') + 1, ' ') + 1; - start = atoi(p); - p = strchr(p, ' ') + 1; - if (strncmp(p, "EOF", 3) == 0) - l = 0; - else - l = atoi(p) - start + 1; - - if (off == start) { - if (len != l) { - fprintf(stderr, "Len %u should be %u: %s", - (int)len, l, line); - abort(); - } - if (type != rw) { - fprintf(stderr, "Type %s wrong: %s", - rw == F_RDLCK ? "READ" : "WRITE", line); - abort(); - } - found = true; - break; - } - } - - if (!found) { - fprintf(stderr, "Unlock on %u@%u not found!\n", - (int)off, (int)len); - abort(); - } - - fclose(locks); -#endif - - fl.l_type = F_UNLCK; - fl.l_whence = SEEK_SET; - fl.l_start = off; - fl.l_len = len; - fl.l_pid = 0; - - return fcntl(tdb->fd, F_SETLKW, &fl); -} - -/* list -1 is the alloc list, otherwise a hash chain. */ -static tdb_off_t lock_offset(int list) -{ - return FREELIST_TOP + 4*list; -} - -/* a byte range locking function - return 0 on success - this functions locks/unlocks 1 byte at the specified offset. - - On error, errno is also set so that errors are passed back properly - through tdb_open(). - - note that a len of zero means lock to end of file -*/ -int tdb_brlock(struct tdb_context *tdb, - int rw_type, tdb_off_t offset, size_t len, - enum tdb_lock_flags flags) -{ - int ret; - - if (tdb->flags & TDB_NOLOCK) { - return 0; - } - - if (flags & TDB_LOCK_MARK_ONLY) { - return 0; - } - - if ((rw_type == F_WRLCK) && (tdb->read_only || tdb->traverse_read)) { - tdb->ecode = TDB_ERR_RDONLY; - return -1; - } - - do { - ret = fcntl_lock(tdb, rw_type, offset, len, - flags & TDB_LOCK_WAIT); - /* Check for a sigalarm break. */ - if (ret == -1 && errno == EINTR && - tdb->interrupt_sig_ptr && - *tdb->interrupt_sig_ptr) { - break; - } - } while (ret == -1 && errno == EINTR); - - if (ret == -1) { - tdb->ecode = TDB_ERR_LOCK; - /* Generic lock error. errno set by fcntl. - * EAGAIN is an expected return from non-blocking - * locks. */ - if (!(flags & TDB_LOCK_PROBE) && errno != EAGAIN) { - TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d flags=%d len=%d\n", - tdb->fd, offset, rw_type, flags, (int)len)); - } - return -1; - } - return 0; -} - -int tdb_brunlock(struct tdb_context *tdb, - int rw_type, tdb_off_t offset, size_t len) -{ - int ret; - - if (tdb->flags & TDB_NOLOCK) { - return 0; - } - - do { - ret = fcntl_unlock(tdb, rw_type, offset, len); - } while (ret == -1 && errno == EINTR); - - if (ret == -1) { - TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brunlock failed (fd=%d) at offset %d rw_type=%d len=%d\n", - tdb->fd, offset, rw_type, (int)len)); - } - return ret; -} - -/* - upgrade a read lock to a write lock. This needs to be handled in a - special way as some OSes (such as solaris) have too conservative - deadlock detection and claim a deadlock when progress can be - made. For those OSes we may loop for a while. -*/ -int tdb_allrecord_upgrade(struct tdb_context *tdb) -{ - int count = 1000; - - if (tdb->allrecord_lock.count != 1) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "tdb_allrecord_upgrade failed: count %u too high\n", - tdb->allrecord_lock.count)); - return -1; - } - - if (tdb->allrecord_lock.off != 1) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "tdb_allrecord_upgrade failed: already upgraded?\n")); - return -1; - } - - while (count--) { - struct timeval tv; - if (tdb_brlock(tdb, F_WRLCK, FREELIST_TOP, 0, - TDB_LOCK_WAIT|TDB_LOCK_PROBE) == 0) { - tdb->allrecord_lock.ltype = F_WRLCK; - tdb->allrecord_lock.off = 0; - return 0; - } - if (errno != EDEADLK) { - break; - } - /* sleep for as short a time as we can - more portable than usleep() */ - tv.tv_sec = 0; - tv.tv_usec = 1; - select(0, NULL, NULL, NULL, &tv); - } - TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_allrecord_upgrade failed\n")); - return -1; -} - -static struct tdb_lock_type *find_nestlock(struct tdb_context *tdb, - tdb_off_t offset) -{ - unsigned int i; - - for (i=0; inum_lockrecs; i++) { - if (tdb->lockrecs[i].off == offset) { - return &tdb->lockrecs[i]; - } - } - return NULL; -} - -/* lock an offset in the database. */ -int tdb_nest_lock(struct tdb_context *tdb, uint32_t offset, int ltype, - enum tdb_lock_flags flags) -{ - struct tdb_lock_type *new_lck; - - if (offset >= lock_offset(tdb->header.hash_size)) { - tdb->ecode = TDB_ERR_LOCK; - TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_lock: invalid offset %u for ltype=%d\n", - offset, ltype)); - return -1; - } - if (tdb->flags & TDB_NOLOCK) - return 0; - - new_lck = find_nestlock(tdb, offset); - if (new_lck) { - /* - * Just increment the in-memory struct, posix locks - * don't stack. - */ - new_lck->count++; - return 0; - } - - new_lck = (struct tdb_lock_type *)realloc( - tdb->lockrecs, - sizeof(*tdb->lockrecs) * (tdb->num_lockrecs+1)); - if (new_lck == NULL) { - errno = ENOMEM; - return -1; - } - tdb->lockrecs = new_lck; - - /* Since fcntl locks don't nest, we do a lock for the first one, - and simply bump the count for future ones */ - if (tdb_brlock(tdb, ltype, offset, 1, flags)) { - return -1; - } - - tdb->lockrecs[tdb->num_lockrecs].off = offset; - tdb->lockrecs[tdb->num_lockrecs].count = 1; - tdb->lockrecs[tdb->num_lockrecs].ltype = ltype; - tdb->num_lockrecs++; - - return 0; -} - -static int tdb_lock_and_recover(struct tdb_context *tdb) -{ - int ret; - - /* We need to match locking order in transaction commit. */ - if (tdb_brlock(tdb, F_WRLCK, FREELIST_TOP, 0, TDB_LOCK_WAIT)) { - return -1; - } - - if (tdb_brlock(tdb, F_WRLCK, OPEN_LOCK, 1, TDB_LOCK_WAIT)) { - tdb_brunlock(tdb, F_WRLCK, FREELIST_TOP, 0); - return -1; - } - - ret = tdb_transaction_recover(tdb); - - tdb_brunlock(tdb, F_WRLCK, OPEN_LOCK, 1); - tdb_brunlock(tdb, F_WRLCK, FREELIST_TOP, 0); - - return ret; -} - -static bool have_data_locks(const struct tdb_context *tdb) -{ - unsigned int i; - - for (i = 0; i < tdb->num_lockrecs; i++) { - if (tdb->lockrecs[i].off >= lock_offset(-1)) - return true; - } - return false; -} - -static int tdb_lock_list(struct tdb_context *tdb, int list, int ltype, - enum tdb_lock_flags waitflag) -{ - int ret; - bool check = false; - - /* a allrecord lock allows us to avoid per chain locks */ - if (tdb->allrecord_lock.count && - (ltype == tdb->allrecord_lock.ltype || ltype == F_RDLCK)) { - return 0; - } - - if (tdb->allrecord_lock.count) { - tdb->ecode = TDB_ERR_LOCK; - ret = -1; - } else { - /* Only check when we grab first data lock. */ - check = !have_data_locks(tdb); - ret = tdb_nest_lock(tdb, lock_offset(list), ltype, waitflag); - - if (ret == 0 && check && tdb_needs_recovery(tdb)) { - tdb_nest_unlock(tdb, lock_offset(list), ltype, false); - - if (tdb_lock_and_recover(tdb) == -1) { - return -1; - } - return tdb_lock_list(tdb, list, ltype, waitflag); - } - } - return ret; -} - -/* lock a list in the database. list -1 is the alloc list */ -int tdb_lock(struct tdb_context *tdb, int list, int ltype) -{ - int ret; - - ret = tdb_lock_list(tdb, list, ltype, TDB_LOCK_WAIT); - if (ret) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock failed on list %d " - "ltype=%d (%s)\n", list, ltype, strerror(errno))); - } - return ret; -} - -/* lock a list in the database. list -1 is the alloc list. non-blocking lock */ -int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype) -{ - return tdb_lock_list(tdb, list, ltype, TDB_LOCK_NOWAIT); -} - - -int tdb_nest_unlock(struct tdb_context *tdb, uint32_t offset, int ltype, - bool mark_lock) -{ - int ret = -1; - struct tdb_lock_type *lck; - - if (tdb->flags & TDB_NOLOCK) - return 0; - - /* Sanity checks */ - if (offset >= lock_offset(tdb->header.hash_size)) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: offset %u invalid (%d)\n", offset, tdb->header.hash_size)); - return ret; - } - - lck = find_nestlock(tdb, offset); - if ((lck == NULL) || (lck->count == 0)) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: count is 0\n")); - return -1; - } - - if (lck->count > 1) { - lck->count--; - return 0; - } - - /* - * This lock has count==1 left, so we need to unlock it in the - * kernel. We don't bother with decrementing the in-memory array - * element, we're about to overwrite it with the last array element - * anyway. - */ - - if (mark_lock) { - ret = 0; - } else { - ret = tdb_brunlock(tdb, ltype, offset, 1); - } - - /* - * Shrink the array by overwriting the element just unlocked with the - * last array element. - */ - *lck = tdb->lockrecs[--tdb->num_lockrecs]; - - /* - * We don't bother with realloc when the array shrinks, but if we have - * a completely idle tdb we should get rid of the locked array. - */ - - if (tdb->num_lockrecs == 0) { - SAFE_FREE(tdb->lockrecs); - } - - if (ret) - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: An error occurred unlocking!\n")); - return ret; -} - -int tdb_unlock(struct tdb_context *tdb, int list, int ltype) -{ - /* a global lock allows us to avoid per chain locks */ - if (tdb->allrecord_lock.count && - (ltype == tdb->allrecord_lock.ltype || ltype == F_RDLCK)) { - return 0; - } - - if (tdb->allrecord_lock.count) { - tdb->ecode = TDB_ERR_LOCK; - return -1; - } - - return tdb_nest_unlock(tdb, lock_offset(list), ltype, false); -} - -/* - get the transaction lock - */ -int tdb_transaction_lock(struct tdb_context *tdb, int ltype, - enum tdb_lock_flags lockflags) -{ - return tdb_nest_lock(tdb, TRANSACTION_LOCK, ltype, lockflags); -} - -/* - release the transaction lock - */ -int tdb_transaction_unlock(struct tdb_context *tdb, int ltype) -{ - return tdb_nest_unlock(tdb, TRANSACTION_LOCK, ltype, false); -} - -/* Returns 0 if all done, -1 if error, 1 if ok. */ -static int tdb_allrecord_check(struct tdb_context *tdb, int ltype, - enum tdb_lock_flags flags, bool upgradable) -{ - /* There are no locks on read-only dbs */ - if (tdb->read_only || tdb->traverse_read) { - tdb->ecode = TDB_ERR_LOCK; - return -1; - } - - if (tdb->allrecord_lock.count && tdb->allrecord_lock.ltype == ltype) { - tdb->allrecord_lock.count++; - return 0; - } - - if (tdb->allrecord_lock.count) { - /* a global lock of a different type exists */ - tdb->ecode = TDB_ERR_LOCK; - return -1; - } - - if (tdb_have_extra_locks(tdb)) { - /* can't combine global and chain locks */ - tdb->ecode = TDB_ERR_LOCK; - return -1; - } - - if (upgradable && ltype != F_RDLCK) { - /* tdb error: you can't upgrade a write lock! */ - tdb->ecode = TDB_ERR_LOCK; - return -1; - } - return 1; -} - -/* We only need to lock individual bytes, but Linux merges consecutive locks - * so we lock in contiguous ranges. */ -static int tdb_chainlock_gradual(struct tdb_context *tdb, - int ltype, enum tdb_lock_flags flags, - size_t off, size_t len) -{ - int ret; - enum tdb_lock_flags nb_flags = (flags & ~TDB_LOCK_WAIT); - - if (len <= 4) { - /* Single record. Just do blocking lock. */ - return tdb_brlock(tdb, ltype, off, len, flags); - } - - /* First we try non-blocking. */ - ret = tdb_brlock(tdb, ltype, off, len, nb_flags); - if (ret == 0) { - return 0; - } - - /* Try locking first half, then second. */ - ret = tdb_chainlock_gradual(tdb, ltype, flags, off, len / 2); - if (ret == -1) - return -1; - - ret = tdb_chainlock_gradual(tdb, ltype, flags, - off + len / 2, len - len / 2); - if (ret == -1) { - tdb_brunlock(tdb, ltype, off, len / 2); - return -1; - } - return 0; -} - -/* lock/unlock entire database. It can only be upgradable if you have some - * other way of guaranteeing exclusivity (ie. transaction write lock). - * We do the locking gradually to avoid being starved by smaller locks. */ -int tdb_allrecord_lock(struct tdb_context *tdb, int ltype, - enum tdb_lock_flags flags, bool upgradable) -{ - switch (tdb_allrecord_check(tdb, ltype, flags, upgradable)) { - case -1: - return -1; - case 0: - return 0; - } - - /* We cover two kinds of locks: - * 1) Normal chain locks. Taken for almost all operations. - * 3) Individual records locks. Taken after normal or free - * chain locks. - * - * It is (1) which cause the starvation problem, so we're only - * gradual for that. */ - if (tdb_chainlock_gradual(tdb, ltype, flags, FREELIST_TOP, - tdb->header.hash_size * 4) == -1) { - return -1; - } - - /* Grab individual record locks. */ - if (tdb_brlock(tdb, ltype, lock_offset(tdb->header.hash_size), 0, - flags) == -1) { - tdb_brunlock(tdb, ltype, FREELIST_TOP, - tdb->header.hash_size * 4); - return -1; - } - - tdb->allrecord_lock.count = 1; - /* If it's upgradable, it's actually exclusive so we can treat - * it as a write lock. */ - tdb->allrecord_lock.ltype = upgradable ? F_WRLCK : ltype; - tdb->allrecord_lock.off = upgradable; - - if (tdb_needs_recovery(tdb)) { - bool mark = flags & TDB_LOCK_MARK_ONLY; - tdb_allrecord_unlock(tdb, ltype, mark); - if (mark) { - tdb->ecode = TDB_ERR_LOCK; - TDB_LOG((tdb, TDB_DEBUG_ERROR, - "tdb_lockall_mark cannot do recovery\n")); - return -1; - } - if (tdb_lock_and_recover(tdb) == -1) { - return -1; - } - return tdb_allrecord_lock(tdb, ltype, flags, upgradable); - } - - return 0; -} - - - -/* unlock entire db */ -int tdb_allrecord_unlock(struct tdb_context *tdb, int ltype, bool mark_lock) -{ - /* There are no locks on read-only dbs */ - if (tdb->read_only || tdb->traverse_read) { - tdb->ecode = TDB_ERR_LOCK; - return -1; - } - - if (tdb->allrecord_lock.count == 0) { - tdb->ecode = TDB_ERR_LOCK; - return -1; - } - - /* Upgradable locks are marked as write locks. */ - if (tdb->allrecord_lock.ltype != ltype - && (!tdb->allrecord_lock.off || ltype != F_RDLCK)) { - tdb->ecode = TDB_ERR_LOCK; - return -1; - } - - if (tdb->allrecord_lock.count > 1) { - tdb->allrecord_lock.count--; - return 0; - } - - if (!mark_lock && tdb_brunlock(tdb, ltype, FREELIST_TOP, 0)) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlockall failed (%s)\n", strerror(errno))); - return -1; - } - - tdb->allrecord_lock.count = 0; - tdb->allrecord_lock.ltype = 0; - - return 0; -} - -/* lock entire database with write lock */ -int tdb_lockall(struct tdb_context *tdb) -{ - tdb_trace(tdb, "tdb_lockall"); - return tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_WAIT, false); -} - -/* lock entire database with write lock - mark only */ -int tdb_lockall_mark(struct tdb_context *tdb) -{ - tdb_trace(tdb, "tdb_lockall_mark"); - return tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_MARK_ONLY, false); -} - -/* unlock entire database with write lock - unmark only */ -int tdb_lockall_unmark(struct tdb_context *tdb) -{ - tdb_trace(tdb, "tdb_lockall_unmark"); - return tdb_allrecord_unlock(tdb, F_WRLCK, true); -} - -/* lock entire database with write lock - nonblocking varient */ -int tdb_lockall_nonblock(struct tdb_context *tdb) -{ - int ret = tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_NOWAIT, false); - tdb_trace_ret(tdb, "tdb_lockall_nonblock", ret); - return ret; -} - -/* unlock entire database with write lock */ -int tdb_unlockall(struct tdb_context *tdb) -{ - tdb_trace(tdb, "tdb_unlockall"); - return tdb_allrecord_unlock(tdb, F_WRLCK, false); -} - -/* lock entire database with read lock */ -int tdb_lockall_read(struct tdb_context *tdb) -{ - tdb_trace(tdb, "tdb_lockall_read"); - return tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false); -} - -/* lock entire database with read lock - nonblock varient */ -int tdb_lockall_read_nonblock(struct tdb_context *tdb) -{ - int ret = tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_NOWAIT, false); - tdb_trace_ret(tdb, "tdb_lockall_read_nonblock", ret); - return ret; -} - -/* unlock entire database with read lock */ -int tdb_unlockall_read(struct tdb_context *tdb) -{ - tdb_trace(tdb, "tdb_unlockall_read"); - return tdb_allrecord_unlock(tdb, F_RDLCK, false); -} - -/* lock/unlock one hash chain. This is meant to be used to reduce - contention - it cannot guarantee how many records will be locked */ -int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key) -{ - int ret = tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK); - tdb_trace_1rec(tdb, "tdb_chainlock", key); - return ret; -} - -/* lock/unlock one hash chain, non-blocking. This is meant to be used - to reduce contention - it cannot guarantee how many records will be - locked */ -int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key) -{ - int ret = tdb_lock_nonblock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK); - tdb_trace_1rec_ret(tdb, "tdb_chainlock_nonblock", key, ret); - return ret; -} - -/* mark a chain as locked without actually locking it. Warning! use with great caution! */ -int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key) -{ - int ret = tdb_nest_lock(tdb, lock_offset(BUCKET(tdb->hash_fn(&key))), - F_WRLCK, TDB_LOCK_MARK_ONLY); - tdb_trace_1rec(tdb, "tdb_chainlock_mark", key); - return ret; -} - -/* unmark a chain as locked without actually locking it. Warning! use with great caution! */ -int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key) -{ - tdb_trace_1rec(tdb, "tdb_chainlock_unmark", key); - return tdb_nest_unlock(tdb, lock_offset(BUCKET(tdb->hash_fn(&key))), - F_WRLCK, true); -} - -int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key) -{ - tdb_trace_1rec(tdb, "tdb_chainunlock", key); - return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK); -} - -int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key) -{ - int ret; - ret = tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_RDLCK); - tdb_trace_1rec(tdb, "tdb_chainlock_read", key); - return ret; -} - -int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key) -{ - tdb_trace_1rec(tdb, "tdb_chainunlock_read", key); - return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_RDLCK); -} - - - -/* record lock stops delete underneath */ -int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off) -{ - if (tdb->allrecord_lock.count) { - return 0; - } - return off ? tdb_brlock(tdb, F_RDLCK, off, 1, TDB_LOCK_WAIT) : 0; -} - -/* - Write locks override our own fcntl readlocks, so check it here. - Note this is meant to be F_SETLK, *not* F_SETLKW, as it's not - an error to fail to get the lock here. -*/ -int tdb_write_lock_record(struct tdb_context *tdb, tdb_off_t off) -{ - struct tdb_traverse_lock *i; - for (i = &tdb->travlocks; i; i = i->next) - if (i->off == off) - return -1; - if (tdb->allrecord_lock.count) { - if (tdb->allrecord_lock.ltype == F_WRLCK) { - return 0; - } - return -1; - } - return tdb_brlock(tdb, F_WRLCK, off, 1, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE); -} - -int tdb_write_unlock_record(struct tdb_context *tdb, tdb_off_t off) -{ - if (tdb->allrecord_lock.count) { - return 0; - } - return tdb_brunlock(tdb, F_WRLCK, off, 1); -} - -/* fcntl locks don't stack: avoid unlocking someone else's */ -int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off) -{ - struct tdb_traverse_lock *i; - uint32_t count = 0; - - if (tdb->allrecord_lock.count) { - return 0; - } - - if (off == 0) - return 0; - for (i = &tdb->travlocks; i; i = i->next) - if (i->off == off) - count++; - return (count == 1 ? tdb_brunlock(tdb, F_RDLCK, off, 1) : 0); -} - -bool tdb_have_extra_locks(struct tdb_context *tdb) -{ - unsigned int extra = tdb->num_lockrecs; - - /* A transaction holds the lock for all records. */ - if (!tdb->transaction && tdb->allrecord_lock.count) { - return true; - } - - /* We always hold the active lock if CLEAR_IF_FIRST. */ - if (find_nestlock(tdb, ACTIVE_LOCK)) { - extra--; - } - - /* In a transaction, we expect to hold the transaction lock */ - if (tdb->transaction && find_nestlock(tdb, TRANSACTION_LOCK)) { - extra--; - } - - return extra; -} - -/* The transaction code uses this to remove all locks. */ -void tdb_release_transaction_locks(struct tdb_context *tdb) -{ - unsigned int i, active = 0; - - if (tdb->allrecord_lock.count != 0) { - tdb_brunlock(tdb, tdb->allrecord_lock.ltype, FREELIST_TOP, 0); - tdb->allrecord_lock.count = 0; - } - - for (i=0;inum_lockrecs;i++) { - struct tdb_lock_type *lck = &tdb->lockrecs[i]; - - /* Don't release the active lock! Copy it to first entry. */ - if (lck->off == ACTIVE_LOCK) { - tdb->lockrecs[active++] = *lck; - } else { - tdb_brunlock(tdb, lck->ltype, lck->off, 1); - } - } - tdb->num_lockrecs = active; - if (tdb->num_lockrecs == 0) { - SAFE_FREE(tdb->lockrecs); - } -} diff --git a/bundled/tdb/common/open.c b/bundled/tdb/common/open.c deleted file mode 100644 index 7687ff6e..00000000 --- a/bundled/tdb/common/open.c +++ /dev/null @@ -1,543 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Andrew Tridgell 1999-2005 - Copyright (C) Paul `Rusty' Russell 2000 - Copyright (C) Jeremy Allison 2000-2003 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "tdb_private.h" - -/* all contexts, to ensure no double-opens (fcntl locks don't nest!) */ -static struct tdb_context *tdbs = NULL; - - -/* This is based on the hash algorithm from gdbm */ -static unsigned int default_tdb_hash(TDB_DATA *key) -{ - uint32_t value; /* Used to compute the hash value. */ - uint32_t i; /* Used to cycle through random values. */ - - /* Set the initial value from the key size. */ - for (value = 0x238F13AF * key->dsize, i=0; i < key->dsize; i++) - value = (value + (key->dptr[i] << (i*5 % 24))); - - return (1103515243 * value + 12345); -} - - -/* initialise a new database with a specified hash size */ -static int tdb_new_database(struct tdb_context *tdb, int hash_size) -{ - struct tdb_header *newdb; - size_t size; - int ret = -1; - - /* We make it up in memory, then write it out if not internal */ - size = sizeof(struct tdb_header) + (hash_size+1)*sizeof(tdb_off_t); - if (!(newdb = (struct tdb_header *)calloc(size, 1))) { - tdb->ecode = TDB_ERR_OOM; - return -1; - } - - /* Fill in the header */ - newdb->version = TDB_VERSION; - newdb->hash_size = hash_size; - if (tdb->flags & TDB_INTERNAL) { - tdb->map_size = size; - tdb->map_ptr = (char *)newdb; - memcpy(&tdb->header, newdb, sizeof(tdb->header)); - /* Convert the `ondisk' version if asked. */ - CONVERT(*newdb); - return 0; - } - if (lseek(tdb->fd, 0, SEEK_SET) == -1) - goto fail; - - if (ftruncate(tdb->fd, 0) == -1) - goto fail; - - /* This creates an endian-converted header, as if read from disk */ - CONVERT(*newdb); - memcpy(&tdb->header, newdb, sizeof(tdb->header)); - /* Don't endian-convert the magic food! */ - memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1); - /* we still have "ret == -1" here */ - if (tdb_write_all(tdb->fd, newdb, size)) - ret = 0; - - fail: - SAFE_FREE(newdb); - return ret; -} - - - -static int tdb_already_open(dev_t device, - ino_t ino) -{ - struct tdb_context *i; - - for (i = tdbs; i; i = i->next) { - if (i->device == device && i->inode == ino) { - return 1; - } - } - - return 0; -} - -/* open the database, creating it if necessary - - The open_flags and mode are passed straight to the open call on the - database file. A flags value of O_WRONLY is invalid. The hash size - is advisory, use zero for a default value. - - Return is NULL on error, in which case errno is also set. Don't - try to call tdb_error or tdb_errname, just do strerror(errno). - - @param name may be NULL for internal databases. */ -struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode) -{ - return tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, NULL, NULL); -} - -/* a default logging function */ -static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); -static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) -{ -} - - -struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode, - const struct tdb_logging_context *log_ctx, - tdb_hash_func hash_fn) -{ - struct tdb_context *tdb; - struct stat st; - int rev = 0, locked = 0; - unsigned char *vp; - uint32_t vertest; - unsigned v; - - if (!(tdb = (struct tdb_context *)calloc(1, sizeof *tdb))) { - /* Can't log this */ - errno = ENOMEM; - goto fail; - } - tdb_io_init(tdb); - tdb->fd = -1; -#ifdef TDB_TRACE - tdb->tracefd = -1; -#endif - tdb->name = NULL; - tdb->map_ptr = NULL; - tdb->flags = tdb_flags; - tdb->open_flags = open_flags; - if (log_ctx) { - tdb->log = *log_ctx; - } else { - tdb->log.log_fn = null_log_fn; - tdb->log.log_private = NULL; - } - tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash; - - /* cache the page size */ - tdb->page_size = getpagesize(); - if (tdb->page_size <= 0) { - tdb->page_size = 0x2000; - } - - tdb->max_dead_records = (tdb_flags & TDB_VOLATILE) ? 5 : 0; - - if ((open_flags & O_ACCMODE) == O_WRONLY) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: can't open tdb %s write-only\n", - name)); - errno = EINVAL; - goto fail; - } - - if (hash_size == 0) - hash_size = DEFAULT_HASH_SIZE; - if ((open_flags & O_ACCMODE) == O_RDONLY) { - tdb->read_only = 1; - /* read only databases don't do locking or clear if first */ - tdb->flags |= TDB_NOLOCK; - tdb->flags &= ~TDB_CLEAR_IF_FIRST; - } - - if ((tdb->flags & TDB_ALLOW_NESTING) && - (tdb->flags & TDB_DISALLOW_NESTING)) { - tdb->ecode = TDB_ERR_NESTING; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: " - "allow_nesting and disallow_nesting are not allowed together!")); - errno = EINVAL; - goto fail; - } - - /* - * TDB_ALLOW_NESTING is the default behavior. - * Note: this may change in future versions! - */ - if (!(tdb->flags & TDB_DISALLOW_NESTING)) { - tdb->flags |= TDB_ALLOW_NESTING; - } - - /* internal databases don't mmap or lock, and start off cleared */ - if (tdb->flags & TDB_INTERNAL) { - tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP); - tdb->flags &= ~TDB_CLEAR_IF_FIRST; - if (tdb_new_database(tdb, hash_size) != 0) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!")); - goto fail; - } - goto internal; - } - - if ((tdb->fd = open(name, open_flags, mode)) == -1) { - TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_open_ex: could not open file %s: %s\n", - name, strerror(errno))); - goto fail; /* errno set by open(2) */ - } - - /* on exec, don't inherit the fd */ - v = fcntl(tdb->fd, F_GETFD, 0); - fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC); - - /* ensure there is only one process initialising at once */ - if (tdb_nest_lock(tdb, OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to get open lock on %s: %s\n", - name, strerror(errno))); - goto fail; /* errno set by tdb_brlock */ - } - - /* we need to zero database if we are the only one with it open */ - if ((tdb_flags & TDB_CLEAR_IF_FIRST) && - (!tdb->read_only) && - (locked = (tdb_nest_lock(tdb, ACTIVE_LOCK, F_WRLCK, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE) == 0))) { - open_flags |= O_CREAT; - if (ftruncate(tdb->fd, 0) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: " - "failed to truncate %s: %s\n", - name, strerror(errno))); - goto fail; /* errno set by ftruncate */ - } - } - - errno = 0; - if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header) - || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) { - if (!(open_flags & O_CREAT) || tdb_new_database(tdb, hash_size) == -1) { - if (errno == 0) { - errno = EIO; /* ie bad format or something */ - } - goto fail; - } - rev = (tdb->flags & TDB_CONVERT); - } else if (tdb->header.version != TDB_VERSION - && !(rev = (tdb->header.version==TDB_BYTEREV(TDB_VERSION)))) { - /* wrong version */ - errno = EIO; - goto fail; - } - vp = (unsigned char *)&tdb->header.version; - vertest = (((uint32_t)vp[0]) << 24) | (((uint32_t)vp[1]) << 16) | - (((uint32_t)vp[2]) << 8) | (uint32_t)vp[3]; - tdb->flags |= (vertest==TDB_VERSION) ? TDB_BIGENDIAN : 0; - if (!rev) - tdb->flags &= ~TDB_CONVERT; - else { - tdb->flags |= TDB_CONVERT; - tdb_convert(&tdb->header, sizeof(tdb->header)); - } - if (fstat(tdb->fd, &st) == -1) - goto fail; - - if (tdb->header.rwlocks != 0) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: spinlocks no longer supported\n")); - goto fail; - } - - /* Is it already in the open list? If so, fail. */ - if (tdb_already_open(st.st_dev, st.st_ino)) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: " - "%s (%d,%d) is already open in this process\n", - name, (int)st.st_dev, (int)st.st_ino)); - errno = EBUSY; - goto fail; - } - - if (!(tdb->name = (char *)strdup(name))) { - errno = ENOMEM; - goto fail; - } - - tdb->map_size = st.st_size; - tdb->device = st.st_dev; - tdb->inode = st.st_ino; - tdb_mmap(tdb); - if (locked) { - if (tdb_nest_unlock(tdb, ACTIVE_LOCK, F_WRLCK, false) == -1) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: " - "failed to release ACTIVE_LOCK on %s: %s\n", - name, strerror(errno))); - goto fail; - } - - } - - /* We always need to do this if the CLEAR_IF_FIRST flag is set, even if - we didn't get the initial exclusive lock as we need to let all other - users know we're using it. */ - - if (tdb_flags & TDB_CLEAR_IF_FIRST) { - /* leave this lock in place to indicate it's in use */ - if (tdb_nest_lock(tdb, ACTIVE_LOCK, F_RDLCK, TDB_LOCK_WAIT) == -1) { - goto fail; - } - } - - /* if needed, run recovery */ - if (tdb_transaction_recover(tdb) == -1) { - goto fail; - } - -#ifdef TDB_TRACE - { - char tracefile[strlen(name) + 32]; - - snprintf(tracefile, sizeof(tracefile), - "%s.trace.%li", name, (long)getpid()); - tdb->tracefd = open(tracefile, O_WRONLY|O_CREAT|O_EXCL, 0600); - if (tdb->tracefd >= 0) { - tdb_enable_seqnum(tdb); - tdb_trace_open(tdb, "tdb_open", hash_size, tdb_flags, - open_flags); - } else - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to open trace file %s!\n", tracefile)); - } -#endif - - internal: - /* Internal (memory-only) databases skip all the code above to - * do with disk files, and resume here by releasing their - * open lock and hooking into the active list. */ - if (tdb_nest_unlock(tdb, OPEN_LOCK, F_WRLCK, false) == -1) { - goto fail; - } - tdb->next = tdbs; - tdbs = tdb; - return tdb; - - fail: - { int save_errno = errno; - - if (!tdb) - return NULL; - -#ifdef TDB_TRACE - close(tdb->tracefd); -#endif - if (tdb->map_ptr) { - if (tdb->flags & TDB_INTERNAL) - SAFE_FREE(tdb->map_ptr); - else - tdb_munmap(tdb); - } - SAFE_FREE(tdb->name); - if (tdb->fd != -1) - if (close(tdb->fd) != 0) - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to close tdb->fd on error!\n")); - SAFE_FREE(tdb->lockrecs); - SAFE_FREE(tdb); - errno = save_errno; - return NULL; - } -} - -/* - * Set the maximum number of dead records per hash chain - */ - -void tdb_set_max_dead(struct tdb_context *tdb, int max_dead) -{ - tdb->max_dead_records = max_dead; -} - -/** - * Close a database. - * - * @returns -1 for error; 0 for success. - **/ -int tdb_close(struct tdb_context *tdb) -{ - struct tdb_context **i; - int ret = 0; - - if (tdb->transaction) { - tdb_transaction_cancel(tdb); - } - tdb_trace(tdb, "tdb_close"); - - if (tdb->map_ptr) { - if (tdb->flags & TDB_INTERNAL) - SAFE_FREE(tdb->map_ptr); - else - tdb_munmap(tdb); - } - SAFE_FREE(tdb->name); - if (tdb->fd != -1) { - ret = close(tdb->fd); - tdb->fd = -1; - } - SAFE_FREE(tdb->lockrecs); - - /* Remove from contexts list */ - for (i = &tdbs; *i; i = &(*i)->next) { - if (*i == tdb) { - *i = tdb->next; - break; - } - } - -#ifdef TDB_TRACE - close(tdb->tracefd); -#endif - memset(tdb, 0, sizeof(*tdb)); - SAFE_FREE(tdb); - - return ret; -} - -/* register a loging function */ -void tdb_set_logging_function(struct tdb_context *tdb, - const struct tdb_logging_context *log_ctx) -{ - tdb->log = *log_ctx; -} - -void *tdb_get_logging_private(struct tdb_context *tdb) -{ - return tdb->log.log_private; -} - -static int tdb_reopen_internal(struct tdb_context *tdb, bool active_lock) -{ -#if !defined(LIBREPLACE_PREAD_NOT_REPLACED) || \ - !defined(LIBREPLACE_PWRITE_NOT_REPLACED) - struct stat st; -#endif - - if (tdb->flags & TDB_INTERNAL) { - return 0; /* Nothing to do. */ - } - - if (tdb_have_extra_locks(tdb)) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_reopen: reopen not allowed with locks held\n")); - goto fail; - } - - if (tdb->transaction != 0) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_reopen: reopen not allowed inside a transaction\n")); - goto fail; - } - -/* If we have real pread & pwrite, we can skip reopen. */ -#if !defined(LIBREPLACE_PREAD_NOT_REPLACED) || \ - !defined(LIBREPLACE_PWRITE_NOT_REPLACED) - if (tdb_munmap(tdb) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: munmap failed (%s)\n", strerror(errno))); - goto fail; - } - if (close(tdb->fd) != 0) - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: WARNING closing tdb->fd failed!\n")); - tdb->fd = open(tdb->name, tdb->open_flags & ~(O_CREAT|O_TRUNC), 0); - if (tdb->fd == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: open failed (%s)\n", strerror(errno))); - goto fail; - } - if (fstat(tdb->fd, &st) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: fstat failed (%s)\n", strerror(errno))); - goto fail; - } - if (st.st_ino != tdb->inode || st.st_dev != tdb->device) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: file dev/inode has changed!\n")); - goto fail; - } - tdb_mmap(tdb); -#endif /* fake pread or pwrite */ - - /* We may still think we hold the active lock. */ - tdb->num_lockrecs = 0; - SAFE_FREE(tdb->lockrecs); - - if (active_lock && tdb_nest_lock(tdb, ACTIVE_LOCK, F_RDLCK, TDB_LOCK_WAIT) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: failed to obtain active lock\n")); - goto fail; - } - - return 0; - -fail: - tdb_close(tdb); - return -1; -} - -/* reopen a tdb - this can be used after a fork to ensure that we have an independent - seek pointer from our parent and to re-establish locks */ -int tdb_reopen(struct tdb_context *tdb) -{ - return tdb_reopen_internal(tdb, tdb->flags & TDB_CLEAR_IF_FIRST); -} - -/* reopen all tdb's */ -int tdb_reopen_all(int parent_longlived) -{ - struct tdb_context *tdb; - - for (tdb=tdbs; tdb; tdb = tdb->next) { - bool active_lock = (tdb->flags & TDB_CLEAR_IF_FIRST); - - /* - * If the parent is longlived (ie. a - * parent daemon architecture), we know - * it will keep it's active lock on a - * tdb opened with CLEAR_IF_FIRST. Thus - * for child processes we don't have to - * add an active lock. This is essential - * to improve performance on systems that - * keep POSIX locks as a non-scalable data - * structure in the kernel. - */ - if (parent_longlived) { - /* Ensure no clear-if-first. */ - active_lock = false; - } - - if (tdb_reopen_internal(tdb, active_lock) != 0) - return -1; - } - - return 0; -} diff --git a/bundled/tdb/common/tdb.c b/bundled/tdb/common/tdb.c deleted file mode 100644 index 4d8c5fc5..00000000 --- a/bundled/tdb/common/tdb.c +++ /dev/null @@ -1,1157 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Andrew Tridgell 1999-2005 - Copyright (C) Paul `Rusty' Russell 2000 - Copyright (C) Jeremy Allison 2000-2003 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "tdb_private.h" - -TDB_DATA tdb_null; - -/* - non-blocking increment of the tdb sequence number if the tdb has been opened using - the TDB_SEQNUM flag -*/ -void tdb_increment_seqnum_nonblock(struct tdb_context *tdb) -{ - tdb_off_t seqnum=0; - - if (!(tdb->flags & TDB_SEQNUM)) { - return; - } - - /* we ignore errors from this, as we have no sane way of - dealing with them. - */ - tdb_ofs_read(tdb, TDB_SEQNUM_OFS, &seqnum); - seqnum++; - tdb_ofs_write(tdb, TDB_SEQNUM_OFS, &seqnum); -} - -/* - increment the tdb sequence number if the tdb has been opened using - the TDB_SEQNUM flag -*/ -static void tdb_increment_seqnum(struct tdb_context *tdb) -{ - if (!(tdb->flags & TDB_SEQNUM)) { - return; - } - - if (tdb_nest_lock(tdb, TDB_SEQNUM_OFS, F_WRLCK, - TDB_LOCK_WAIT|TDB_LOCK_PROBE) != 0) { - return; - } - - tdb_increment_seqnum_nonblock(tdb); - - tdb_nest_unlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, false); -} - -static int tdb_key_compare(TDB_DATA key, TDB_DATA data, void *private_data) -{ - return memcmp(data.dptr, key.dptr, data.dsize); -} - -/* Returns 0 on fail. On success, return offset of record, and fills - in rec */ -static tdb_off_t tdb_find(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, - struct tdb_record *r) -{ - tdb_off_t rec_ptr; - - /* read in the hash top */ - if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) - return 0; - - /* keep looking until we find the right record */ - while (rec_ptr) { - if (tdb_rec_read(tdb, rec_ptr, r) == -1) - return 0; - - if (!TDB_DEAD(r) && hash==r->full_hash - && key.dsize==r->key_len - && tdb_parse_data(tdb, key, rec_ptr + sizeof(*r), - r->key_len, tdb_key_compare, - NULL) == 0) { - return rec_ptr; - } - /* detect tight infinite loop */ - if (rec_ptr == r->next) { - tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_find: loop detected.\n")); - return 0; - } - rec_ptr = r->next; - } - tdb->ecode = TDB_ERR_NOEXIST; - return 0; -} - -/* As tdb_find, but if you succeed, keep the lock */ -tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, int locktype, - struct tdb_record *rec) -{ - uint32_t rec_ptr; - - if (tdb_lock(tdb, BUCKET(hash), locktype) == -1) - return 0; - if (!(rec_ptr = tdb_find(tdb, key, hash, rec))) - tdb_unlock(tdb, BUCKET(hash), locktype); - return rec_ptr; -} - -static TDB_DATA _tdb_fetch(struct tdb_context *tdb, TDB_DATA key); - -/* update an entry in place - this only works if the new data size - is <= the old data size and the key exists. - on failure return -1. -*/ -static int tdb_update_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, TDB_DATA dbuf) -{ - struct tdb_record rec; - tdb_off_t rec_ptr; - - /* find entry */ - if (!(rec_ptr = tdb_find(tdb, key, hash, &rec))) - return -1; - - /* it could be an exact duplicate of what is there - this is - * surprisingly common (eg. with a ldb re-index). */ - if (rec.key_len == key.dsize && - rec.data_len == dbuf.dsize && - rec.full_hash == hash) { - TDB_DATA data = _tdb_fetch(tdb, key); - if (data.dsize == dbuf.dsize && - memcmp(data.dptr, dbuf.dptr, data.dsize) == 0) { - if (data.dptr) { - free(data.dptr); - } - return 0; - } - if (data.dptr) { - free(data.dptr); - } - } - - /* must be long enough key, data and tailer */ - if (rec.rec_len < key.dsize + dbuf.dsize + sizeof(tdb_off_t)) { - tdb->ecode = TDB_SUCCESS; /* Not really an error */ - return -1; - } - - if (tdb->methods->tdb_write(tdb, rec_ptr + sizeof(rec) + rec.key_len, - dbuf.dptr, dbuf.dsize) == -1) - return -1; - - if (dbuf.dsize != rec.data_len) { - /* update size */ - rec.data_len = dbuf.dsize; - return tdb_rec_write(tdb, rec_ptr, &rec); - } - - return 0; -} - -/* find an entry in the database given a key */ -/* If an entry doesn't exist tdb_err will be set to - * TDB_ERR_NOEXIST. If a key has no data attached - * then the TDB_DATA will have zero length but - * a non-zero pointer - */ -static TDB_DATA _tdb_fetch(struct tdb_context *tdb, TDB_DATA key) -{ - tdb_off_t rec_ptr; - struct tdb_record rec; - TDB_DATA ret; - uint32_t hash; - - /* find which hash bucket it is in */ - hash = tdb->hash_fn(&key); - if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) - return tdb_null; - - ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec) + rec.key_len, - rec.data_len); - ret.dsize = rec.data_len; - tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK); - return ret; -} - -TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key) -{ - TDB_DATA ret = _tdb_fetch(tdb, key); - - tdb_trace_1rec_retrec(tdb, "tdb_fetch", key, ret); - return ret; -} - -/* - * Find an entry in the database and hand the record's data to a parsing - * function. The parsing function is executed under the chain read lock, so it - * should be fast and should not block on other syscalls. - * - * DON'T CALL OTHER TDB CALLS FROM THE PARSER, THIS MIGHT LEAD TO SEGFAULTS. - * - * For mmapped tdb's that do not have a transaction open it points the parsing - * function directly at the mmap area, it avoids the malloc/memcpy in this - * case. If a transaction is open or no mmap is available, it has to do - * malloc/read/parse/free. - * - * This is interesting for all readers of potentially large data structures in - * the tdb records, ldb indexes being one example. - * - * Return -1 if the record was not found. - */ - -int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data) -{ - tdb_off_t rec_ptr; - struct tdb_record rec; - int ret; - uint32_t hash; - - /* find which hash bucket it is in */ - hash = tdb->hash_fn(&key); - - if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) { - /* record not found */ - tdb_trace_1rec_ret(tdb, "tdb_parse_record", key, -1); - tdb->ecode = TDB_ERR_NOEXIST; - return -1; - } - tdb_trace_1rec_ret(tdb, "tdb_parse_record", key, 0); - - ret = tdb_parse_data(tdb, key, rec_ptr + sizeof(rec) + rec.key_len, - rec.data_len, parser, private_data); - - tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK); - - return ret; -} - -/* check if an entry in the database exists - - note that 1 is returned if the key is found and 0 is returned if not found - this doesn't match the conventions in the rest of this module, but is - compatible with gdbm -*/ -static int tdb_exists_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash) -{ - struct tdb_record rec; - - if (tdb_find_lock_hash(tdb, key, hash, F_RDLCK, &rec) == 0) - return 0; - tdb_unlock(tdb, BUCKET(rec.full_hash), F_RDLCK); - return 1; -} - -int tdb_exists(struct tdb_context *tdb, TDB_DATA key) -{ - uint32_t hash = tdb->hash_fn(&key); - int ret; - - ret = tdb_exists_hash(tdb, key, hash); - tdb_trace_1rec_ret(tdb, "tdb_exists", key, ret); - return ret; -} - -/* actually delete an entry in the database given the offset */ -int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct tdb_record *rec) -{ - tdb_off_t last_ptr, i; - struct tdb_record lastrec; - - if (tdb->read_only || tdb->traverse_read) return -1; - - if (((tdb->traverse_write != 0) && (!TDB_DEAD(rec))) || - tdb_write_lock_record(tdb, rec_ptr) == -1) { - /* Someone traversing here: mark it as dead */ - rec->magic = TDB_DEAD_MAGIC; - return tdb_rec_write(tdb, rec_ptr, rec); - } - if (tdb_write_unlock_record(tdb, rec_ptr) != 0) - return -1; - - /* find previous record in hash chain */ - if (tdb_ofs_read(tdb, TDB_HASH_TOP(rec->full_hash), &i) == -1) - return -1; - for (last_ptr = 0; i != rec_ptr; last_ptr = i, i = lastrec.next) - if (tdb_rec_read(tdb, i, &lastrec) == -1) - return -1; - - /* unlink it: next ptr is at start of record. */ - if (last_ptr == 0) - last_ptr = TDB_HASH_TOP(rec->full_hash); - if (tdb_ofs_write(tdb, last_ptr, &rec->next) == -1) - return -1; - - /* recover the space */ - if (tdb_free(tdb, rec_ptr, rec) == -1) - return -1; - return 0; -} - -static int tdb_count_dead(struct tdb_context *tdb, uint32_t hash) -{ - int res = 0; - tdb_off_t rec_ptr; - struct tdb_record rec; - - /* read in the hash top */ - if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) - return 0; - - while (rec_ptr) { - if (tdb_rec_read(tdb, rec_ptr, &rec) == -1) - return 0; - - if (rec.magic == TDB_DEAD_MAGIC) { - res += 1; - } - rec_ptr = rec.next; - } - return res; -} - -/* - * Purge all DEAD records from a hash chain - */ -static int tdb_purge_dead(struct tdb_context *tdb, uint32_t hash) -{ - int res = -1; - struct tdb_record rec; - tdb_off_t rec_ptr; - - if (tdb_lock(tdb, -1, F_WRLCK) == -1) { - return -1; - } - - /* read in the hash top */ - if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) - goto fail; - - while (rec_ptr) { - tdb_off_t next; - - if (tdb_rec_read(tdb, rec_ptr, &rec) == -1) { - goto fail; - } - - next = rec.next; - - if (rec.magic == TDB_DEAD_MAGIC - && tdb_do_delete(tdb, rec_ptr, &rec) == -1) { - goto fail; - } - rec_ptr = next; - } - res = 0; - fail: - tdb_unlock(tdb, -1, F_WRLCK); - return res; -} - -/* delete an entry in the database given a key */ -static int tdb_delete_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash) -{ - tdb_off_t rec_ptr; - struct tdb_record rec; - int ret; - - if (tdb->max_dead_records != 0) { - - /* - * Allow for some dead records per hash chain, mainly for - * tdb's with a very high create/delete rate like locking.tdb. - */ - - if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1) - return -1; - - if (tdb_count_dead(tdb, hash) >= tdb->max_dead_records) { - /* - * Don't let the per-chain freelist grow too large, - * delete all existing dead records - */ - tdb_purge_dead(tdb, hash); - } - - if (!(rec_ptr = tdb_find(tdb, key, hash, &rec))) { - tdb_unlock(tdb, BUCKET(hash), F_WRLCK); - return -1; - } - - /* - * Just mark the record as dead. - */ - rec.magic = TDB_DEAD_MAGIC; - ret = tdb_rec_write(tdb, rec_ptr, &rec); - } - else { - if (!(rec_ptr = tdb_find_lock_hash(tdb, key, hash, F_WRLCK, - &rec))) - return -1; - - ret = tdb_do_delete(tdb, rec_ptr, &rec); - } - - if (ret == 0) { - tdb_increment_seqnum(tdb); - } - - if (tdb_unlock(tdb, BUCKET(rec.full_hash), F_WRLCK) != 0) - TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_delete: WARNING tdb_unlock failed!\n")); - return ret; -} - -int tdb_delete(struct tdb_context *tdb, TDB_DATA key) -{ - uint32_t hash = tdb->hash_fn(&key); - int ret; - - ret = tdb_delete_hash(tdb, key, hash); - tdb_trace_1rec_ret(tdb, "tdb_delete", key, ret); - return ret; -} - -/* - * See if we have a dead record around with enough space - */ -static tdb_off_t tdb_find_dead(struct tdb_context *tdb, uint32_t hash, - struct tdb_record *r, tdb_len_t length) -{ - tdb_off_t rec_ptr; - - /* read in the hash top */ - if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) - return 0; - - /* keep looking until we find the right record */ - while (rec_ptr) { - if (tdb_rec_read(tdb, rec_ptr, r) == -1) - return 0; - - if (TDB_DEAD(r) && r->rec_len >= length) { - /* - * First fit for simple coding, TODO: change to best - * fit - */ - return rec_ptr; - } - rec_ptr = r->next; - } - return 0; -} - -static int _tdb_store(struct tdb_context *tdb, TDB_DATA key, - TDB_DATA dbuf, int flag, uint32_t hash) -{ - struct tdb_record rec; - tdb_off_t rec_ptr; - char *p = NULL; - int ret = -1; - - /* check for it existing, on insert. */ - if (flag == TDB_INSERT) { - if (tdb_exists_hash(tdb, key, hash)) { - tdb->ecode = TDB_ERR_EXISTS; - goto fail; - } - } else { - /* first try in-place update, on modify or replace. */ - if (tdb_update_hash(tdb, key, hash, dbuf) == 0) { - goto done; - } - if (tdb->ecode == TDB_ERR_NOEXIST && - flag == TDB_MODIFY) { - /* if the record doesn't exist and we are in TDB_MODIFY mode then - we should fail the store */ - goto fail; - } - } - /* reset the error code potentially set by the tdb_update() */ - tdb->ecode = TDB_SUCCESS; - - /* delete any existing record - if it doesn't exist we don't - care. Doing this first reduces fragmentation, and avoids - coalescing with `allocated' block before it's updated. */ - if (flag != TDB_INSERT) - tdb_delete_hash(tdb, key, hash); - - /* Copy key+value *before* allocating free space in case malloc - fails and we are left with a dead spot in the tdb. */ - - if (!(p = (char *)malloc(key.dsize + dbuf.dsize))) { - tdb->ecode = TDB_ERR_OOM; - goto fail; - } - - memcpy(p, key.dptr, key.dsize); - if (dbuf.dsize) - memcpy(p+key.dsize, dbuf.dptr, dbuf.dsize); - - if (tdb->max_dead_records != 0) { - /* - * Allow for some dead records per hash chain, look if we can - * find one that can hold the new record. We need enough space - * for key, data and tailer. If we find one, we don't have to - * consult the central freelist. - */ - rec_ptr = tdb_find_dead( - tdb, hash, &rec, - key.dsize + dbuf.dsize + sizeof(tdb_off_t)); - - if (rec_ptr != 0) { - rec.key_len = key.dsize; - rec.data_len = dbuf.dsize; - rec.full_hash = hash; - rec.magic = TDB_MAGIC; - if (tdb_rec_write(tdb, rec_ptr, &rec) == -1 - || tdb->methods->tdb_write( - tdb, rec_ptr + sizeof(rec), - p, key.dsize + dbuf.dsize) == -1) { - goto fail; - } - goto done; - } - } - - /* - * We have to allocate some space from the freelist, so this means we - * have to lock it. Use the chance to purge all the DEAD records from - * the hash chain under the freelist lock. - */ - - if (tdb_lock(tdb, -1, F_WRLCK) == -1) { - goto fail; - } - - if ((tdb->max_dead_records != 0) - && (tdb_purge_dead(tdb, hash) == -1)) { - tdb_unlock(tdb, -1, F_WRLCK); - goto fail; - } - - /* we have to allocate some space */ - rec_ptr = tdb_allocate(tdb, key.dsize + dbuf.dsize, &rec); - - tdb_unlock(tdb, -1, F_WRLCK); - - if (rec_ptr == 0) { - goto fail; - } - - /* Read hash top into next ptr */ - if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec.next) == -1) - goto fail; - - rec.key_len = key.dsize; - rec.data_len = dbuf.dsize; - rec.full_hash = hash; - rec.magic = TDB_MAGIC; - - /* write out and point the top of the hash chain at it */ - if (tdb_rec_write(tdb, rec_ptr, &rec) == -1 - || tdb->methods->tdb_write(tdb, rec_ptr+sizeof(rec), p, key.dsize+dbuf.dsize)==-1 - || tdb_ofs_write(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) { - /* Need to tdb_unallocate() here */ - goto fail; - } - - done: - ret = 0; - fail: - if (ret == 0) { - tdb_increment_seqnum(tdb); - } - - SAFE_FREE(p); - return ret; -} - -/* store an element in the database, replacing any existing element - with the same key - - return 0 on success, -1 on failure -*/ -int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag) -{ - uint32_t hash; - int ret; - - if (tdb->read_only || tdb->traverse_read) { - tdb->ecode = TDB_ERR_RDONLY; - tdb_trace_2rec_flag_ret(tdb, "tdb_store", key, dbuf, flag, -1); - return -1; - } - - /* find which hash bucket it is in */ - hash = tdb->hash_fn(&key); - if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1) - return -1; - - ret = _tdb_store(tdb, key, dbuf, flag, hash); - tdb_trace_2rec_flag_ret(tdb, "tdb_store", key, dbuf, flag, ret); - tdb_unlock(tdb, BUCKET(hash), F_WRLCK); - return ret; -} - -/* Append to an entry. Create if not exist. */ -int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf) -{ - uint32_t hash; - TDB_DATA dbuf; - int ret = -1; - - /* find which hash bucket it is in */ - hash = tdb->hash_fn(&key); - if (tdb_lock(tdb, BUCKET(hash), F_WRLCK) == -1) - return -1; - - dbuf = _tdb_fetch(tdb, key); - - if (dbuf.dptr == NULL) { - dbuf.dptr = (unsigned char *)malloc(new_dbuf.dsize); - } else { - unsigned int new_len = dbuf.dsize + new_dbuf.dsize; - unsigned char *new_dptr; - - /* realloc '0' is special: don't do that. */ - if (new_len == 0) - new_len = 1; - new_dptr = (unsigned char *)realloc(dbuf.dptr, new_len); - if (new_dptr == NULL) { - free(dbuf.dptr); - } - dbuf.dptr = new_dptr; - } - - if (dbuf.dptr == NULL) { - tdb->ecode = TDB_ERR_OOM; - goto failed; - } - - memcpy(dbuf.dptr + dbuf.dsize, new_dbuf.dptr, new_dbuf.dsize); - dbuf.dsize += new_dbuf.dsize; - - ret = _tdb_store(tdb, key, dbuf, 0, hash); - tdb_trace_2rec_retrec(tdb, "tdb_append", key, new_dbuf, dbuf); - -failed: - tdb_unlock(tdb, BUCKET(hash), F_WRLCK); - SAFE_FREE(dbuf.dptr); - return ret; -} - - -/* - return the name of the current tdb file - useful for external logging functions -*/ -const char *tdb_name(struct tdb_context *tdb) -{ - return tdb->name; -} - -/* - return the underlying file descriptor being used by tdb, or -1 - useful for external routines that want to check the device/inode - of the fd -*/ -int tdb_fd(struct tdb_context *tdb) -{ - return tdb->fd; -} - -/* - return the current logging function - useful for external tdb routines that wish to log tdb errors -*/ -tdb_log_func tdb_log_fn(struct tdb_context *tdb) -{ - return tdb->log.log_fn; -} - - -/* - get the tdb sequence number. Only makes sense if the writers opened - with TDB_SEQNUM set. Note that this sequence number will wrap quite - quickly, so it should only be used for a 'has something changed' - test, not for code that relies on the count of the number of changes - made. If you want a counter then use a tdb record. - - The aim of this sequence number is to allow for a very lightweight - test of a possible tdb change. -*/ -int tdb_get_seqnum(struct tdb_context *tdb) -{ - tdb_off_t seqnum=0; - - tdb_ofs_read(tdb, TDB_SEQNUM_OFS, &seqnum); - return seqnum; -} - -int tdb_hash_size(struct tdb_context *tdb) -{ - return tdb->header.hash_size; -} - -size_t tdb_map_size(struct tdb_context *tdb) -{ - return tdb->map_size; -} - -int tdb_get_flags(struct tdb_context *tdb) -{ - return tdb->flags; -} - -void tdb_add_flags(struct tdb_context *tdb, unsigned flags) -{ - if ((flags & TDB_ALLOW_NESTING) && - (flags & TDB_DISALLOW_NESTING)) { - tdb->ecode = TDB_ERR_NESTING; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_add_flags: " - "allow_nesting and disallow_nesting are not allowed together!")); - return; - } - - if (flags & TDB_ALLOW_NESTING) { - tdb->flags &= ~TDB_DISALLOW_NESTING; - } - if (flags & TDB_DISALLOW_NESTING) { - tdb->flags &= ~TDB_ALLOW_NESTING; - } - - tdb->flags |= flags; -} - -void tdb_remove_flags(struct tdb_context *tdb, unsigned flags) -{ - if ((flags & TDB_ALLOW_NESTING) && - (flags & TDB_DISALLOW_NESTING)) { - tdb->ecode = TDB_ERR_NESTING; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_remove_flags: " - "allow_nesting and disallow_nesting are not allowed together!")); - return; - } - - if (flags & TDB_ALLOW_NESTING) { - tdb->flags |= TDB_DISALLOW_NESTING; - } - if (flags & TDB_DISALLOW_NESTING) { - tdb->flags |= TDB_ALLOW_NESTING; - } - - tdb->flags &= ~flags; -} - - -/* - enable sequence number handling on an open tdb -*/ -void tdb_enable_seqnum(struct tdb_context *tdb) -{ - tdb->flags |= TDB_SEQNUM; -} - - -/* - add a region of the file to the freelist. Length is the size of the region in bytes, - which includes the free list header that needs to be added - */ -static int tdb_free_region(struct tdb_context *tdb, tdb_off_t offset, ssize_t length) -{ - struct tdb_record rec; - if (length <= sizeof(rec)) { - /* the region is not worth adding */ - return 0; - } - if (length + offset > tdb->map_size) { - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_free_region: adding region beyond end of file\n")); - return -1; - } - memset(&rec,'\0',sizeof(rec)); - rec.rec_len = length - sizeof(rec); - if (tdb_free(tdb, offset, &rec) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_free_region: failed to add free record\n")); - return -1; - } - return 0; -} - -/* - wipe the entire database, deleting all records. This can be done - very fast by using a allrecord lock. The entire data portion of the - file becomes a single entry in the freelist. - - This code carefully steps around the recovery area, leaving it alone - */ -int tdb_wipe_all(struct tdb_context *tdb) -{ - int i; - tdb_off_t offset = 0; - ssize_t data_len; - tdb_off_t recovery_head; - tdb_len_t recovery_size = 0; - - if (tdb_lockall(tdb) != 0) { - return -1; - } - - tdb_trace(tdb, "tdb_wipe_all"); - - /* see if the tdb has a recovery area, and remember its size - if so. We don't want to lose this as otherwise each - tdb_wipe_all() in a transaction will increase the size of - the tdb by the size of the recovery area */ - if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_wipe_all: failed to read recovery head\n")); - goto failed; - } - - if (recovery_head != 0) { - struct tdb_record rec; - if (tdb->methods->tdb_read(tdb, recovery_head, &rec, sizeof(rec), DOCONV()) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_wipe_all: failed to read recovery record\n")); - return -1; - } - recovery_size = rec.rec_len + sizeof(rec); - } - - /* wipe the hashes */ - for (i=0;iheader.hash_size;i++) { - if (tdb_ofs_write(tdb, TDB_HASH_TOP(i), &offset) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to write hash %d\n", i)); - goto failed; - } - } - - /* wipe the freelist */ - if (tdb_ofs_write(tdb, FREELIST_TOP, &offset) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to write freelist\n")); - goto failed; - } - - /* add all the rest of the file to the freelist, possibly leaving a gap - for the recovery area */ - if (recovery_size == 0) { - /* the simple case - the whole file can be used as a freelist */ - data_len = (tdb->map_size - TDB_DATA_START(tdb->header.hash_size)); - if (tdb_free_region(tdb, TDB_DATA_START(tdb->header.hash_size), data_len) != 0) { - goto failed; - } - } else { - /* we need to add two freelist entries - one on either - side of the recovery area - - Note that we cannot shift the recovery area during - this operation. Only the transaction.c code may - move the recovery area or we risk subtle data - corruption - */ - data_len = (recovery_head - TDB_DATA_START(tdb->header.hash_size)); - if (tdb_free_region(tdb, TDB_DATA_START(tdb->header.hash_size), data_len) != 0) { - goto failed; - } - /* and the 2nd free list entry after the recovery area - if any */ - data_len = tdb->map_size - (recovery_head+recovery_size); - if (tdb_free_region(tdb, recovery_head+recovery_size, data_len) != 0) { - goto failed; - } - } - - if (tdb_unlockall(tdb) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to unlock\n")); - goto failed; - } - - return 0; - -failed: - tdb_unlockall(tdb); - return -1; -} - -struct traverse_state { - bool error; - struct tdb_context *dest_db; -}; - -/* - traverse function for repacking - */ -static int repack_traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *private_data) -{ - struct traverse_state *state = (struct traverse_state *)private_data; - if (tdb_store(state->dest_db, key, data, TDB_INSERT) != 0) { - state->error = true; - return -1; - } - return 0; -} - -/* - repack a tdb - */ -int tdb_repack(struct tdb_context *tdb) -{ - struct tdb_context *tmp_db; - struct traverse_state state; - - tdb_trace(tdb, "tdb_repack"); - - if (tdb_transaction_start(tdb) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to start transaction\n")); - return -1; - } - - tmp_db = tdb_open("tmpdb", tdb_hash_size(tdb), TDB_INTERNAL, O_RDWR|O_CREAT, 0); - if (tmp_db == NULL) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to create tmp_db\n")); - tdb_transaction_cancel(tdb); - return -1; - } - - state.error = false; - state.dest_db = tmp_db; - - if (tdb_traverse_read(tdb, repack_traverse, &state) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to traverse copying out\n")); - tdb_transaction_cancel(tdb); - tdb_close(tmp_db); - return -1; - } - - if (state.error) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Error during traversal\n")); - tdb_transaction_cancel(tdb); - tdb_close(tmp_db); - return -1; - } - - if (tdb_wipe_all(tdb) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to wipe database\n")); - tdb_transaction_cancel(tdb); - tdb_close(tmp_db); - return -1; - } - - state.error = false; - state.dest_db = tdb; - - if (tdb_traverse_read(tmp_db, repack_traverse, &state) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to traverse copying back\n")); - tdb_transaction_cancel(tdb); - tdb_close(tmp_db); - return -1; - } - - if (state.error) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Error during second traversal\n")); - tdb_transaction_cancel(tdb); - tdb_close(tmp_db); - return -1; - } - - tdb_close(tmp_db); - - if (tdb_transaction_commit(tdb) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, __location__ " Failed to commit\n")); - return -1; - } - - return 0; -} - -/* Even on files, we can get partial writes due to signals. */ -bool tdb_write_all(int fd, const void *buf, size_t count) -{ - while (count) { - size_t ret; - ret = write(fd, buf, count); - if (ret < 0) - return false; - buf = (const char *)buf + ret; - count -= ret; - } - return true; -} - -#ifdef TDB_TRACE -static void tdb_trace_write(struct tdb_context *tdb, const char *str) -{ - if (!tdb_write_alltdb->tracefd, str, strlen(str)) { - close(tdb->tracefd); - tdb->tracefd = -1; - } -} - -static void tdb_trace_start(struct tdb_context *tdb) -{ - tdb_off_t seqnum=0; - char msg[sizeof(tdb_off_t) * 4 + 1]; - - tdb_ofs_read(tdb, TDB_SEQNUM_OFS, &seqnum); - snprintf(msg, sizeof(msg), "%u ", seqnum); - tdb_trace_write(tdb, msg); -} - -static void tdb_trace_end(struct tdb_context *tdb) -{ - tdb_trace_write(tdb, "\n"); -} - -static void tdb_trace_end_ret(struct tdb_context *tdb, int ret) -{ - char msg[sizeof(ret) * 4 + 4]; - snprintf(msg, sizeof(msg), " = %i\n", ret); - tdb_trace_write(tdb, msg); -} - -static void tdb_trace_record(struct tdb_context *tdb, TDB_DATA rec) -{ - char msg[20 + rec.dsize*2], *p; - unsigned int i; - - /* We differentiate zero-length records from non-existent ones. */ - if (rec.dptr == NULL) { - tdb_trace_write(tdb, " NULL"); - return; - } - - /* snprintf here is purely cargo-cult programming. */ - p = msg; - p += snprintf(p, sizeof(msg), " %zu:", rec.dsize); - for (i = 0; i < rec.dsize; i++) - p += snprintf(p, 2, "%02x", rec.dptr[i]); - - tdb_trace_write(tdb, msg); -} - -void tdb_trace(struct tdb_context *tdb, const char *op) -{ - tdb_trace_start(tdb); - tdb_trace_write(tdb, op); - tdb_trace_end(tdb); -} - -void tdb_trace_seqnum(struct tdb_context *tdb, uint32_t seqnum, const char *op) -{ - char msg[sizeof(tdb_off_t) * 4 + 1]; - - snprintf(msg, sizeof(msg), "%u ", seqnum); - tdb_trace_write(tdb, msg); - tdb_trace_write(tdb, op); - tdb_trace_end(tdb); -} - -void tdb_trace_open(struct tdb_context *tdb, const char *op, - unsigned hash_size, unsigned tdb_flags, unsigned open_flags) -{ - char msg[128]; - - snprintf(msg, sizeof(msg), - "%s %u 0x%x 0x%x", op, hash_size, tdb_flags, open_flags); - tdb_trace_start(tdb); - tdb_trace_write(tdb, msg); - tdb_trace_end(tdb); -} - -void tdb_trace_ret(struct tdb_context *tdb, const char *op, int ret) -{ - tdb_trace_start(tdb); - tdb_trace_write(tdb, op); - tdb_trace_end_ret(tdb, ret); -} - -void tdb_trace_retrec(struct tdb_context *tdb, const char *op, TDB_DATA ret) -{ - tdb_trace_start(tdb); - tdb_trace_write(tdb, op); - tdb_trace_write(tdb, " ="); - tdb_trace_record(tdb, ret); - tdb_trace_end(tdb); -} - -void tdb_trace_1rec(struct tdb_context *tdb, const char *op, - TDB_DATA rec) -{ - tdb_trace_start(tdb); - tdb_trace_write(tdb, op); - tdb_trace_record(tdb, rec); - tdb_trace_end(tdb); -} - -void tdb_trace_1rec_ret(struct tdb_context *tdb, const char *op, - TDB_DATA rec, int ret) -{ - tdb_trace_start(tdb); - tdb_trace_write(tdb, op); - tdb_trace_record(tdb, rec); - tdb_trace_end_ret(tdb, ret); -} - -void tdb_trace_1rec_retrec(struct tdb_context *tdb, const char *op, - TDB_DATA rec, TDB_DATA ret) -{ - tdb_trace_start(tdb); - tdb_trace_write(tdb, op); - tdb_trace_record(tdb, rec); - tdb_trace_write(tdb, " ="); - tdb_trace_record(tdb, ret); - tdb_trace_end(tdb); -} - -void tdb_trace_2rec_flag_ret(struct tdb_context *tdb, const char *op, - TDB_DATA rec1, TDB_DATA rec2, unsigned flag, - int ret) -{ - char msg[1 + sizeof(ret) * 4]; - - snprintf(msg, sizeof(msg), " %#x", flag); - tdb_trace_start(tdb); - tdb_trace_write(tdb, op); - tdb_trace_record(tdb, rec1); - tdb_trace_record(tdb, rec2); - tdb_trace_write(tdb, msg); - tdb_trace_end_ret(tdb, ret); -} - -void tdb_trace_2rec_retrec(struct tdb_context *tdb, const char *op, - TDB_DATA rec1, TDB_DATA rec2, TDB_DATA ret) -{ - tdb_trace_start(tdb); - tdb_trace_write(tdb, op); - tdb_trace_record(tdb, rec1); - tdb_trace_record(tdb, rec2); - tdb_trace_write(tdb, " ="); - tdb_trace_record(tdb, ret); - tdb_trace_end(tdb); -} -#endif diff --git a/bundled/tdb/common/tdb_private.h b/bundled/tdb/common/tdb_private.h deleted file mode 100644 index 9d0f3bcd..00000000 --- a/bundled/tdb/common/tdb_private.h +++ /dev/null @@ -1,270 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - private includes - - Copyright (C) Andrew Tridgell 2005 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "replace.h" -#include "system/filesys.h" -#include "system/time.h" -#include "system/shmem.h" -#include "system/select.h" -#include "system/wait.h" -#include "tdb.h" - -/* #define TDB_TRACE 1 */ -#ifndef HAVE_GETPAGESIZE -#define getpagesize() 0x2000 -#endif - -typedef uint32_t tdb_len_t; -typedef uint32_t tdb_off_t; - -#ifndef offsetof -#define offsetof(t,f) ((unsigned int)&((t *)0)->f) -#endif - -#define TDB_MAGIC_FOOD "TDB file\n" -#define TDB_VERSION (0x26011967 + 6) -#define TDB_MAGIC (0x26011999U) -#define TDB_FREE_MAGIC (~TDB_MAGIC) -#define TDB_DEAD_MAGIC (0xFEE1DEAD) -#define TDB_RECOVERY_MAGIC (0xf53bc0e7U) -#define TDB_RECOVERY_INVALID_MAGIC (0x0) -#define TDB_ALIGNMENT 4 -#define DEFAULT_HASH_SIZE 131 -#define FREELIST_TOP (sizeof(struct tdb_header)) -#define TDB_ALIGN(x,a) (((x) + (a)-1) & ~((a)-1)) -#define TDB_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24)) -#define TDB_DEAD(r) ((r)->magic == TDB_DEAD_MAGIC) -#define TDB_BAD_MAGIC(r) ((r)->magic != TDB_MAGIC && !TDB_DEAD(r)) -#define TDB_HASH_TOP(hash) (FREELIST_TOP + (BUCKET(hash)+1)*sizeof(tdb_off_t)) -#define TDB_HASHTABLE_SIZE(tdb) ((tdb->header.hash_size+1)*sizeof(tdb_off_t)) -#define TDB_DATA_START(hash_size) (TDB_HASH_TOP(hash_size-1) + sizeof(tdb_off_t)) -#define TDB_RECOVERY_HEAD offsetof(struct tdb_header, recovery_start) -#define TDB_SEQNUM_OFS offsetof(struct tdb_header, sequence_number) -#define TDB_PAD_BYTE 0x42 -#define TDB_PAD_U32 0x42424242 - -/* NB assumes there is a local variable called "tdb" that is the - * current context, also takes doubly-parenthesized print-style - * argument. */ -#define TDB_LOG(x) tdb->log.log_fn x - -#ifdef TDB_TRACE -void tdb_trace(struct tdb_context *tdb, const char *op); -void tdb_trace_seqnum(struct tdb_context *tdb, uint32_t seqnum, const char *op); -void tdb_trace_open(struct tdb_context *tdb, const char *op, - unsigned hash_size, unsigned tdb_flags, unsigned open_flags); -void tdb_trace_ret(struct tdb_context *tdb, const char *op, int ret); -void tdb_trace_retrec(struct tdb_context *tdb, const char *op, TDB_DATA ret); -void tdb_trace_1rec(struct tdb_context *tdb, const char *op, - TDB_DATA rec); -void tdb_trace_1rec_ret(struct tdb_context *tdb, const char *op, - TDB_DATA rec, int ret); -void tdb_trace_1rec_retrec(struct tdb_context *tdb, const char *op, - TDB_DATA rec, TDB_DATA ret); -void tdb_trace_2rec_flag_ret(struct tdb_context *tdb, const char *op, - TDB_DATA rec1, TDB_DATA rec2, unsigned flag, - int ret); -void tdb_trace_2rec_retrec(struct tdb_context *tdb, const char *op, - TDB_DATA rec1, TDB_DATA rec2, TDB_DATA ret); -#else -#define tdb_trace(tdb, op) -#define tdb_trace_seqnum(tdb, seqnum, op) -#define tdb_trace_open(tdb, op, hash_size, tdb_flags, open_flags) -#define tdb_trace_ret(tdb, op, ret) -#define tdb_trace_retrec(tdb, op, ret) -#define tdb_trace_1rec(tdb, op, rec) -#define tdb_trace_1rec_ret(tdb, op, rec, ret) -#define tdb_trace_1rec_retrec(tdb, op, rec, ret) -#define tdb_trace_2rec_flag_ret(tdb, op, rec1, rec2, flag, ret) -#define tdb_trace_2rec_retrec(tdb, op, rec1, rec2, ret) -#endif /* !TDB_TRACE */ - -/* lock offsets */ -#define OPEN_LOCK 0 -#define ACTIVE_LOCK 4 -#define TRANSACTION_LOCK 8 - -/* free memory if the pointer is valid and zero the pointer */ -#ifndef SAFE_FREE -#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0) -#endif - -#define BUCKET(hash) ((hash) % tdb->header.hash_size) - -#define DOCONV() (tdb->flags & TDB_CONVERT) -#define CONVERT(x) (DOCONV() ? tdb_convert(&x, sizeof(x)) : &x) - - -/* the body of the database is made of one tdb_record for the free space - plus a separate data list for each hash value */ -struct tdb_record { - tdb_off_t next; /* offset of the next record in the list */ - tdb_len_t rec_len; /* total byte length of record */ - tdb_len_t key_len; /* byte length of key */ - tdb_len_t data_len; /* byte length of data */ - uint32_t full_hash; /* the full 32 bit hash of the key */ - uint32_t magic; /* try to catch errors */ - /* the following union is implied: - union { - char record[rec_len]; - struct { - char key[key_len]; - char data[data_len]; - } - uint32_t totalsize; (tailer) - } - */ -}; - - -/* this is stored at the front of every database */ -struct tdb_header { - char magic_food[32]; /* for /etc/magic */ - uint32_t version; /* version of the code */ - uint32_t hash_size; /* number of hash entries */ - tdb_off_t rwlocks; /* obsolete - kept to detect old formats */ - tdb_off_t recovery_start; /* offset of transaction recovery region */ - tdb_off_t sequence_number; /* used when TDB_SEQNUM is set */ - tdb_off_t reserved[29]; -}; - -struct tdb_lock_type { - uint32_t off; - uint32_t count; - uint32_t ltype; -}; - -struct tdb_traverse_lock { - struct tdb_traverse_lock *next; - uint32_t off; - uint32_t hash; - int lock_rw; -}; - -enum tdb_lock_flags { - /* WAIT == F_SETLKW, NOWAIT == F_SETLK */ - TDB_LOCK_NOWAIT = 0, - TDB_LOCK_WAIT = 1, - /* If set, don't log an error on failure. */ - TDB_LOCK_PROBE = 2, - /* If set, don't actually lock at all. */ - TDB_LOCK_MARK_ONLY = 4, -}; - -struct tdb_methods { - int (*tdb_read)(struct tdb_context *, tdb_off_t , void *, tdb_len_t , int ); - int (*tdb_write)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t); - void (*next_hash_chain)(struct tdb_context *, uint32_t *); - int (*tdb_oob)(struct tdb_context *, tdb_off_t , int ); - int (*tdb_expand_file)(struct tdb_context *, tdb_off_t , tdb_off_t ); -}; - -struct tdb_context { - char *name; /* the name of the database */ - void *map_ptr; /* where it is currently mapped */ - int fd; /* open file descriptor for the database */ - tdb_len_t map_size; /* how much space has been mapped */ - int read_only; /* opened read-only */ - int traverse_read; /* read-only traversal */ - int traverse_write; /* read-write traversal */ - struct tdb_lock_type allrecord_lock; /* .offset == upgradable */ - int num_lockrecs; - struct tdb_lock_type *lockrecs; /* only real locks, all with count>0 */ - enum TDB_ERROR ecode; /* error code for last tdb error */ - struct tdb_header header; /* a cached copy of the header */ - uint32_t flags; /* the flags passed to tdb_open */ - struct tdb_traverse_lock travlocks; /* current traversal locks */ - struct tdb_context *next; /* all tdbs to avoid multiple opens */ - dev_t device; /* uniquely identifies this tdb */ - ino_t inode; /* uniquely identifies this tdb */ - struct tdb_logging_context log; - unsigned int (*hash_fn)(TDB_DATA *key); - int open_flags; /* flags used in the open - needed by reopen */ - const struct tdb_methods *methods; - struct tdb_transaction *transaction; - int page_size; - int max_dead_records; -#ifdef TDB_TRACE - int tracefd; -#endif - volatile sig_atomic_t *interrupt_sig_ptr; -}; - - -/* - internal prototypes -*/ -int tdb_munmap(struct tdb_context *tdb); -void tdb_mmap(struct tdb_context *tdb); -int tdb_lock(struct tdb_context *tdb, int list, int ltype); -int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype); -int tdb_nest_lock(struct tdb_context *tdb, uint32_t offset, int ltype, - enum tdb_lock_flags flags); -int tdb_nest_unlock(struct tdb_context *tdb, uint32_t offset, int ltype, - bool mark_lock); -int tdb_unlock(struct tdb_context *tdb, int list, int ltype); -int tdb_brlock(struct tdb_context *tdb, - int rw_type, tdb_off_t offset, size_t len, - enum tdb_lock_flags flags); -int tdb_brunlock(struct tdb_context *tdb, - int rw_type, tdb_off_t offset, size_t len); -bool tdb_have_extra_locks(struct tdb_context *tdb); -void tdb_release_transaction_locks(struct tdb_context *tdb); -int tdb_transaction_lock(struct tdb_context *tdb, int ltype, - enum tdb_lock_flags lockflags); -int tdb_transaction_unlock(struct tdb_context *tdb, int ltype); -int tdb_allrecord_lock(struct tdb_context *tdb, int ltype, - enum tdb_lock_flags flags, bool upgradable); -int tdb_allrecord_unlock(struct tdb_context *tdb, int ltype, bool mark_lock); -int tdb_allrecord_upgrade(struct tdb_context *tdb); -int tdb_write_lock_record(struct tdb_context *tdb, tdb_off_t off); -int tdb_write_unlock_record(struct tdb_context *tdb, tdb_off_t off); -int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d); -int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d); -void *tdb_convert(void *buf, uint32_t size); -int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec); -tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct tdb_record *rec); -int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d); -int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d); -int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off); -int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off); -bool tdb_needs_recovery(struct tdb_context *tdb); -int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec); -int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec); -int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct tdb_record *rec); -unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len); -int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key, - tdb_off_t offset, tdb_len_t len, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data); -tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, int locktype, - struct tdb_record *rec); -void tdb_io_init(struct tdb_context *tdb); -int tdb_expand(struct tdb_context *tdb, tdb_off_t size); -int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, - struct tdb_record *rec); -bool tdb_write_all(int fd, const void *buf, size_t count); -int tdb_transaction_recover(struct tdb_context *tdb); diff --git a/bundled/tdb/common/transaction.c b/bundled/tdb/common/transaction.c deleted file mode 100644 index ebf1cec5..00000000 --- a/bundled/tdb/common/transaction.c +++ /dev/null @@ -1,1236 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Andrew Tridgell 2005 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "tdb_private.h" - -/* - transaction design: - - - only allow a single transaction at a time per database. This makes - using the transaction API simpler, as otherwise the caller would - have to cope with temporary failures in transactions that conflict - with other current transactions - - - keep the transaction recovery information in the same file as the - database, using a special 'transaction recovery' record pointed at - by the header. This removes the need for extra journal files as - used by some other databases - - - dynamically allocated the transaction recover record, re-using it - for subsequent transactions. If a larger record is needed then - tdb_free() the old record to place it on the normal tdb freelist - before allocating the new record - - - during transactions, keep a linked list of writes all that have - been performed by intercepting all tdb_write() calls. The hooked - transaction versions of tdb_read() and tdb_write() check this - linked list and try to use the elements of the list in preference - to the real database. - - - don't allow any locks to be held when a transaction starts, - otherwise we can end up with deadlock (plus lack of lock nesting - in posix locks would mean the lock is lost) - - - if the caller gains a lock during the transaction but doesn't - release it then fail the commit - - - allow for nested calls to tdb_transaction_start(), re-using the - existing transaction record. If the inner transaction is cancelled - then a subsequent commit will fail - - - keep a mirrored copy of the tdb hash chain heads to allow for the - fast hash heads scan on traverse, updating the mirrored copy in - the transaction version of tdb_write - - - allow callers to mix transaction and non-transaction use of tdb, - although once a transaction is started then an exclusive lock is - gained until the transaction is committed or cancelled - - - the commit stategy involves first saving away all modified data - into a linearised buffer in the transaction recovery area, then - marking the transaction recovery area with a magic value to - indicate a valid recovery record. In total 4 fsync/msync calls are - needed per commit to prevent race conditions. It might be possible - to reduce this to 3 or even 2 with some more work. - - - check for a valid recovery record on open of the tdb, while the - open lock is held. Automatically recover from the transaction - recovery area if needed, then continue with the open as - usual. This allows for smooth crash recovery with no administrator - intervention. - - - if TDB_NOSYNC is passed to flags in tdb_open then transactions are - still available, but no transaction recovery area is used and no - fsync/msync calls are made. - - - if TDB_ALLOW_NESTING is passed to flags in tdb open, or added using - tdb_add_flags() transaction nesting is enabled. - It resets the TDB_DISALLOW_NESTING flag, as both cannot be used together. - The default is that transaction nesting is allowed. - Note: this default may change in future versions of tdb. - - Beware. when transactions are nested a transaction successfully - completed with tdb_transaction_commit() can be silently unrolled later. - - - if TDB_DISALLOW_NESTING is passed to flags in tdb open, or added using - tdb_add_flags() transaction nesting is disabled. - It resets the TDB_ALLOW_NESTING flag, as both cannot be used together. - An attempt create a nested transaction will fail with TDB_ERR_NESTING. - The default is that transaction nesting is allowed. - Note: this default may change in future versions of tdb. -*/ - - -/* - hold the context of any current transaction -*/ -struct tdb_transaction { - /* we keep a mirrored copy of the tdb hash heads here so - tdb_next_hash_chain() can operate efficiently */ - uint32_t *hash_heads; - - /* the original io methods - used to do IOs to the real db */ - const struct tdb_methods *io_methods; - - /* the list of transaction blocks. When a block is first - written to, it gets created in this list */ - uint8_t **blocks; - uint32_t num_blocks; - uint32_t block_size; /* bytes in each block */ - uint32_t last_block_size; /* number of valid bytes in the last block */ - - /* non-zero when an internal transaction error has - occurred. All write operations will then fail until the - transaction is ended */ - int transaction_error; - - /* when inside a transaction we need to keep track of any - nested tdb_transaction_start() calls, as these are allowed, - but don't create a new transaction */ - int nesting; - - /* set when a prepare has already occurred */ - bool prepared; - tdb_off_t magic_offset; - - /* old file size before transaction */ - tdb_len_t old_map_size; - - /* we should re-pack on commit */ - bool need_repack; -}; - - -/* - read while in a transaction. We need to check first if the data is in our list - of transaction elements, then if not do a real read -*/ -static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf, - tdb_len_t len, int cv) -{ - uint32_t blk; - - /* break it down into block sized ops */ - while (len + (off % tdb->transaction->block_size) > tdb->transaction->block_size) { - tdb_len_t len2 = tdb->transaction->block_size - (off % tdb->transaction->block_size); - if (transaction_read(tdb, off, buf, len2, cv) != 0) { - return -1; - } - len -= len2; - off += len2; - buf = (void *)(len2 + (char *)buf); - } - - if (len == 0) { - return 0; - } - - blk = off / tdb->transaction->block_size; - - /* see if we have it in the block list */ - if (tdb->transaction->num_blocks <= blk || - tdb->transaction->blocks[blk] == NULL) { - /* nope, do a real read */ - if (tdb->transaction->io_methods->tdb_read(tdb, off, buf, len, cv) != 0) { - goto fail; - } - return 0; - } - - /* it is in the block list. Now check for the last block */ - if (blk == tdb->transaction->num_blocks-1) { - if (len > tdb->transaction->last_block_size) { - goto fail; - } - } - - /* now copy it out of this block */ - memcpy(buf, tdb->transaction->blocks[blk] + (off % tdb->transaction->block_size), len); - if (cv) { - tdb_convert(buf, len); - } - return 0; - -fail: - TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_read: failed at off=%d len=%d\n", off, len)); - tdb->ecode = TDB_ERR_IO; - tdb->transaction->transaction_error = 1; - return -1; -} - - -/* - write while in a transaction -*/ -static int transaction_write(struct tdb_context *tdb, tdb_off_t off, - const void *buf, tdb_len_t len) -{ - uint32_t blk; - - /* Only a commit is allowed on a prepared transaction */ - if (tdb->transaction->prepared) { - tdb->ecode = TDB_ERR_EINVAL; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_write: transaction already prepared, write not allowed\n")); - tdb->transaction->transaction_error = 1; - return -1; - } - - /* if the write is to a hash head, then update the transaction - hash heads */ - if (len == sizeof(tdb_off_t) && off >= FREELIST_TOP && - off < FREELIST_TOP+TDB_HASHTABLE_SIZE(tdb)) { - uint32_t chain = (off-FREELIST_TOP) / sizeof(tdb_off_t); - memcpy(&tdb->transaction->hash_heads[chain], buf, len); - } - - /* break it up into block sized chunks */ - while (len + (off % tdb->transaction->block_size) > tdb->transaction->block_size) { - tdb_len_t len2 = tdb->transaction->block_size - (off % tdb->transaction->block_size); - if (transaction_write(tdb, off, buf, len2) != 0) { - return -1; - } - len -= len2; - off += len2; - if (buf != NULL) { - buf = (const void *)(len2 + (const char *)buf); - } - } - - if (len == 0) { - return 0; - } - - blk = off / tdb->transaction->block_size; - off = off % tdb->transaction->block_size; - - if (tdb->transaction->num_blocks <= blk) { - uint8_t **new_blocks; - /* expand the blocks array */ - if (tdb->transaction->blocks == NULL) { - new_blocks = (uint8_t **)malloc( - (blk+1)*sizeof(uint8_t *)); - } else { - new_blocks = (uint8_t **)realloc( - tdb->transaction->blocks, - (blk+1)*sizeof(uint8_t *)); - } - if (new_blocks == NULL) { - tdb->ecode = TDB_ERR_OOM; - goto fail; - } - memset(&new_blocks[tdb->transaction->num_blocks], 0, - (1+(blk - tdb->transaction->num_blocks))*sizeof(uint8_t *)); - tdb->transaction->blocks = new_blocks; - tdb->transaction->num_blocks = blk+1; - tdb->transaction->last_block_size = 0; - } - - /* allocate and fill a block? */ - if (tdb->transaction->blocks[blk] == NULL) { - tdb->transaction->blocks[blk] = (uint8_t *)calloc(tdb->transaction->block_size, 1); - if (tdb->transaction->blocks[blk] == NULL) { - tdb->ecode = TDB_ERR_OOM; - tdb->transaction->transaction_error = 1; - return -1; - } - if (tdb->transaction->old_map_size > blk * tdb->transaction->block_size) { - tdb_len_t len2 = tdb->transaction->block_size; - if (len2 + (blk * tdb->transaction->block_size) > tdb->transaction->old_map_size) { - len2 = tdb->transaction->old_map_size - (blk * tdb->transaction->block_size); - } - if (tdb->transaction->io_methods->tdb_read(tdb, blk * tdb->transaction->block_size, - tdb->transaction->blocks[blk], - len2, 0) != 0) { - SAFE_FREE(tdb->transaction->blocks[blk]); - tdb->ecode = TDB_ERR_IO; - goto fail; - } - if (blk == tdb->transaction->num_blocks-1) { - tdb->transaction->last_block_size = len2; - } - } - } - - /* overwrite part of an existing block */ - if (buf == NULL) { - memset(tdb->transaction->blocks[blk] + off, 0, len); - } else { - memcpy(tdb->transaction->blocks[blk] + off, buf, len); - } - if (blk == tdb->transaction->num_blocks-1) { - if (len + off > tdb->transaction->last_block_size) { - tdb->transaction->last_block_size = len + off; - } - } - - return 0; - -fail: - TDB_LOG((tdb, TDB_DEBUG_FATAL, "transaction_write: failed at off=%d len=%d\n", - (blk*tdb->transaction->block_size) + off, len)); - tdb->transaction->transaction_error = 1; - return -1; -} - - -/* - write while in a transaction - this varient never expands the transaction blocks, it only - updates existing blocks. This means it cannot change the recovery size -*/ -static int transaction_write_existing(struct tdb_context *tdb, tdb_off_t off, - const void *buf, tdb_len_t len) -{ - uint32_t blk; - - /* break it up into block sized chunks */ - while (len + (off % tdb->transaction->block_size) > tdb->transaction->block_size) { - tdb_len_t len2 = tdb->transaction->block_size - (off % tdb->transaction->block_size); - if (transaction_write_existing(tdb, off, buf, len2) != 0) { - return -1; - } - len -= len2; - off += len2; - if (buf != NULL) { - buf = (const void *)(len2 + (const char *)buf); - } - } - - if (len == 0) { - return 0; - } - - blk = off / tdb->transaction->block_size; - off = off % tdb->transaction->block_size; - - if (tdb->transaction->num_blocks <= blk || - tdb->transaction->blocks[blk] == NULL) { - return 0; - } - - if (blk == tdb->transaction->num_blocks-1 && - off + len > tdb->transaction->last_block_size) { - if (off >= tdb->transaction->last_block_size) { - return 0; - } - len = tdb->transaction->last_block_size - off; - } - - /* overwrite part of an existing block */ - memcpy(tdb->transaction->blocks[blk] + off, buf, len); - - return 0; -} - - -/* - accelerated hash chain head search, using the cached hash heads -*/ -static void transaction_next_hash_chain(struct tdb_context *tdb, uint32_t *chain) -{ - uint32_t h = *chain; - for (;h < tdb->header.hash_size;h++) { - /* the +1 takes account of the freelist */ - if (0 != tdb->transaction->hash_heads[h+1]) { - break; - } - } - (*chain) = h; -} - -/* - out of bounds check during a transaction -*/ -static int transaction_oob(struct tdb_context *tdb, tdb_off_t len, int probe) -{ - if (len <= tdb->map_size) { - return 0; - } - tdb->ecode = TDB_ERR_IO; - return -1; -} - -/* - transaction version of tdb_expand(). -*/ -static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t size, - tdb_off_t addition) -{ - /* add a write to the transaction elements, so subsequent - reads see the zero data */ - if (transaction_write(tdb, size, NULL, addition) != 0) { - return -1; - } - - tdb->transaction->need_repack = true; - - return 0; -} - -static const struct tdb_methods transaction_methods = { - transaction_read, - transaction_write, - transaction_next_hash_chain, - transaction_oob, - transaction_expand_file, -}; - - -/* - start a tdb transaction. No token is returned, as only a single - transaction is allowed to be pending per tdb_context -*/ -static int _tdb_transaction_start(struct tdb_context *tdb, - enum tdb_lock_flags lockflags) -{ - /* some sanity checks */ - if (tdb->read_only || (tdb->flags & TDB_INTERNAL) || tdb->traverse_read) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: cannot start a transaction on a read-only or internal db\n")); - tdb->ecode = TDB_ERR_EINVAL; - return -1; - } - - /* cope with nested tdb_transaction_start() calls */ - if (tdb->transaction != NULL) { - if (!(tdb->flags & TDB_ALLOW_NESTING)) { - tdb->ecode = TDB_ERR_NESTING; - return -1; - } - tdb->transaction->nesting++; - TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_start: nesting %d\n", - tdb->transaction->nesting)); - return 0; - } - - if (tdb_have_extra_locks(tdb)) { - /* the caller must not have any locks when starting a - transaction as otherwise we'll be screwed by lack - of nested locks in posix */ - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: cannot start a transaction with locks held\n")); - tdb->ecode = TDB_ERR_LOCK; - return -1; - } - - if (tdb->travlocks.next != NULL) { - /* you cannot use transactions inside a traverse (although you can use - traverse inside a transaction) as otherwise you can end up with - deadlock */ - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: cannot start a transaction within a traverse\n")); - tdb->ecode = TDB_ERR_LOCK; - return -1; - } - - tdb->transaction = (struct tdb_transaction *) - calloc(sizeof(struct tdb_transaction), 1); - if (tdb->transaction == NULL) { - tdb->ecode = TDB_ERR_OOM; - return -1; - } - - /* a page at a time seems like a reasonable compromise between compactness and efficiency */ - tdb->transaction->block_size = tdb->page_size; - - /* get the transaction write lock. This is a blocking lock. As - discussed with Volker, there are a number of ways we could - make this async, which we will probably do in the future */ - if (tdb_transaction_lock(tdb, F_WRLCK, lockflags) == -1) { - SAFE_FREE(tdb->transaction->blocks); - SAFE_FREE(tdb->transaction); - if ((lockflags & TDB_LOCK_WAIT) == 0) { - tdb->ecode = TDB_ERR_NOLOCK; - } - return -1; - } - - /* get a read lock from the freelist to the end of file. This - is upgraded to a write lock during the commit */ - if (tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, true) == -1) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to get hash locks\n")); - goto fail_allrecord_lock; - } - - /* setup a copy of the hash table heads so the hash scan in - traverse can be fast */ - tdb->transaction->hash_heads = (uint32_t *) - calloc(tdb->header.hash_size+1, sizeof(uint32_t)); - if (tdb->transaction->hash_heads == NULL) { - tdb->ecode = TDB_ERR_OOM; - goto fail; - } - if (tdb->methods->tdb_read(tdb, FREELIST_TOP, tdb->transaction->hash_heads, - TDB_HASHTABLE_SIZE(tdb), 0) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_start: failed to read hash heads\n")); - tdb->ecode = TDB_ERR_IO; - goto fail; - } - - /* make sure we know about any file expansions already done by - anyone else */ - tdb->methods->tdb_oob(tdb, tdb->map_size + 1, 1); - tdb->transaction->old_map_size = tdb->map_size; - - /* finally hook the io methods, replacing them with - transaction specific methods */ - tdb->transaction->io_methods = tdb->methods; - tdb->methods = &transaction_methods; - - /* Trace at the end, so we get sequence number correct. */ - tdb_trace(tdb, "tdb_transaction_start"); - return 0; - -fail: - tdb_allrecord_unlock(tdb, F_RDLCK, false); -fail_allrecord_lock: - tdb_transaction_unlock(tdb, F_WRLCK); - SAFE_FREE(tdb->transaction->blocks); - SAFE_FREE(tdb->transaction->hash_heads); - SAFE_FREE(tdb->transaction); - return -1; -} - -int tdb_transaction_start(struct tdb_context *tdb) -{ - return _tdb_transaction_start(tdb, TDB_LOCK_WAIT); -} - -int tdb_transaction_start_nonblock(struct tdb_context *tdb) -{ - return _tdb_transaction_start(tdb, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE); -} - -/* - sync to disk -*/ -static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t length) -{ - if (tdb->flags & TDB_NOSYNC) { - return 0; - } - -#ifdef HAVE_FDATASYNC - if (fdatasync(tdb->fd) != 0) { -#else - if (fsync(tdb->fd) != 0) { -#endif - tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: fsync failed\n")); - return -1; - } -#ifdef HAVE_MMAP - if (tdb->map_ptr) { - tdb_off_t moffset = offset & ~(tdb->page_size-1); - if (msync(moffset + (char *)tdb->map_ptr, - length + (offset - moffset), MS_SYNC) != 0) { - tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction: msync failed - %s\n", - strerror(errno))); - return -1; - } - } -#endif - return 0; -} - - -static int _tdb_transaction_cancel(struct tdb_context *tdb) -{ - int i, ret = 0; - - if (tdb->transaction == NULL) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_cancel: no transaction\n")); - return -1; - } - - if (tdb->transaction->nesting != 0) { - tdb->transaction->transaction_error = 1; - tdb->transaction->nesting--; - return 0; - } - - tdb->map_size = tdb->transaction->old_map_size; - - /* free all the transaction blocks */ - for (i=0;itransaction->num_blocks;i++) { - if (tdb->transaction->blocks[i] != NULL) { - free(tdb->transaction->blocks[i]); - } - } - SAFE_FREE(tdb->transaction->blocks); - - if (tdb->transaction->magic_offset) { - const struct tdb_methods *methods = tdb->transaction->io_methods; - const uint32_t invalid = TDB_RECOVERY_INVALID_MAGIC; - - /* remove the recovery marker */ - if (methods->tdb_write(tdb, tdb->transaction->magic_offset, &invalid, 4) == -1 || - transaction_sync(tdb, tdb->transaction->magic_offset, 4) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_cancel: failed to remove recovery magic\n")); - ret = -1; - } - } - - /* This also removes the OPEN_LOCK, if we have it. */ - tdb_release_transaction_locks(tdb); - - /* restore the normal io methods */ - tdb->methods = tdb->transaction->io_methods; - - SAFE_FREE(tdb->transaction->hash_heads); - SAFE_FREE(tdb->transaction); - - return ret; -} - -/* - cancel the current transaction -*/ -int tdb_transaction_cancel(struct tdb_context *tdb) -{ - tdb_trace(tdb, "tdb_transaction_cancel"); - return _tdb_transaction_cancel(tdb); -} - -/* - work out how much space the linearised recovery data will consume -*/ -static tdb_len_t tdb_recovery_size(struct tdb_context *tdb) -{ - tdb_len_t recovery_size = 0; - int i; - - recovery_size = sizeof(uint32_t); - for (i=0;itransaction->num_blocks;i++) { - if (i * tdb->transaction->block_size >= tdb->transaction->old_map_size) { - break; - } - if (tdb->transaction->blocks[i] == NULL) { - continue; - } - recovery_size += 2*sizeof(tdb_off_t); - if (i == tdb->transaction->num_blocks-1) { - recovery_size += tdb->transaction->last_block_size; - } else { - recovery_size += tdb->transaction->block_size; - } - } - - return recovery_size; -} - -/* - allocate the recovery area, or use an existing recovery area if it is - large enough -*/ -static int tdb_recovery_allocate(struct tdb_context *tdb, - tdb_len_t *recovery_size, - tdb_off_t *recovery_offset, - tdb_len_t *recovery_max_size) -{ - struct tdb_record rec; - const struct tdb_methods *methods = tdb->transaction->io_methods; - tdb_off_t recovery_head; - - if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to read recovery head\n")); - return -1; - } - - rec.rec_len = 0; - - if (recovery_head != 0) { - if (methods->tdb_read(tdb, recovery_head, &rec, sizeof(rec), DOCONV()) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to read recovery record\n")); - return -1; - } - /* ignore invalid recovery regions: can happen in crash */ - if (rec.magic != TDB_RECOVERY_MAGIC && - rec.magic != TDB_RECOVERY_INVALID_MAGIC) { - recovery_head = 0; - } - } - - *recovery_size = tdb_recovery_size(tdb); - - if (recovery_head != 0 && *recovery_size <= rec.rec_len) { - /* it fits in the existing area */ - *recovery_max_size = rec.rec_len; - *recovery_offset = recovery_head; - return 0; - } - - /* we need to free up the old recovery area, then allocate a - new one at the end of the file. Note that we cannot use - tdb_allocate() to allocate the new one as that might return - us an area that is being currently used (as of the start of - the transaction) */ - if (recovery_head != 0) { - if (tdb_free(tdb, recovery_head, &rec) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to free previous recovery area\n")); - return -1; - } - } - - /* the tdb_free() call might have increased the recovery size */ - *recovery_size = tdb_recovery_size(tdb); - - /* round up to a multiple of page size */ - *recovery_max_size = TDB_ALIGN(sizeof(rec) + *recovery_size, tdb->page_size) - sizeof(rec); - *recovery_offset = tdb->map_size; - recovery_head = *recovery_offset; - - if (methods->tdb_expand_file(tdb, tdb->transaction->old_map_size, - (tdb->map_size - tdb->transaction->old_map_size) + - sizeof(rec) + *recovery_max_size) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to create recovery area\n")); - return -1; - } - - /* remap the file (if using mmap) */ - methods->tdb_oob(tdb, tdb->map_size + 1, 1); - - /* we have to reset the old map size so that we don't try to expand the file - again in the transaction commit, which would destroy the recovery area */ - tdb->transaction->old_map_size = tdb->map_size; - - /* write the recovery header offset and sync - we can sync without a race here - as the magic ptr in the recovery record has not been set */ - CONVERT(recovery_head); - if (methods->tdb_write(tdb, TDB_RECOVERY_HEAD, - &recovery_head, sizeof(tdb_off_t)) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to write recovery head\n")); - return -1; - } - if (transaction_write_existing(tdb, TDB_RECOVERY_HEAD, &recovery_head, sizeof(tdb_off_t)) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_recovery_allocate: failed to write recovery head\n")); - return -1; - } - - return 0; -} - - -/* - setup the recovery data that will be used on a crash during commit -*/ -static int transaction_setup_recovery(struct tdb_context *tdb, - tdb_off_t *magic_offset) -{ - tdb_len_t recovery_size; - unsigned char *data, *p; - const struct tdb_methods *methods = tdb->transaction->io_methods; - struct tdb_record *rec; - tdb_off_t recovery_offset, recovery_max_size; - tdb_off_t old_map_size = tdb->transaction->old_map_size; - uint32_t magic, tailer; - int i; - - /* - check that the recovery area has enough space - */ - if (tdb_recovery_allocate(tdb, &recovery_size, - &recovery_offset, &recovery_max_size) == -1) { - return -1; - } - - data = (unsigned char *)malloc(recovery_size + sizeof(*rec)); - if (data == NULL) { - tdb->ecode = TDB_ERR_OOM; - return -1; - } - - rec = (struct tdb_record *)data; - memset(rec, 0, sizeof(*rec)); - - rec->magic = TDB_RECOVERY_INVALID_MAGIC; - rec->data_len = recovery_size; - rec->rec_len = recovery_max_size; - rec->key_len = old_map_size; - CONVERT(rec); - - /* build the recovery data into a single blob to allow us to do a single - large write, which should be more efficient */ - p = data + sizeof(*rec); - for (i=0;itransaction->num_blocks;i++) { - tdb_off_t offset; - tdb_len_t length; - - if (tdb->transaction->blocks[i] == NULL) { - continue; - } - - offset = i * tdb->transaction->block_size; - length = tdb->transaction->block_size; - if (i == tdb->transaction->num_blocks-1) { - length = tdb->transaction->last_block_size; - } - - if (offset >= old_map_size) { - continue; - } - if (offset + length > tdb->transaction->old_map_size) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: transaction data over new region boundary\n")); - free(data); - tdb->ecode = TDB_ERR_CORRUPT; - return -1; - } - memcpy(p, &offset, 4); - memcpy(p+4, &length, 4); - if (DOCONV()) { - tdb_convert(p, 8); - } - /* the recovery area contains the old data, not the - new data, so we have to call the original tdb_read - method to get it */ - if (methods->tdb_read(tdb, offset, p + 8, length, 0) != 0) { - free(data); - tdb->ecode = TDB_ERR_IO; - return -1; - } - p += 8 + length; - } - - /* and the tailer */ - tailer = sizeof(*rec) + recovery_max_size; - memcpy(p, &tailer, 4); - CONVERT(p); - - /* write the recovery data to the recovery area */ - if (methods->tdb_write(tdb, recovery_offset, data, sizeof(*rec) + recovery_size) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write recovery data\n")); - free(data); - tdb->ecode = TDB_ERR_IO; - return -1; - } - if (transaction_write_existing(tdb, recovery_offset, data, sizeof(*rec) + recovery_size) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write secondary recovery data\n")); - free(data); - tdb->ecode = TDB_ERR_IO; - return -1; - } - - /* as we don't have ordered writes, we have to sync the recovery - data before we update the magic to indicate that the recovery - data is present */ - if (transaction_sync(tdb, recovery_offset, sizeof(*rec) + recovery_size) == -1) { - free(data); - return -1; - } - - free(data); - - magic = TDB_RECOVERY_MAGIC; - CONVERT(magic); - - *magic_offset = recovery_offset + offsetof(struct tdb_record, magic); - - if (methods->tdb_write(tdb, *magic_offset, &magic, sizeof(magic)) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write recovery magic\n")); - tdb->ecode = TDB_ERR_IO; - return -1; - } - if (transaction_write_existing(tdb, *magic_offset, &magic, sizeof(magic)) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write secondary recovery magic\n")); - tdb->ecode = TDB_ERR_IO; - return -1; - } - - /* ensure the recovery magic marker is on disk */ - if (transaction_sync(tdb, *magic_offset, sizeof(magic)) == -1) { - return -1; - } - - return 0; -} - -static int _tdb_transaction_prepare_commit(struct tdb_context *tdb) -{ - const struct tdb_methods *methods; - - if (tdb->transaction == NULL) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: no transaction\n")); - return -1; - } - - if (tdb->transaction->prepared) { - tdb->ecode = TDB_ERR_EINVAL; - _tdb_transaction_cancel(tdb); - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: transaction already prepared\n")); - return -1; - } - - if (tdb->transaction->transaction_error) { - tdb->ecode = TDB_ERR_IO; - _tdb_transaction_cancel(tdb); - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: transaction error pending\n")); - return -1; - } - - - if (tdb->transaction->nesting != 0) { - return 0; - } - - /* check for a null transaction */ - if (tdb->transaction->blocks == NULL) { - return 0; - } - - methods = tdb->transaction->io_methods; - - /* if there are any locks pending then the caller has not - nested their locks properly, so fail the transaction */ - if (tdb_have_extra_locks(tdb)) { - tdb->ecode = TDB_ERR_LOCK; - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: locks pending on commit\n")); - _tdb_transaction_cancel(tdb); - return -1; - } - - /* upgrade the main transaction lock region to a write lock */ - if (tdb_allrecord_upgrade(tdb) == -1) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: failed to upgrade hash locks\n")); - _tdb_transaction_cancel(tdb); - return -1; - } - - /* get the open lock - this prevents new users attaching to the database - during the commit */ - if (tdb_nest_lock(tdb, OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: failed to get open lock\n")); - _tdb_transaction_cancel(tdb); - return -1; - } - - if (!(tdb->flags & TDB_NOSYNC)) { - /* write the recovery data to the end of the file */ - if (transaction_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_prepare_commit: failed to setup recovery data\n")); - _tdb_transaction_cancel(tdb); - return -1; - } - } - - tdb->transaction->prepared = true; - - /* expand the file to the new size if needed */ - if (tdb->map_size != tdb->transaction->old_map_size) { - if (methods->tdb_expand_file(tdb, tdb->transaction->old_map_size, - tdb->map_size - - tdb->transaction->old_map_size) == -1) { - tdb->ecode = TDB_ERR_IO; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_prepare_commit: expansion failed\n")); - _tdb_transaction_cancel(tdb); - return -1; - } - tdb->map_size = tdb->transaction->old_map_size; - methods->tdb_oob(tdb, tdb->map_size + 1, 1); - } - - /* Keep the open lock until the actual commit */ - - return 0; -} - -/* - prepare to commit the current transaction -*/ -int tdb_transaction_prepare_commit(struct tdb_context *tdb) -{ - tdb_trace(tdb, "tdb_transaction_prepare_commit"); - return _tdb_transaction_prepare_commit(tdb); -} - -/* - commit the current transaction -*/ -int tdb_transaction_commit(struct tdb_context *tdb) -{ - const struct tdb_methods *methods; - int i; - bool need_repack; - - if (tdb->transaction == NULL) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: no transaction\n")); - return -1; - } - - tdb_trace(tdb, "tdb_transaction_commit"); - - if (tdb->transaction->transaction_error) { - tdb->ecode = TDB_ERR_IO; - _tdb_transaction_cancel(tdb); - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: transaction error pending\n")); - return -1; - } - - - if (tdb->transaction->nesting != 0) { - tdb->transaction->nesting--; - return 0; - } - - /* check for a null transaction */ - if (tdb->transaction->blocks == NULL) { - _tdb_transaction_cancel(tdb); - return 0; - } - - if (!tdb->transaction->prepared) { - int ret = _tdb_transaction_prepare_commit(tdb); - if (ret) - return ret; - } - - methods = tdb->transaction->io_methods; - - /* perform all the writes */ - for (i=0;itransaction->num_blocks;i++) { - tdb_off_t offset; - tdb_len_t length; - - if (tdb->transaction->blocks[i] == NULL) { - continue; - } - - offset = i * tdb->transaction->block_size; - length = tdb->transaction->block_size; - if (i == tdb->transaction->num_blocks-1) { - length = tdb->transaction->last_block_size; - } - - if (methods->tdb_write(tdb, offset, tdb->transaction->blocks[i], length) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: write failed during commit\n")); - - /* we've overwritten part of the data and - possibly expanded the file, so we need to - run the crash recovery code */ - tdb->methods = methods; - tdb_transaction_recover(tdb); - - _tdb_transaction_cancel(tdb); - - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_commit: write failed\n")); - return -1; - } - SAFE_FREE(tdb->transaction->blocks[i]); - } - - SAFE_FREE(tdb->transaction->blocks); - tdb->transaction->num_blocks = 0; - - /* ensure the new data is on disk */ - if (transaction_sync(tdb, 0, tdb->map_size) == -1) { - return -1; - } - - /* - TODO: maybe write to some dummy hdr field, or write to magic - offset without mmap, before the last sync, instead of the - utime() call - */ - - /* on some systems (like Linux 2.6.x) changes via mmap/msync - don't change the mtime of the file, this means the file may - not be backed up (as tdb rounding to block sizes means that - file size changes are quite rare too). The following forces - mtime changes when a transaction completes */ -#ifdef HAVE_UTIME - utime(tdb->name, NULL); -#endif - - need_repack = tdb->transaction->need_repack; - - /* use a transaction cancel to free memory and remove the - transaction locks */ - _tdb_transaction_cancel(tdb); - - if (need_repack) { - return tdb_repack(tdb); - } - - return 0; -} - - -/* - recover from an aborted transaction. Must be called with exclusive - database write access already established (including the open - lock to prevent new processes attaching) -*/ -int tdb_transaction_recover(struct tdb_context *tdb) -{ - tdb_off_t recovery_head, recovery_eof; - unsigned char *data, *p; - uint32_t zero = 0; - struct tdb_record rec; - - /* find the recovery area */ - if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery head\n")); - tdb->ecode = TDB_ERR_IO; - return -1; - } - - if (recovery_head == 0) { - /* we have never allocated a recovery record */ - return 0; - } - - /* read the recovery record */ - if (tdb->methods->tdb_read(tdb, recovery_head, &rec, - sizeof(rec), DOCONV()) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery record\n")); - tdb->ecode = TDB_ERR_IO; - return -1; - } - - if (rec.magic != TDB_RECOVERY_MAGIC) { - /* there is no valid recovery data */ - return 0; - } - - if (tdb->read_only) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: attempt to recover read only database\n")); - tdb->ecode = TDB_ERR_CORRUPT; - return -1; - } - - recovery_eof = rec.key_len; - - data = (unsigned char *)malloc(rec.data_len); - if (data == NULL) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to allocate recovery data\n")); - tdb->ecode = TDB_ERR_OOM; - return -1; - } - - /* read the full recovery data */ - if (tdb->methods->tdb_read(tdb, recovery_head + sizeof(rec), data, - rec.data_len, 0) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to read recovery data\n")); - tdb->ecode = TDB_ERR_IO; - return -1; - } - - /* recover the file data */ - p = data; - while (p+8 < data + rec.data_len) { - uint32_t ofs, len; - if (DOCONV()) { - tdb_convert(p, 8); - } - memcpy(&ofs, p, 4); - memcpy(&len, p+4, 4); - - if (tdb->methods->tdb_write(tdb, ofs, p+8, len) == -1) { - free(data); - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to recover %d bytes at offset %d\n", len, ofs)); - tdb->ecode = TDB_ERR_IO; - return -1; - } - p += 8 + len; - } - - free(data); - - if (transaction_sync(tdb, 0, tdb->map_size) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to sync recovery\n")); - tdb->ecode = TDB_ERR_IO; - return -1; - } - - /* if the recovery area is after the recovered eof then remove it */ - if (recovery_eof <= recovery_head) { - if (tdb_ofs_write(tdb, TDB_RECOVERY_HEAD, &zero) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to remove recovery head\n")); - tdb->ecode = TDB_ERR_IO; - return -1; - } - } - - /* remove the recovery magic */ - if (tdb_ofs_write(tdb, recovery_head + offsetof(struct tdb_record, magic), - &zero) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to remove recovery magic\n")); - tdb->ecode = TDB_ERR_IO; - return -1; - } - - if (transaction_sync(tdb, 0, recovery_eof) == -1) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to sync2 recovery\n")); - tdb->ecode = TDB_ERR_IO; - return -1; - } - - TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_transaction_recover: recovered %d byte database\n", - recovery_eof)); - - /* all done */ - return 0; -} - -/* Any I/O failures we say "needs recovery". */ -bool tdb_needs_recovery(struct tdb_context *tdb) -{ - tdb_off_t recovery_head; - struct tdb_record rec; - - /* find the recovery area */ - if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) { - return true; - } - - if (recovery_head == 0) { - /* we have never allocated a recovery record */ - return false; - } - - /* read the recovery record */ - if (tdb->methods->tdb_read(tdb, recovery_head, &rec, - sizeof(rec), DOCONV()) == -1) { - return true; - } - - return (rec.magic == TDB_RECOVERY_MAGIC); -} diff --git a/bundled/tdb/common/traverse.c b/bundled/tdb/common/traverse.c deleted file mode 100644 index d77086a7..00000000 --- a/bundled/tdb/common/traverse.c +++ /dev/null @@ -1,366 +0,0 @@ - /* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Andrew Tridgell 1999-2005 - Copyright (C) Paul `Rusty' Russell 2000 - Copyright (C) Jeremy Allison 2000-2003 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "tdb_private.h" - -#define TDB_NEXT_LOCK_ERR ((tdb_off_t)-1) - -/* Uses traverse lock: 0 = finish, TDB_NEXT_LOCK_ERR = error, - other = record offset */ -static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock *tlock, - struct tdb_record *rec) -{ - int want_next = (tlock->off != 0); - - /* Lock each chain from the start one. */ - for (; tlock->hash < tdb->header.hash_size; tlock->hash++) { - if (!tlock->off && tlock->hash != 0) { - /* this is an optimisation for the common case where - the hash chain is empty, which is particularly - common for the use of tdb with ldb, where large - hashes are used. In that case we spend most of our - time in tdb_brlock(), locking empty hash chains. - - To avoid this, we do an unlocked pre-check to see - if the hash chain is empty before starting to look - inside it. If it is empty then we can avoid that - hash chain. If it isn't empty then we can't believe - the value we get back, as we read it without a - lock, so instead we get the lock and re-fetch the - value below. - - Notice that not doing this optimisation on the - first hash chain is critical. We must guarantee - that we have done at least one fcntl lock at the - start of a search to guarantee that memory is - coherent on SMP systems. If records are added by - others during the search then thats OK, and we - could possibly miss those with this trick, but we - could miss them anyway without this trick, so the - semantics don't change. - - With a non-indexed ldb search this trick gains us a - factor of around 80 in speed on a linux 2.6.x - system (testing using ldbtest). - */ - tdb->methods->next_hash_chain(tdb, &tlock->hash); - if (tlock->hash == tdb->header.hash_size) { - continue; - } - } - - if (tdb_lock(tdb, tlock->hash, tlock->lock_rw) == -1) - return TDB_NEXT_LOCK_ERR; - - /* No previous record? Start at top of chain. */ - if (!tlock->off) { - if (tdb_ofs_read(tdb, TDB_HASH_TOP(tlock->hash), - &tlock->off) == -1) - goto fail; - } else { - /* Otherwise unlock the previous record. */ - if (tdb_unlock_record(tdb, tlock->off) != 0) - goto fail; - } - - if (want_next) { - /* We have offset of old record: grab next */ - if (tdb_rec_read(tdb, tlock->off, rec) == -1) - goto fail; - tlock->off = rec->next; - } - - /* Iterate through chain */ - while( tlock->off) { - tdb_off_t current; - if (tdb_rec_read(tdb, tlock->off, rec) == -1) - goto fail; - - /* Detect infinite loops. From "Shlomi Yaakobovich" . */ - if (tlock->off == rec->next) { - tdb->ecode = TDB_ERR_CORRUPT; - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_next_lock: loop detected.\n")); - goto fail; - } - - if (!TDB_DEAD(rec)) { - /* Woohoo: we found one! */ - if (tdb_lock_record(tdb, tlock->off) != 0) - goto fail; - return tlock->off; - } - - /* Try to clean dead ones from old traverses */ - current = tlock->off; - tlock->off = rec->next; - if (!(tdb->read_only || tdb->traverse_read) && - tdb_do_delete(tdb, current, rec) != 0) - goto fail; - } - tdb_unlock(tdb, tlock->hash, tlock->lock_rw); - want_next = 0; - } - /* We finished iteration without finding anything */ - tdb->ecode = TDB_SUCCESS; - return 0; - - fail: - tlock->off = 0; - if (tdb_unlock(tdb, tlock->hash, tlock->lock_rw) != 0) - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_next_lock: On error unlock failed!\n")); - return TDB_NEXT_LOCK_ERR; -} - -/* traverse the entire database - calling fn(tdb, key, data) on each element. - return -1 on error or the record count traversed - if fn is NULL then it is not called - a non-zero return value from fn() indicates that the traversal should stop - */ -static int tdb_traverse_internal(struct tdb_context *tdb, - tdb_traverse_func fn, void *private_data, - struct tdb_traverse_lock *tl) -{ - TDB_DATA key, dbuf; - struct tdb_record rec; - int ret = 0, count = 0; - tdb_off_t off; - - /* This was in the initializaton, above, but the IRIX compiler - * did not like it. crh - */ - tl->next = tdb->travlocks.next; - - /* fcntl locks don't stack: beware traverse inside traverse */ - tdb->travlocks.next = tl; - - /* tdb_next_lock places locks on the record returned, and its chain */ - while ((off = tdb_next_lock(tdb, tl, &rec)) != 0) { - if (off == TDB_NEXT_LOCK_ERR) { - ret = -1; - goto out; - } - count++; - /* now read the full record */ - key.dptr = tdb_alloc_read(tdb, tl->off + sizeof(rec), - rec.key_len + rec.data_len); - if (!key.dptr) { - ret = -1; - if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0) - goto out; - if (tdb_unlock_record(tdb, tl->off) != 0) - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_traverse: key.dptr == NULL and unlock_record failed!\n")); - goto out; - } - key.dsize = rec.key_len; - dbuf.dptr = key.dptr + rec.key_len; - dbuf.dsize = rec.data_len; - - tdb_trace_1rec_retrec(tdb, "traverse", key, dbuf); - - /* Drop chain lock, call out */ - if (tdb_unlock(tdb, tl->hash, tl->lock_rw) != 0) { - ret = -1; - SAFE_FREE(key.dptr); - goto out; - } - if (fn && fn(tdb, key, dbuf, private_data)) { - /* They want us to terminate traversal */ - tdb_trace_ret(tdb, "tdb_traverse_end", count); - if (tdb_unlock_record(tdb, tl->off) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_traverse: unlock_record failed!\n"));; - ret = -1; - } - SAFE_FREE(key.dptr); - goto out; - } - SAFE_FREE(key.dptr); - } - tdb_trace(tdb, "tdb_traverse_end"); -out: - tdb->travlocks.next = tl->next; - if (ret < 0) - return -1; - else - return count; -} - - -/* - a write style traverse - temporarily marks the db read only -*/ -int tdb_traverse_read(struct tdb_context *tdb, - tdb_traverse_func fn, void *private_data) -{ - struct tdb_traverse_lock tl = { NULL, 0, 0, F_RDLCK }; - int ret; - - /* we need to get a read lock on the transaction lock here to - cope with the lock ordering semantics of solaris10 */ - if (tdb_transaction_lock(tdb, F_RDLCK, TDB_LOCK_WAIT)) { - return -1; - } - - tdb->traverse_read++; - tdb_trace(tdb, "tdb_traverse_read_start"); - ret = tdb_traverse_internal(tdb, fn, private_data, &tl); - tdb->traverse_read--; - - tdb_transaction_unlock(tdb, F_RDLCK); - - return ret; -} - -/* - a write style traverse - needs to get the transaction lock to - prevent deadlocks - - WARNING: The data buffer given to the callback fn does NOT meet the - alignment restrictions malloc gives you. -*/ -int tdb_traverse(struct tdb_context *tdb, - tdb_traverse_func fn, void *private_data) -{ - struct tdb_traverse_lock tl = { NULL, 0, 0, F_WRLCK }; - int ret; - - if (tdb->read_only || tdb->traverse_read) { - return tdb_traverse_read(tdb, fn, private_data); - } - - if (tdb_transaction_lock(tdb, F_WRLCK, TDB_LOCK_WAIT)) { - return -1; - } - - tdb->traverse_write++; - tdb_trace(tdb, "tdb_traverse_start"); - ret = tdb_traverse_internal(tdb, fn, private_data, &tl); - tdb->traverse_write--; - - tdb_transaction_unlock(tdb, F_WRLCK); - - return ret; -} - - -/* find the first entry in the database and return its key */ -TDB_DATA tdb_firstkey(struct tdb_context *tdb) -{ - TDB_DATA key; - struct tdb_record rec; - tdb_off_t off; - - /* release any old lock */ - if (tdb_unlock_record(tdb, tdb->travlocks.off) != 0) - return tdb_null; - tdb->travlocks.off = tdb->travlocks.hash = 0; - tdb->travlocks.lock_rw = F_RDLCK; - - /* Grab first record: locks chain and returned record. */ - off = tdb_next_lock(tdb, &tdb->travlocks, &rec); - if (off == 0 || off == TDB_NEXT_LOCK_ERR) { - tdb_trace_retrec(tdb, "tdb_firstkey", tdb_null); - return tdb_null; - } - /* now read the key */ - key.dsize = rec.key_len; - key.dptr =tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec),key.dsize); - - tdb_trace_retrec(tdb, "tdb_firstkey", key); - - /* Unlock the hash chain of the record we just read. */ - if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0) - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_firstkey: error occurred while tdb_unlocking!\n")); - return key; -} - -/* find the next entry in the database, returning its key */ -TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA oldkey) -{ - uint32_t oldhash; - TDB_DATA key = tdb_null; - struct tdb_record rec; - unsigned char *k = NULL; - tdb_off_t off; - - /* Is locked key the old key? If so, traverse will be reliable. */ - if (tdb->travlocks.off) { - if (tdb_lock(tdb,tdb->travlocks.hash,tdb->travlocks.lock_rw)) - return tdb_null; - if (tdb_rec_read(tdb, tdb->travlocks.off, &rec) == -1 - || !(k = tdb_alloc_read(tdb,tdb->travlocks.off+sizeof(rec), - rec.key_len)) - || memcmp(k, oldkey.dptr, oldkey.dsize) != 0) { - /* No, it wasn't: unlock it and start from scratch */ - if (tdb_unlock_record(tdb, tdb->travlocks.off) != 0) { - tdb_trace_1rec_retrec(tdb, "tdb_nextkey", - oldkey, tdb_null); - SAFE_FREE(k); - return tdb_null; - } - if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0) { - SAFE_FREE(k); - return tdb_null; - } - tdb->travlocks.off = 0; - } - - SAFE_FREE(k); - } - - if (!tdb->travlocks.off) { - /* No previous element: do normal find, and lock record */ - tdb->travlocks.off = tdb_find_lock_hash(tdb, oldkey, tdb->hash_fn(&oldkey), tdb->travlocks.lock_rw, &rec); - if (!tdb->travlocks.off) { - tdb_trace_1rec_retrec(tdb, "tdb_nextkey", oldkey, tdb_null); - return tdb_null; - } - tdb->travlocks.hash = BUCKET(rec.full_hash); - if (tdb_lock_record(tdb, tdb->travlocks.off) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_nextkey: lock_record failed (%s)!\n", strerror(errno))); - return tdb_null; - } - } - oldhash = tdb->travlocks.hash; - - /* Grab next record: locks chain and returned record, - unlocks old record */ - off = tdb_next_lock(tdb, &tdb->travlocks, &rec); - if (off != TDB_NEXT_LOCK_ERR && off != 0) { - key.dsize = rec.key_len; - key.dptr = tdb_alloc_read(tdb, tdb->travlocks.off+sizeof(rec), - key.dsize); - /* Unlock the chain of this new record */ - if (tdb_unlock(tdb, tdb->travlocks.hash, tdb->travlocks.lock_rw) != 0) - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_nextkey: WARNING tdb_unlock failed!\n")); - } - /* Unlock the chain of old record */ - if (tdb_unlock(tdb, BUCKET(oldhash), tdb->travlocks.lock_rw) != 0) - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_nextkey: WARNING tdb_unlock failed!\n")); - tdb_trace_1rec_retrec(tdb, "tdb_nextkey", oldkey, key); - return key; -} - diff --git a/bundled/tdb/config.guess b/bundled/tdb/config.guess deleted file mode 100755 index da833146..00000000 --- a/bundled/tdb/config.guess +++ /dev/null @@ -1,1561 +0,0 @@ -#! /bin/sh -# Attempt to guess a canonical system name. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 -# Free Software Foundation, Inc. - -timestamp='2009-04-27' - -# This file is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Originally written by Per Bothner . -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. -# -# This script attempts to guess a canonical system name similar to -# config.sub. If it succeeds, it prints the system name on stdout, and -# exits with 0. Otherwise, it exits with 1. -# -# The plan is that this can be called by configure scripts if you -# don't specify an explicit build system type. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] - -Output the configuration name of the system \`$me' is run on. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.guess ($timestamp) - -Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" >&2 - exit 1 ;; - * ) - break ;; - esac -done - -if test $# != 0; then - echo "$me: too many arguments$help" >&2 - exit 1 -fi - -trap 'exit 1' 1 2 15 - -# CC_FOR_BUILD -- compiler used by this script. Note that the use of a -# compiler to aid in system detection is discouraged as it requires -# temporary files to be created and, as you can see below, it is a -# headache to deal with in a portable fashion. - -# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still -# use `HOST_CC' if defined, but it is deprecated. - -# Portable tmp directory creation inspired by the Autoconf team. - -set_cc_for_build=' -trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; -trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; -: ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; -dummy=$tmp/dummy ; -tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; -case $CC_FOR_BUILD,$HOST_CC,$CC in - ,,) echo "int x;" > $dummy.c ; - for c in cc gcc c89 c99 ; do - if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then - CC_FOR_BUILD="$c"; break ; - fi ; - done ; - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found ; - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; set_cc_for_build= ;' - -# This is needed to find uname on a Pyramid OSx when run in the BSD universe. -# (ghazi@noc.rutgers.edu 1994-08-24) -if (test -f /.attbin/uname) >/dev/null 2>&1 ; then - PATH=$PATH:/.attbin ; export PATH -fi - -UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown -UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown -UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown - -# Note: order is significant - the case branches are not exclusive. - -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in - *:NetBSD:*:*) - # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, - # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently - # switched to ELF, *-*-netbsd* would select the old - # object file format. This provides both forward - # compatibility and a consistent mechanism for selecting the - # object file format. - # - # Note: NetBSD doesn't particularly care about the vendor - # portion of the name. We always set it to "unknown". - sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || echo unknown)` - case "${UNAME_MACHINE_ARCH}" in - armeb) machine=armeb-unknown ;; - arm*) machine=arm-unknown ;; - sh3el) machine=shl-unknown ;; - sh3eb) machine=sh-unknown ;; - sh5el) machine=sh5le-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-unknown ;; - esac - # The Operating System including object format, if it has switched - # to ELF recently, or will in the future. - case "${UNAME_MACHINE_ARCH}" in - arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build - if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep __ELF__ >/dev/null - then - # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). - # Return netbsd for either. FIX? - os=netbsd - else - os=netbsdelf - fi - ;; - *) - os=netbsd - ;; - esac - # The OS release - # Debian GNU/NetBSD machines have a different userland, and - # thus, need a distinct triplet. However, they do not need - # kernel version information, so it can be replaced with a - # suitable tag, in the style of linux-gnu. - case "${UNAME_VERSION}" in - Debian*) - release='-gnu' - ;; - *) - release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` - ;; - esac - # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: - # contains redundant information, the shorter form: - # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}" - exit ;; - *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} - exit ;; - *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} - exit ;; - *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE} - exit ;; - macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd${UNAME_RELEASE} - exit ;; - *:MirBSD:*:*) - echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} - exit ;; - alpha:OSF1:*:*) - case $UNAME_RELEASE in - *4.0) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - ;; - *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` - ;; - esac - # According to Compaq, /usr/sbin/psrinfo has been available on - # OSF/1 and Tru64 systems produced since 1995. I hope that - # covers most systems running today. This code pipes the CPU - # types through head -n 1, so we only detect the type of CPU 0. - ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` - case "$ALPHA_CPU_TYPE" in - "EV4 (21064)") - UNAME_MACHINE="alpha" ;; - "EV4.5 (21064)") - UNAME_MACHINE="alpha" ;; - "LCA4 (21066/21068)") - UNAME_MACHINE="alpha" ;; - "EV5 (21164)") - UNAME_MACHINE="alphaev5" ;; - "EV5.6 (21164A)") - UNAME_MACHINE="alphaev56" ;; - "EV5.6 (21164PC)") - UNAME_MACHINE="alphapca56" ;; - "EV5.7 (21164PC)") - UNAME_MACHINE="alphapca57" ;; - "EV6 (21264)") - UNAME_MACHINE="alphaev6" ;; - "EV6.7 (21264A)") - UNAME_MACHINE="alphaev67" ;; - "EV6.8CB (21264C)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8AL (21264B)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8CX (21264D)") - UNAME_MACHINE="alphaev68" ;; - "EV6.9A (21264/EV69A)") - UNAME_MACHINE="alphaev69" ;; - "EV7 (21364)") - UNAME_MACHINE="alphaev7" ;; - "EV7.9 (21364A)") - UNAME_MACHINE="alphaev79" ;; - esac - # A Pn.n version is a patched version. - # A Vn.n version is a released version. - # A Tn.n version is a released field test version. - # A Xn.n version is an unreleased experimental baselevel. - # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit ;; - Alpha\ *:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # Should we change UNAME_MACHINE based on the output of uname instead - # of the specific Alpha model? - echo alpha-pc-interix - exit ;; - 21064:Windows_NT:50:3) - echo alpha-dec-winnt3.5 - exit ;; - Amiga*:UNIX_System_V:4.0:*) - echo m68k-unknown-sysv4 - exit ;; - *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-amigaos - exit ;; - *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-morphos - exit ;; - *:OS/390:*:*) - echo i370-ibm-openedition - exit ;; - *:z/VM:*:*) - echo s390-ibm-zvmoe - exit ;; - *:OS400:*:*) - echo powerpc-ibm-os400 - exit ;; - arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} - exit ;; - arm:riscos:*:*|arm:RISCOS:*:*) - echo arm-unknown-riscos - exit ;; - SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) - echo hppa1.1-hitachi-hiuxmpp - exit ;; - Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) - # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "`(/bin/universe) 2>/dev/null`" = att ; then - echo pyramid-pyramid-sysv3 - else - echo pyramid-pyramid-bsd - fi - exit ;; - NILE*:*:*:dcosx) - echo pyramid-pyramid-svr4 - exit ;; - DRS?6000:unix:4.0:6*) - echo sparc-icl-nx6 - exit ;; - DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7; exit ;; - esac ;; - s390x:SunOS:*:*) - echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - eval $set_cc_for_build - SUN_ARCH="i386" - # If there is a compiler, see if it is configured for 64-bit objects. - # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. - # This test works for both compilers. - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then - if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - SUN_ARCH="x86_64" - fi - fi - echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:6*:*) - # According to config.sub, this is the proper way to canonicalize - # SunOS6. Hard to guess exactly what SunOS6 will be like, but - # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in - Series*|S4*) - UNAME_RELEASE=`uname -v` - ;; - esac - # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit ;; - sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} - exit ;; - sun*:*:4.2BSD:*) - UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 - case "`/bin/arch`" in - sun3) - echo m68k-sun-sunos${UNAME_RELEASE} - ;; - sun4) - echo sparc-sun-sunos${UNAME_RELEASE} - ;; - esac - exit ;; - aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} - exit ;; - # The situation for MiNT is a little confusing. The machine name - # can be virtually everything (everything which is not - # "atarist" or "atariste" at least should have a processor - # > m68000). The system name ranges from "MiNT" over "FreeMiNT" - # to the lowercase version "mint" (or "freemint"). Finally - # the system name "TOS" denotes a system which is actually not - # MiNT. But MiNT is downward compatible to TOS, so this should - # be no problem. - atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} - exit ;; - hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} - exit ;; - *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint${UNAME_RELEASE} - exit ;; - m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} - exit ;; - powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} - exit ;; - RISC*:Mach:*:*) - echo mips-dec-mach_bsd4.3 - exit ;; - RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} - exit ;; - VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} - exit ;; - 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} - exit ;; - mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c -#ifdef __cplusplus -#include /* for printf() prototype */ - int main (int argc, char *argv[]) { -#else - int main (argc, argv) int argc; char *argv[]; { -#endif - #if defined (host_mips) && defined (MIPSEB) - #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); - #endif - #endif - exit (-1); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && - dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`$dummy $dummyarg` && - { echo "$SYSTEM_NAME"; exit; } - echo mips-mips-riscos${UNAME_RELEASE} - exit ;; - Motorola:PowerMAX_OS:*:*) - echo powerpc-motorola-powermax - exit ;; - Motorola:*:4.3:PL8-*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:Power_UNIX:*:*) - echo powerpc-harris-powerunix - exit ;; - m88k:CX/UX:7*:*) - echo m88k-harris-cxux7 - exit ;; - m88k:*:4*:R4*) - echo m88k-motorola-sysv4 - exit ;; - m88k:*:3*:R3*) - echo m88k-motorola-sysv3 - exit ;; - AViiON:dgux:*:*) - # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] - then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] - then - echo m88k-dg-dgux${UNAME_RELEASE} - else - echo m88k-dg-dguxbcs${UNAME_RELEASE} - fi - else - echo i586-dg-dgux${UNAME_RELEASE} - fi - exit ;; - M88*:DolphinOS:*:*) # DolphinOS (SVR3) - echo m88k-dolphin-sysv3 - exit ;; - M88*:*:R3*:*) - # Delta 88k system running SVR3 - echo m88k-motorola-sysv3 - exit ;; - XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) - echo m88k-tektronix-sysv3 - exit ;; - Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) - echo m68k-tektronix-bsd - exit ;; - *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit ;; - ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' - i*86:AIX:*:*) - echo i386-ibm-aix - exit ;; - ia64:AIX:*:*) - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit ;; - *:AIX:2:3) - if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - - main() - { - if (!__power_pc()) - exit(1); - puts("powerpc-ibm-aix3.2.5"); - exit(0); - } -EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` - then - echo "$SYSTEM_NAME" - else - echo rs6000-ibm-aix3.2.5 - fi - elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then - echo rs6000-ibm-aix3.2.4 - else - echo rs6000-ibm-aix3.2 - fi - exit ;; - *:AIX:*:[456]) - IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` - if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then - IBM_ARCH=rs6000 - else - IBM_ARCH=powerpc - fi - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit ;; - *:AIX:*:*) - echo rs6000-ibm-aix - exit ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) - echo romp-ibm-bsd4.4 - exit ;; - ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit ;; # report: romp-ibm BSD 4.3 - *:BOSX:*:*) - echo rs6000-bull-bosx - exit ;; - DPX/2?00:B.O.S.:*:*) - echo m68k-bull-sysv3 - exit ;; - 9000/[34]??:4.3bsd:1.*:*) - echo m68k-hp-bsd - exit ;; - hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) - echo m68k-hp-bsd4.4 - exit ;; - 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - case "${UNAME_MACHINE}" in - 9000/31? ) HP_ARCH=m68000 ;; - 9000/[34]?? ) HP_ARCH=m68k ;; - 9000/[678][0-9][0-9]) - if [ -x /usr/bin/getconf ]; then - sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "${sc_cpu_version}" in - 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 - 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 - 532) # CPU_PA_RISC2_0 - case "${sc_kernel_bits}" in - 32) HP_ARCH="hppa2.0n" ;; - 64) HP_ARCH="hppa2.0w" ;; - '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 - esac ;; - esac - fi - if [ "${HP_ARCH}" = "" ]; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - - #define _HPUX_SOURCE - #include - #include - - int main () - { - #if defined(_SC_KERNEL_BITS) - long bits = sysconf(_SC_KERNEL_BITS); - #endif - long cpu = sysconf (_SC_CPU_VERSION); - - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: - #if defined(_SC_KERNEL_BITS) - switch (bits) - { - case 64: puts ("hppa2.0w"); break; - case 32: puts ("hppa2.0n"); break; - default: puts ("hppa2.0"); break; - } break; - #else /* !defined(_SC_KERNEL_BITS) */ - puts ("hppa2.0"); break; - #endif - default: puts ("hppa1.0"); break; - } - exit (0); - } -EOF - (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` - test -z "$HP_ARCH" && HP_ARCH=hppa - fi ;; - esac - if [ ${HP_ARCH} = "hppa2.0w" ] - then - eval $set_cc_for_build - - # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating - # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler - # generating 64-bit code. GNU and HP use different nomenclature: - # - # $ CC_FOR_BUILD=cc ./config.guess - # => hppa2.0w-hp-hpux11.23 - # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess - # => hppa64-hp-hpux11.23 - - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | - grep __LP64__ >/dev/null - then - HP_ARCH="hppa2.0w" - else - HP_ARCH="hppa64" - fi - fi - echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit ;; - ia64:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - echo ia64-hp-hpux${HPUX_REV} - exit ;; - 3050*:HI-UX:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - int - main () - { - long cpu = sysconf (_SC_CPU_VERSION); - /* The order matters, because CPU_IS_HP_MC68K erroneously returns - true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct - results, however. */ - if (CPU_IS_PA_RISC (cpu)) - { - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; - case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; - default: puts ("hppa-hitachi-hiuxwe2"); break; - } - } - else if (CPU_IS_HP_MC68K (cpu)) - puts ("m68k-hitachi-hiuxwe2"); - else puts ("unknown-hitachi-hiuxwe2"); - exit (0); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - echo unknown-hitachi-hiuxwe2 - exit ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) - echo hppa1.1-hp-bsd - exit ;; - 9000/8??:4.3bsd:*:*) - echo hppa1.0-hp-bsd - exit ;; - *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) - echo hppa1.0-hp-mpeix - exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) - echo hppa1.1-hp-osf - exit ;; - hp8??:OSF1:*:*) - echo hppa1.0-hp-osf - exit ;; - i*86:OSF1:*:*) - if [ -x /usr/sbin/sysversion ] ; then - echo ${UNAME_MACHINE}-unknown-osf1mk - else - echo ${UNAME_MACHINE}-unknown-osf1 - fi - exit ;; - parisc*:Lites*:*:*) - echo hppa1.1-hp-lites - exit ;; - C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) - echo c1-convex-bsd - exit ;; - C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) - echo c34-convex-bsd - exit ;; - C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) - echo c38-convex-bsd - exit ;; - C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) - echo c4-convex-bsd - exit ;; - CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ - | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ - -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ - -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` - echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit ;; - sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:FreeBSD:*:*) - case ${UNAME_MACHINE} in - pc98) - echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - amd64) - echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - *) - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;; - esac - exit ;; - i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin - exit ;; - *:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 - exit ;; - i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 - exit ;; - i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 - exit ;; - *:Interix*:[3456]*) - case ${UNAME_MACHINE} in - x86) - echo i586-pc-interix${UNAME_RELEASE} - exit ;; - EM64T | authenticamd | genuineintel) - echo x86_64-unknown-interix${UNAME_RELEASE} - exit ;; - IA64) - echo ia64-unknown-interix${UNAME_RELEASE} - exit ;; - esac ;; - [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) - echo i${UNAME_MACHINE}-pc-mks - exit ;; - i*:Windows_NT*:* | Pentium*:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we - # UNAME_MACHINE based on the output of uname instead of i386? - echo i586-pc-interix - exit ;; - i*:UWIN*:*) - echo ${UNAME_MACHINE}-pc-uwin - exit ;; - amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-unknown-cygwin - exit ;; - p*:CYGWIN*:*) - echo powerpcle-unknown-cygwin - exit ;; - prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - *:GNU:*:*) - # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit ;; - *:GNU/*:*:*) - # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu - exit ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix - exit ;; - arm*:Linux:*:*) - eval $set_cc_for_build - if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep -q __ARM_EABI__ - then - echo ${UNAME_MACHINE}-unknown-linux-gnu - else - echo ${UNAME_MACHINE}-unknown-linux-gnueabi - fi - exit ;; - avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - cris:Linux:*:*) - echo cris-axis-linux-gnu - exit ;; - crisv32:Linux:*:*) - echo crisv32-axis-linux-gnu - exit ;; - frv:Linux:*:*) - echo frv-unknown-linux-gnu - exit ;; - ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - mips:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips - #undef mipsel - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mipsel - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips - #else - CPU= - #endif - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips64 - #undef mips64el - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mips64el - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips64 - #else - CPU= - #endif - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^CPU/{ - s: ::g - p - }'`" - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - or32:Linux:*:*) - echo or32-unknown-linux-gnu - exit ;; - ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu - exit ;; - ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu - exit ;; - alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in - EV5) UNAME_MACHINE=alphaev5 ;; - EV56) UNAME_MACHINE=alphaev56 ;; - PCA56) UNAME_MACHINE=alphapca56 ;; - PCA57) UNAME_MACHINE=alphapca56 ;; - EV6) UNAME_MACHINE=alphaev6 ;; - EV67) UNAME_MACHINE=alphaev67 ;; - EV68*) UNAME_MACHINE=alphaev68 ;; - esac - objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null - if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi - echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit ;; - padre:Linux:*:*) - echo sparc-unknown-linux-gnu - exit ;; - parisc:Linux:*:* | hppa:Linux:*:*) - # Look for CPU level - case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-gnu ;; - PA8*) echo hppa2.0-unknown-linux-gnu ;; - *) echo hppa-unknown-linux-gnu ;; - esac - exit ;; - parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-gnu - exit ;; - s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux - exit ;; - sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sh*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-gnu - exit ;; - x86_64:Linux:*:*) - echo x86_64-unknown-linux-gnu - exit ;; - xtensa*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - i*86:Linux:*:*) - # The BFD linker knows what the default object file format is, so - # first see if it will tell us. cd to the root directory to prevent - # problems with other programs or directories called `ld' in the path. - # Set LC_ALL=C to ensure ld outputs messages in English. - ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ - | sed -ne '/supported targets:/!d - s/[ ][ ]*/ /g - s/.*supported targets: *// - s/ .*// - p'` - case "$ld_supported_targets" in - elf32-i386) - TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" - ;; - a.out-i386-linux) - echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit ;; - "") - # Either a pre-BFD a.out linker (linux-gnuoldld) or - # one that does not give us useful --help. - echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit ;; - esac - # Determine whether the default compiler is a.out or elf - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include - #ifdef __ELF__ - # ifdef __GLIBC__ - # if __GLIBC__ >= 2 - LIBC=gnu - # else - LIBC=gnulibc1 - # endif - # else - LIBC=gnulibc1 - # endif - #else - #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) - LIBC=gnu - #else - LIBC=gnuaout - #endif - #endif - #ifdef __dietlibc__ - LIBC=dietlibc - #endif -EOF - eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n ' - /^LIBC/{ - s: ::g - p - }'`" - test x"${LIBC}" != x && { - echo "${UNAME_MACHINE}-pc-linux-${LIBC}" - exit - } - test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } - ;; - i*86:DYNIX/ptx:4*:*) - # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. - # earlier versions are messed up and put the nodename in both - # sysname and nodename. - echo i386-sequent-sysv4 - exit ;; - i*86:UNIX_SV:4.2MP:2.*) - # Unixware is an offshoot of SVR4, but it has its own version - # number series starting with 2... - # I am not positive that other SVR4 systems won't match this, - # I just have to hope. -- rms. - # Use sysv4.2uw... so that sysv4* matches it. - echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit ;; - i*86:OS/2:*:*) - # If we were able to find `uname', then EMX Unix compatibility - # is probably installed. - echo ${UNAME_MACHINE}-pc-os2-emx - exit ;; - i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-unknown-stop - exit ;; - i*86:atheos:*:*) - echo ${UNAME_MACHINE}-unknown-atheos - exit ;; - i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable - exit ;; - i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) - echo i386-unknown-lynxos${UNAME_RELEASE} - exit ;; - i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` - if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} - else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} - fi - exit ;; - i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. - case `/bin/uname -X | grep "^Machine"` in - *486*) UNAME_MACHINE=i486 ;; - *Pentium) UNAME_MACHINE=i586 ;; - *Pent*|*Celeron) UNAME_MACHINE=i686 ;; - esac - echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit ;; - i*86:*:3.2:*) - if test -f /usr/options/cb.name; then - UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then - UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` - (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 - (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ - && UNAME_MACHINE=i586 - (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ - && UNAME_MACHINE=i686 - (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ - && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL - else - echo ${UNAME_MACHINE}-pc-sysv32 - fi - exit ;; - pc:*:*:*) - # Left here for compatibility: - # uname -m prints for DJGPP always 'pc', but it prints nothing about - # the processor, so we play safe by assuming i586. - # Note: whatever this is, it MUST be the same as what config.sub - # prints for the "djgpp" host, or else GDB configury will decide that - # this is a cross-build. - echo i586-pc-msdosdjgpp - exit ;; - Intel:Mach:3*:*) - echo i386-pc-mach3 - exit ;; - paragon:*:*:*) - echo i860-intel-osf1 - exit ;; - i860:*:4.*:*) # i860-SVR4 - if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 - else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 - fi - exit ;; - mini*:CTIX:SYS*5:*) - # "miniframe" - echo m68010-convergent-sysv - exit ;; - mc68k:UNIX:SYSTEM5:3.51m) - echo m68k-convergent-sysv - exit ;; - M680?0:D-NIX:5.3:*) - echo m68k-diab-dnix - exit ;; - M68*:*:R3V[5678]*:*) - test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; - 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) - OS_REL='' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; - 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; - NCR*:*:4.2:* | MPRAS*:*:4.2:*) - OS_REL='.3' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; - m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos${UNAME_RELEASE} - exit ;; - mc68030:UNIX_System_V:4.*:*) - echo m68k-atari-sysv4 - exit ;; - TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos${UNAME_RELEASE} - exit ;; - rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit ;; - PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) - echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit ;; - SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} - exit ;; - RM*:ReliantUNIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - RM*:SINIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - *:SINIX-*:*:*) - if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 - else - echo ns32k-sni-sysv - fi - exit ;; - PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says - echo i586-unisys-sysv4 - exit ;; - *:UNIX_System_V:4*:FTX*) - # From Gerald Hewes . - # How about differentiating between stratus architectures? -djm - echo hppa1.1-stratus-sysv4 - exit ;; - *:*:*:FTX*) - # From seanf@swdc.stratus.com. - echo i860-stratus-sysv4 - exit ;; - i*86:VOS:*:*) - # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos - exit ;; - *:VOS:*:*) - # From Paul.Green@stratus.com. - echo hppa1.1-stratus-vos - exit ;; - mc68*:A/UX:*:*) - echo m68k-apple-aux${UNAME_RELEASE} - exit ;; - news*:NEWS-OS:6*:*) - echo mips-sony-newsos6 - exit ;; - R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if [ -d /usr/nec ]; then - echo mips-nec-sysv${UNAME_RELEASE} - else - echo mips-unknown-sysv${UNAME_RELEASE} - fi - exit ;; - BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. - echo powerpc-be-beos - exit ;; - BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. - echo powerpc-apple-beos - exit ;; - BePC:BeOS:*:*) # BeOS running on Intel PC compatible. - echo i586-pc-beos - exit ;; - BePC:Haiku:*:*) # Haiku running on Intel PC compatible. - echo i586-pc-haiku - exit ;; - SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} - exit ;; - SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} - exit ;; - SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} - exit ;; - SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} - exit ;; - SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} - exit ;; - SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} - exit ;; - Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - case $UNAME_PROCESSOR in - unknown) UNAME_PROCESSOR=powerpc ;; - esac - echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit ;; - *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = "x86"; then - UNAME_PROCESSOR=i386 - UNAME_MACHINE=pc - fi - echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit ;; - *:QNX:*:4*) - echo i386-pc-qnx - exit ;; - NSE-?:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} - exit ;; - NSR-?:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} - exit ;; - *:NonStop-UX:*:*) - echo mips-compaq-nonstopux - exit ;; - BS2000:POSIX*:*:*) - echo bs2000-siemens-sysv - exit ;; - DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit ;; - *:Plan9:*:*) - # "uname -m" is not consistent, so use $cputype instead. 386 - # is converted to i386 for consistency with other x86 - # operating systems. - if test "$cputype" = "386"; then - UNAME_MACHINE=i386 - else - UNAME_MACHINE="$cputype" - fi - echo ${UNAME_MACHINE}-unknown-plan9 - exit ;; - *:TOPS-10:*:*) - echo pdp10-unknown-tops10 - exit ;; - *:TENEX:*:*) - echo pdp10-unknown-tenex - exit ;; - KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) - echo pdp10-dec-tops20 - exit ;; - XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) - echo pdp10-xkl-tops20 - exit ;; - *:TOPS-20:*:*) - echo pdp10-unknown-tops20 - exit ;; - *:ITS:*:*) - echo pdp10-unknown-its - exit ;; - SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} - exit ;; - *:DragonFly:*:*) - echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` - exit ;; - *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in - A*) echo alpha-dec-vms ; exit ;; - I*) echo ia64-dec-vms ; exit ;; - V*) echo vax-dec-vms ; exit ;; - esac ;; - *:XENIX:*:SysV) - echo i386-pc-xenix - exit ;; - i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' - exit ;; - i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos - exit ;; - i*86:AROS:*:*) - echo ${UNAME_MACHINE}-pc-aros - exit ;; -esac - -#echo '(No uname command or uname output not recognized.)' 1>&2 -#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 - -eval $set_cc_for_build -cat >$dummy.c < -# include -#endif -main () -{ -#if defined (sony) -#if defined (MIPSEB) - /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, - I don't know.... */ - printf ("mips-sony-bsd\n"); exit (0); -#else -#include - printf ("m68k-sony-newsos%s\n", -#ifdef NEWSOS4 - "4" -#else - "" -#endif - ); exit (0); -#endif -#endif - -#if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix\n"); exit (0); -#endif - -#if defined (hp300) && !defined (hpux) - printf ("m68k-hp-bsd\n"); exit (0); -#endif - -#if defined (NeXT) -#if !defined (__ARCHITECTURE__) -#define __ARCHITECTURE__ "m68k" -#endif - int version; - version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - if (version < 4) - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); - else - printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); - exit (0); -#endif - -#if defined (MULTIMAX) || defined (n16) -#if defined (UMAXV) - printf ("ns32k-encore-sysv\n"); exit (0); -#else -#if defined (CMU) - printf ("ns32k-encore-mach\n"); exit (0); -#else - printf ("ns32k-encore-bsd\n"); exit (0); -#endif -#endif -#endif - -#if defined (__386BSD__) - printf ("i386-pc-bsd\n"); exit (0); -#endif - -#if defined (sequent) -#if defined (i386) - printf ("i386-sequent-dynix\n"); exit (0); -#endif -#if defined (ns32000) - printf ("ns32k-sequent-dynix\n"); exit (0); -#endif -#endif - -#if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); - -#endif - -#if defined (vax) -# if !defined (ultrix) -# include -# if defined (BSD) -# if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -# else -# if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# endif -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# else - printf ("vax-dec-ultrix\n"); exit (0); -# endif -#endif - -#if defined (alliant) && defined (i860) - printf ("i860-alliant-bsd\n"); exit (0); -#endif - - exit (1); -} -EOF - -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - -# Apollos put the system type in the environment. - -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } - -# Convex versions that predate uname can use getsysinfo(1) - -if [ -x /usr/convex/getsysinfo ] -then - case `getsysinfo -f cpu_type` in - c1*) - echo c1-convex-bsd - exit ;; - c2*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - c34*) - echo c34-convex-bsd - exit ;; - c38*) - echo c38-convex-bsd - exit ;; - c4*) - echo c4-convex-bsd - exit ;; - esac -fi - -cat >&2 < in order to provide the needed -information to handle your system. - -config.guess timestamp = $timestamp - -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null` - -hostinfo = `(hostinfo) 2>/dev/null` -/bin/universe = `(/bin/universe) 2>/dev/null` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` -/bin/arch = `(/bin/arch) 2>/dev/null` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` - -UNAME_MACHINE = ${UNAME_MACHINE} -UNAME_RELEASE = ${UNAME_RELEASE} -UNAME_SYSTEM = ${UNAME_SYSTEM} -UNAME_VERSION = ${UNAME_VERSION} -EOF - -exit 1 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/bundled/tdb/config.mk b/bundled/tdb/config.mk deleted file mode 100644 index b2e322ce..00000000 --- a/bundled/tdb/config.mk +++ /dev/null @@ -1,57 +0,0 @@ -################################################ -# Start SUBSYSTEM LIBTDB -[LIBRARY::LIBTDB] -OUTPUT_TYPE = MERGED_OBJ -CFLAGS = -I$(tdbsrcdir)/include -# -# End SUBSYSTEM ldb -################################################ - -LIBTDB_OBJ_FILES = $(addprefix $(tdbsrcdir)/common/, \ - tdb.o dump.o io.o lock.o \ - open.o traverse.o freelist.o \ - error.o transaction.o check.o) - -################################################ -# Start BINARY tdbtool -[BINARY::tdbtool] -INSTALLDIR = BINDIR -PRIVATE_DEPENDENCIES = \ - LIBTDB -# End BINARY tdbtool -################################################ - -tdbtool_OBJ_FILES = $(tdbsrcdir)/tools/tdbtool.o - -################################################ -# Start BINARY tdbtorture -[BINARY::tdbtorture] -INSTALLDIR = BINDIR -PRIVATE_DEPENDENCIES = \ - LIBTDB -# End BINARY tdbtorture -################################################ - -tdbtorture_OBJ_FILES = $(tdbsrcdir)/tools/tdbtorture.o - -################################################ -# Start BINARY tdbdump -[BINARY::tdbdump] -INSTALLDIR = BINDIR -PRIVATE_DEPENDENCIES = \ - LIBTDB -# End BINARY tdbdump -################################################ - -tdbdump_OBJ_FILES = $(tdbsrcdir)/tools/tdbdump.o - -################################################ -# Start BINARY tdbbackup -[BINARY::tdbbackup] -INSTALLDIR = BINDIR -PRIVATE_DEPENDENCIES = \ - LIBTDB -# End BINARY tdbbackup -################################################ - -tdbbackup_OBJ_FILES = $(tdbsrcdir)/tools/tdbbackup.o diff --git a/bundled/tdb/config.sub b/bundled/tdb/config.sub deleted file mode 100755 index a39437d0..00000000 --- a/bundled/tdb/config.sub +++ /dev/null @@ -1,1686 +0,0 @@ -#! /bin/sh -# Configuration validation subroutine script. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 -# Free Software Foundation, Inc. - -timestamp='2009-04-17' - -# This file is (in principle) common to ALL GNU software. -# The presence of a machine in this file suggests that SOME GNU software -# can handle that machine. It does not imply ALL GNU software can. -# -# This file is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA -# 02110-1301, USA. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Please send patches to . Submit a context -# diff and a properly formatted ChangeLog entry. -# -# Configuration subroutine to validate and canonicalize a configuration type. -# Supply the specified configuration type as an argument. -# If it is invalid, we print an error message on stderr and exit with code 1. -# Otherwise, we print the canonical config type on stdout and succeed. - -# This file is supposed to be the same for all GNU packages -# and recognize all the CPU types, system types and aliases -# that are meaningful with *any* GNU software. -# Each package is responsible for reporting which valid configurations -# it does not support. The user should be able to distinguish -# a failure to support a valid configuration from a meaningless -# configuration. - -# The goal of this file is to map all the various variations of a given -# machine specification into a single specification in the form: -# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM -# or in some cases, the newer four-part form: -# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM -# It is wrong to echo any other type of specification. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] CPU-MFR-OPSYS - $0 [OPTION] ALIAS - -Canonicalize a configuration name. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to ." - -version="\ -GNU config.sub ($timestamp) - -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" - exit 1 ;; - - *local*) - # First pass through any local machine types. - echo $1 - exit ;; - - * ) - break ;; - esac -done - -case $# in - 0) echo "$me: missing argument$help" >&2 - exit 1;; - 1) ;; - *) echo "$me: too many arguments$help" >&2 - exit 1;; -esac - -# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). -# Here we must recognize all the valid KERNEL-OS combinations. -maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` -case $maybe_os in - nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ - uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ - kopensolaris*-gnu* | \ - storm-chaos* | os2-emx* | rtmk-nova*) - os=-$maybe_os - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` - ;; - *) - basic_machine=`echo $1 | sed 's/-[^-]*$//'` - if [ $basic_machine != $1 ] - then os=`echo $1 | sed 's/.*-/-/'` - else os=; fi - ;; -esac - -### Let's recognize common machines as not being operating systems so -### that things like config.sub decstation-3100 work. We also -### recognize some manufacturers as not being operating systems, so we -### can provide default operating systems below. -case $os in - -sun*os*) - # Prevent following clause from handling this invalid input. - ;; - -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ - -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ - -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ - -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ - -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ - -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis | -knuth | -cray) - os= - basic_machine=$1 - ;; - -sim | -cisco | -oki | -wec | -winbond) - os= - basic_machine=$1 - ;; - -scout) - ;; - -wrs) - os=-vxworks - basic_machine=$1 - ;; - -chorusos*) - os=-chorusos - basic_machine=$1 - ;; - -chorusrdb) - os=-chorusrdb - basic_machine=$1 - ;; - -hiux*) - os=-hiuxwe2 - ;; - -sco6) - os=-sco5v6 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco5) - os=-sco3.2v5 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco4) - os=-sco3.2v4 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2.[4-9]*) - os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2v[4-9]*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco5v6*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco*) - os=-sco3.2v2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -udk*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -isc) - os=-isc2.2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -clix*) - basic_machine=clipper-intergraph - ;; - -isc*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -lynx*) - os=-lynxos - ;; - -ptx*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` - ;; - -windowsnt*) - os=`echo $os | sed -e 's/windowsnt/winnt/'` - ;; - -psos*) - os=-psos - ;; - -mint | -mint[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; -esac - -# Decode aliases for certain CPU-COMPANY combinations. -case $basic_machine in - # Recognize the basic CPU types without company name. - # Some are omitted here because they have special meanings below. - 1750a | 580 \ - | a29k \ - | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ - | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | am33_2.0 \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ - | bfin \ - | c4x | clipper \ - | d10v | d30v | dlx | dsp16xx \ - | fido | fr30 | frv \ - | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ - | i370 | i860 | i960 | ia64 \ - | ip2k | iq2000 \ - | lm32 \ - | m32c | m32r | m32rle | m68000 | m68k | m88k \ - | maxq | mb | microblaze | mcore | mep | metag \ - | mips | mipsbe | mipseb | mipsel | mipsle \ - | mips16 \ - | mips64 | mips64el \ - | mips64octeon | mips64octeonel \ - | mips64orion | mips64orionel \ - | mips64r5900 | mips64r5900el \ - | mips64vr | mips64vrel \ - | mips64vr4100 | mips64vr4100el \ - | mips64vr4300 | mips64vr4300el \ - | mips64vr5000 | mips64vr5000el \ - | mips64vr5900 | mips64vr5900el \ - | mipsisa32 | mipsisa32el \ - | mipsisa32r2 | mipsisa32r2el \ - | mipsisa64 | mipsisa64el \ - | mipsisa64r2 | mipsisa64r2el \ - | mipsisa64sb1 | mipsisa64sb1el \ - | mipsisa64sr71k | mipsisa64sr71kel \ - | mipstx39 | mipstx39el \ - | mn10200 | mn10300 \ - | moxie \ - | mt \ - | msp430 \ - | nios | nios2 \ - | ns16k | ns32k \ - | or32 \ - | pdp10 | pdp11 | pj | pjl \ - | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ - | pyramid \ - | score \ - | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ - | sh64 | sh64le \ - | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ - | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ - | spu | strongarm \ - | tahoe | thumb | tic4x | tic80 | tron \ - | v850 | v850e \ - | we32k \ - | x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ - | z8k | z80) - basic_machine=$basic_machine-unknown - ;; - m6811 | m68hc11 | m6812 | m68hc12) - # Motorola 68HC11/12. - basic_machine=$basic_machine-unknown - os=-none - ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) - ;; - ms1) - basic_machine=mt-unknown - ;; - - # We use `pc' rather than `unknown' - # because (1) that's what they normally are, and - # (2) the word "unknown" tends to confuse beginning users. - i*86 | x86_64) - basic_machine=$basic_machine-pc - ;; - # Object if more than one company name word. - *-*-*) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; - # Recognize the basic CPU types with company name. - 580-* \ - | a29k-* \ - | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ - | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ - | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* | avr32-* \ - | bfin-* | bs2000-* \ - | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ - | clipper-* | craynv-* | cydra-* \ - | d10v-* | d30v-* | dlx-* \ - | elxsi-* \ - | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ - | h8300-* | h8500-* \ - | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ - | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* | iq2000-* \ - | lm32-* \ - | m32c-* | m32r-* | m32rle-* \ - | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \ - | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ - | mips16-* \ - | mips64-* | mips64el-* \ - | mips64octeon-* | mips64octeonel-* \ - | mips64orion-* | mips64orionel-* \ - | mips64r5900-* | mips64r5900el-* \ - | mips64vr-* | mips64vrel-* \ - | mips64vr4100-* | mips64vr4100el-* \ - | mips64vr4300-* | mips64vr4300el-* \ - | mips64vr5000-* | mips64vr5000el-* \ - | mips64vr5900-* | mips64vr5900el-* \ - | mipsisa32-* | mipsisa32el-* \ - | mipsisa32r2-* | mipsisa32r2el-* \ - | mipsisa64-* | mipsisa64el-* \ - | mipsisa64r2-* | mipsisa64r2el-* \ - | mipsisa64sb1-* | mipsisa64sb1el-* \ - | mipsisa64sr71k-* | mipsisa64sr71kel-* \ - | mipstx39-* | mipstx39el-* \ - | mmix-* \ - | mt-* \ - | msp430-* \ - | nios-* | nios2-* \ - | none-* | np1-* | ns16k-* | ns32k-* \ - | orion-* \ - | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ - | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ - | pyramid-* \ - | romp-* | rs6000-* \ - | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ - | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ - | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ - | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ - | tahoe-* | thumb-* \ - | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* | tile-* \ - | tron-* \ - | v850-* | v850e-* | vax-* \ - | we32k-* \ - | x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ - | xstormy16-* | xtensa*-* \ - | ymp-* \ - | z8k-* | z80-*) - ;; - # Recognize the basic CPU types without company name, with glob match. - xtensa*) - basic_machine=$basic_machine-unknown - ;; - # Recognize the various machine names and aliases which stand - # for a CPU type and a company and sometimes even an OS. - 386bsd) - basic_machine=i386-unknown - os=-bsd - ;; - 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) - basic_machine=m68000-att - ;; - 3b*) - basic_machine=we32k-att - ;; - a29khif) - basic_machine=a29k-amd - os=-udi - ;; - abacus) - basic_machine=abacus-unknown - ;; - adobe68k) - basic_machine=m68010-adobe - os=-scout - ;; - alliant | fx80) - basic_machine=fx80-alliant - ;; - altos | altos3068) - basic_machine=m68k-altos - ;; - am29k) - basic_machine=a29k-none - os=-bsd - ;; - amd64) - basic_machine=x86_64-pc - ;; - amd64-*) - basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - amdahl) - basic_machine=580-amdahl - os=-sysv - ;; - amiga | amiga-*) - basic_machine=m68k-unknown - ;; - amigaos | amigados) - basic_machine=m68k-unknown - os=-amigaos - ;; - amigaunix | amix) - basic_machine=m68k-unknown - os=-sysv4 - ;; - apollo68) - basic_machine=m68k-apollo - os=-sysv - ;; - apollo68bsd) - basic_machine=m68k-apollo - os=-bsd - ;; - aros) - basic_machine=i386-pc - os=-aros - ;; - aux) - basic_machine=m68k-apple - os=-aux - ;; - balance) - basic_machine=ns32k-sequent - os=-dynix - ;; - blackfin) - basic_machine=bfin-unknown - os=-linux - ;; - blackfin-*) - basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux - ;; - c90) - basic_machine=c90-cray - os=-unicos - ;; - cegcc) - basic_machine=arm-unknown - os=-cegcc - ;; - convex-c1) - basic_machine=c1-convex - os=-bsd - ;; - convex-c2) - basic_machine=c2-convex - os=-bsd - ;; - convex-c32) - basic_machine=c32-convex - os=-bsd - ;; - convex-c34) - basic_machine=c34-convex - os=-bsd - ;; - convex-c38) - basic_machine=c38-convex - os=-bsd - ;; - cray | j90) - basic_machine=j90-cray - os=-unicos - ;; - craynv) - basic_machine=craynv-cray - os=-unicosmp - ;; - cr16) - basic_machine=cr16-unknown - os=-elf - ;; - crds | unos) - basic_machine=m68k-crds - ;; - crisv32 | crisv32-* | etraxfs*) - basic_machine=crisv32-axis - ;; - cris | cris-* | etrax*) - basic_machine=cris-axis - ;; - crx) - basic_machine=crx-unknown - os=-elf - ;; - da30 | da30-*) - basic_machine=m68k-da30 - ;; - decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) - basic_machine=mips-dec - ;; - decsystem10* | dec10*) - basic_machine=pdp10-dec - os=-tops10 - ;; - decsystem20* | dec20*) - basic_machine=pdp10-dec - os=-tops20 - ;; - delta | 3300 | motorola-3300 | motorola-delta \ - | 3300-motorola | delta-motorola) - basic_machine=m68k-motorola - ;; - delta88) - basic_machine=m88k-motorola - os=-sysv3 - ;; - dicos) - basic_machine=i686-pc - os=-dicos - ;; - djgpp) - basic_machine=i586-pc - os=-msdosdjgpp - ;; - dpx20 | dpx20-*) - basic_machine=rs6000-bull - os=-bosx - ;; - dpx2* | dpx2*-bull) - basic_machine=m68k-bull - os=-sysv3 - ;; - ebmon29k) - basic_machine=a29k-amd - os=-ebmon - ;; - elxsi) - basic_machine=elxsi-elxsi - os=-bsd - ;; - encore | umax | mmax) - basic_machine=ns32k-encore - ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - os=-ose - ;; - fx2800) - basic_machine=i860-alliant - ;; - genix) - basic_machine=ns32k-ns - ;; - gmicro) - basic_machine=tron-gmicro - os=-sysv - ;; - go32) - basic_machine=i386-pc - os=-go32 - ;; - h3050r* | hiux*) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - h8300hms) - basic_machine=h8300-hitachi - os=-hms - ;; - h8300xray) - basic_machine=h8300-hitachi - os=-xray - ;; - h8500hms) - basic_machine=h8500-hitachi - os=-hms - ;; - harris) - basic_machine=m88k-harris - os=-sysv3 - ;; - hp300-*) - basic_machine=m68k-hp - ;; - hp300bsd) - basic_machine=m68k-hp - os=-bsd - ;; - hp300hpux) - basic_machine=m68k-hp - os=-hpux - ;; - hp3k9[0-9][0-9] | hp9[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k2[0-9][0-9] | hp9k31[0-9]) - basic_machine=m68000-hp - ;; - hp9k3[2-9][0-9]) - basic_machine=m68k-hp - ;; - hp9k6[0-9][0-9] | hp6[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k7[0-79][0-9] | hp7[0-79][0-9]) - basic_machine=hppa1.1-hp - ;; - hp9k78[0-9] | hp78[0-9]) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][13679] | hp8[0-9][13679]) - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][0-9] | hp8[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hppa-next) - os=-nextstep3 - ;; - hppaosf) - basic_machine=hppa1.1-hp - os=-osf - ;; - hppro) - basic_machine=hppa1.1-hp - os=-proelf - ;; - i370-ibm* | ibm*) - basic_machine=i370-ibm - ;; -# I'm not sure what "Sysv32" means. Should this be sysv3.2? - i*86v32) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv32 - ;; - i*86v4*) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv4 - ;; - i*86v) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv - ;; - i*86sol2) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-solaris2 - ;; - i386mach) - basic_machine=i386-mach - os=-mach - ;; - i386-vsta | vsta) - basic_machine=i386-unknown - os=-vsta - ;; - iris | iris4d) - basic_machine=mips-sgi - case $os in - -irix*) - ;; - *) - os=-irix4 - ;; - esac - ;; - isi68 | isi) - basic_machine=m68k-isi - os=-sysv - ;; - m68knommu) - basic_machine=m68k-unknown - os=-linux - ;; - m68knommu-*) - basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux - ;; - m88k-omron*) - basic_machine=m88k-omron - ;; - magnum | m3230) - basic_machine=mips-mips - os=-sysv - ;; - merlin) - basic_machine=ns32k-utek - os=-sysv - ;; - mingw32) - basic_machine=i386-pc - os=-mingw32 - ;; - mingw32ce) - basic_machine=arm-unknown - os=-mingw32ce - ;; - miniframe) - basic_machine=m68000-convergent - ;; - *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; - mips3*-*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` - ;; - mips3*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown - ;; - monitor) - basic_machine=m68k-rom68k - os=-coff - ;; - morphos) - basic_machine=powerpc-unknown - os=-morphos - ;; - msdos) - basic_machine=i386-pc - os=-msdos - ;; - ms1-*) - basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` - ;; - mvs) - basic_machine=i370-ibm - os=-mvs - ;; - ncr3000) - basic_machine=i486-ncr - os=-sysv4 - ;; - netbsd386) - basic_machine=i386-unknown - os=-netbsd - ;; - netwinder) - basic_machine=armv4l-rebel - os=-linux - ;; - news | news700 | news800 | news900) - basic_machine=m68k-sony - os=-newsos - ;; - news1000) - basic_machine=m68030-sony - os=-newsos - ;; - news-3600 | risc-news) - basic_machine=mips-sony - os=-newsos - ;; - necv70) - basic_machine=v70-nec - os=-sysv - ;; - next | m*-next ) - basic_machine=m68k-next - case $os in - -nextstep* ) - ;; - -ns2*) - os=-nextstep2 - ;; - *) - os=-nextstep3 - ;; - esac - ;; - nh3000) - basic_machine=m68k-harris - os=-cxux - ;; - nh[45]000) - basic_machine=m88k-harris - os=-cxux - ;; - nindy960) - basic_machine=i960-intel - os=-nindy - ;; - mon960) - basic_machine=i960-intel - os=-mon960 - ;; - nonstopux) - basic_machine=mips-compaq - os=-nonstopux - ;; - np1) - basic_machine=np1-gould - ;; - nsr-tandem) - basic_machine=nsr-tandem - ;; - op50n-* | op60c-*) - basic_machine=hppa1.1-oki - os=-proelf - ;; - openrisc | openrisc-*) - basic_machine=or32-unknown - ;; - os400) - basic_machine=powerpc-ibm - os=-os400 - ;; - OSE68000 | ose68000) - basic_machine=m68000-ericsson - os=-ose - ;; - os68k) - basic_machine=m68k-none - os=-os68k - ;; - pa-hitachi) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - paragon) - basic_machine=i860-intel - os=-osf - ;; - parisc) - basic_machine=hppa-unknown - os=-linux - ;; - parisc-*) - basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'` - os=-linux - ;; - pbd) - basic_machine=sparc-tti - ;; - pbb) - basic_machine=m68k-tti - ;; - pc532 | pc532-*) - basic_machine=ns32k-pc532 - ;; - pc98) - basic_machine=i386-pc - ;; - pc98-*) - basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium | p5 | k5 | k6 | nexgen | viac3) - basic_machine=i586-pc - ;; - pentiumpro | p6 | 6x86 | athlon | athlon_*) - basic_machine=i686-pc - ;; - pentiumii | pentium2 | pentiumiii | pentium3) - basic_machine=i686-pc - ;; - pentium4) - basic_machine=i786-pc - ;; - pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) - basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumpro-* | p6-* | 6x86-* | athlon-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium4-*) - basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pn) - basic_machine=pn-gould - ;; - power) basic_machine=power-ibm - ;; - ppc) basic_machine=powerpc-unknown - ;; - ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppcle | powerpclittle | ppc-le | powerpc-little) - basic_machine=powerpcle-unknown - ;; - ppcle-* | powerpclittle-*) - basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64) basic_machine=powerpc64-unknown - ;; - ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64le | powerpc64little | ppc64-le | powerpc64-little) - basic_machine=powerpc64le-unknown - ;; - ppc64le-* | powerpc64little-*) - basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ps2) - basic_machine=i386-ibm - ;; - pw32) - basic_machine=i586-unknown - os=-pw32 - ;; - rdos) - basic_machine=i386-pc - os=-rdos - ;; - rom68k) - basic_machine=m68k-rom68k - os=-coff - ;; - rm[46]00) - basic_machine=mips-siemens - ;; - rtpc | rtpc-*) - basic_machine=romp-ibm - ;; - s390 | s390-*) - basic_machine=s390-ibm - ;; - s390x | s390x-*) - basic_machine=s390x-ibm - ;; - sa29200) - basic_machine=a29k-amd - os=-udi - ;; - sb1) - basic_machine=mipsisa64sb1-unknown - ;; - sb1el) - basic_machine=mipsisa64sb1el-unknown - ;; - sde) - basic_machine=mipsisa32-sde - os=-elf - ;; - sei) - basic_machine=mips-sei - os=-seiux - ;; - sequent) - basic_machine=i386-sequent - ;; - sh) - basic_machine=sh-hitachi - os=-hms - ;; - sh5el) - basic_machine=sh5le-unknown - ;; - sh64) - basic_machine=sh64-unknown - ;; - sparclite-wrs | simso-wrs) - basic_machine=sparclite-wrs - os=-vxworks - ;; - sps7) - basic_machine=m68k-bull - os=-sysv2 - ;; - spur) - basic_machine=spur-unknown - ;; - st2000) - basic_machine=m68k-tandem - ;; - stratus) - basic_machine=i860-stratus - os=-sysv4 - ;; - sun2) - basic_machine=m68000-sun - ;; - sun2os3) - basic_machine=m68000-sun - os=-sunos3 - ;; - sun2os4) - basic_machine=m68000-sun - os=-sunos4 - ;; - sun3os3) - basic_machine=m68k-sun - os=-sunos3 - ;; - sun3os4) - basic_machine=m68k-sun - os=-sunos4 - ;; - sun4os3) - basic_machine=sparc-sun - os=-sunos3 - ;; - sun4os4) - basic_machine=sparc-sun - os=-sunos4 - ;; - sun4sol2) - basic_machine=sparc-sun - os=-solaris2 - ;; - sun3 | sun3-*) - basic_machine=m68k-sun - ;; - sun4) - basic_machine=sparc-sun - ;; - sun386 | sun386i | roadrunner) - basic_machine=i386-sun - ;; - sv1) - basic_machine=sv1-cray - os=-unicos - ;; - symmetry) - basic_machine=i386-sequent - os=-dynix - ;; - t3e) - basic_machine=alphaev5-cray - os=-unicos - ;; - t90) - basic_machine=t90-cray - os=-unicos - ;; - tic54x | c54x*) - basic_machine=tic54x-unknown - os=-coff - ;; - tic55x | c55x*) - basic_machine=tic55x-unknown - os=-coff - ;; - tic6x | c6x*) - basic_machine=tic6x-unknown - os=-coff - ;; - tile*) - basic_machine=tile-unknown - os=-linux-gnu - ;; - tx39) - basic_machine=mipstx39-unknown - ;; - tx39el) - basic_machine=mipstx39el-unknown - ;; - toad1) - basic_machine=pdp10-xkl - os=-tops20 - ;; - tower | tower-32) - basic_machine=m68k-ncr - ;; - tpf) - basic_machine=s390x-ibm - os=-tpf - ;; - udi29k) - basic_machine=a29k-amd - os=-udi - ;; - ultra3) - basic_machine=a29k-nyu - os=-sym1 - ;; - v810 | necv810) - basic_machine=v810-nec - os=-none - ;; - vaxv) - basic_machine=vax-dec - os=-sysv - ;; - vms) - basic_machine=vax-dec - os=-vms - ;; - vpp*|vx|vx-*) - basic_machine=f301-fujitsu - ;; - vxworks960) - basic_machine=i960-wrs - os=-vxworks - ;; - vxworks68) - basic_machine=m68k-wrs - os=-vxworks - ;; - vxworks29k) - basic_machine=a29k-wrs - os=-vxworks - ;; - w65*) - basic_machine=w65-wdc - os=-none - ;; - w89k-*) - basic_machine=hppa1.1-winbond - os=-proelf - ;; - xbox) - basic_machine=i686-pc - os=-mingw32 - ;; - xps | xps100) - basic_machine=xps100-honeywell - ;; - ymp) - basic_machine=ymp-cray - os=-unicos - ;; - z8k-*-coff) - basic_machine=z8k-unknown - os=-sim - ;; - z80-*-coff) - basic_machine=z80-unknown - os=-sim - ;; - none) - basic_machine=none-none - os=-none - ;; - -# Here we handle the default manufacturer of certain CPU types. It is in -# some cases the only manufacturer, in others, it is the most popular. - w89k) - basic_machine=hppa1.1-winbond - ;; - op50n) - basic_machine=hppa1.1-oki - ;; - op60c) - basic_machine=hppa1.1-oki - ;; - romp) - basic_machine=romp-ibm - ;; - mmix) - basic_machine=mmix-knuth - ;; - rs6000) - basic_machine=rs6000-ibm - ;; - vax) - basic_machine=vax-dec - ;; - pdp10) - # there are many clones, so DEC is not a safe bet - basic_machine=pdp10-unknown - ;; - pdp11) - basic_machine=pdp11-dec - ;; - we32k) - basic_machine=we32k-att - ;; - sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele) - basic_machine=sh-unknown - ;; - sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) - basic_machine=sparc-sun - ;; - cydra) - basic_machine=cydra-cydrome - ;; - orion) - basic_machine=orion-highlevel - ;; - orion105) - basic_machine=clipper-highlevel - ;; - mac | mpw | mac-mpw) - basic_machine=m68k-apple - ;; - pmac | pmac-mpw) - basic_machine=powerpc-apple - ;; - *-unknown) - # Make sure to match an already-canonicalized machine name. - ;; - *) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; -esac - -# Here we canonicalize certain aliases for manufacturers. -case $basic_machine in - *-digital*) - basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` - ;; - *-commodore*) - basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` - ;; - *) - ;; -esac - -# Decode manufacturer-specific aliases for certain operating systems. - -if [ x"$os" != x"" ] -then -case $os in - # First match some system type aliases - # that might get confused with valid system types. - # -solaris* is a basic system type, with this one exception. - -solaris1 | -solaris1.*) - os=`echo $os | sed -e 's|solaris1|sunos4|'` - ;; - -solaris) - os=-solaris2 - ;; - -svr4*) - os=-sysv4 - ;; - -unixware*) - os=-sysv4.2uw - ;; - -gnu/linux*) - os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` - ;; - # First accept the basic system types. - # The portable systems comes first. - # Each alternative MUST END IN A *, to match a version number. - # -sysv* is not here because it comes later, after sysvr4. - -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ - | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ - | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ - | -kopensolaris* \ - | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ - | -aos* | -aros* \ - | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ - | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -openbsd* | -solidbsd* \ - | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ - | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ - | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ - | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ - | -chorusos* | -chorusrdb* | -cegcc* \ - | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ - | -uxpv* | -beos* | -mpeix* | -udk* \ - | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ - | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ - | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ - | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ - | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops*) - # Remember, each alternative MUST END IN *, to match a version number. - ;; - -qnx*) - case $basic_machine in - x86-* | i*86-*) - ;; - *) - os=-nto$os - ;; - esac - ;; - -nto-qnx*) - ;; - -nto*) - os=`echo $os | sed -e 's|nto|nto-qnx|'` - ;; - -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ - | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) - ;; - -mac*) - os=`echo $os | sed -e 's|mac|macos|'` - ;; - -linux-dietlibc) - os=-linux-dietlibc - ;; - -linux*) - os=`echo $os | sed -e 's|linux|linux-gnu|'` - ;; - -sunos5*) - os=`echo $os | sed -e 's|sunos5|solaris2|'` - ;; - -sunos6*) - os=`echo $os | sed -e 's|sunos6|solaris3|'` - ;; - -opened*) - os=-openedition - ;; - -os400*) - os=-os400 - ;; - -wince*) - os=-wince - ;; - -osfrose*) - os=-osfrose - ;; - -osf*) - os=-osf - ;; - -utek*) - os=-bsd - ;; - -dynix*) - os=-bsd - ;; - -acis*) - os=-aos - ;; - -atheos*) - os=-atheos - ;; - -syllable*) - os=-syllable - ;; - -386bsd) - os=-bsd - ;; - -ctix* | -uts*) - os=-sysv - ;; - -nova*) - os=-rtmk-nova - ;; - -ns2 ) - os=-nextstep2 - ;; - -nsk*) - os=-nsk - ;; - # Preserve the version number of sinix5. - -sinix5.*) - os=`echo $os | sed -e 's|sinix|sysv|'` - ;; - -sinix*) - os=-sysv4 - ;; - -tpf*) - os=-tpf - ;; - -triton*) - os=-sysv3 - ;; - -oss*) - os=-sysv3 - ;; - -svr4) - os=-sysv4 - ;; - -svr3) - os=-sysv3 - ;; - -sysvr4) - os=-sysv4 - ;; - # This must come after -sysvr4. - -sysv*) - ;; - -ose*) - os=-ose - ;; - -es1800*) - os=-ose - ;; - -xenix) - os=-xenix - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - os=-mint - ;; - -aros*) - os=-aros - ;; - -kaos*) - os=-kaos - ;; - -zvmoe) - os=-zvmoe - ;; - -dicos*) - os=-dicos - ;; - -none) - ;; - *) - # Get rid of the `-' at the beginning of $os. - os=`echo $os | sed 's/[^-]*-//'` - echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 - exit 1 - ;; -esac -else - -# Here we handle the default operating systems that come with various machines. -# The value should be what the vendor currently ships out the door with their -# machine or put another way, the most popular os provided with the machine. - -# Note that if you're going to try to match "-MANUFACTURER" here (say, -# "-sun"), then you have to tell the case statement up towards the top -# that MANUFACTURER isn't an operating system. Otherwise, code above -# will signal an error saying that MANUFACTURER isn't an operating -# system, and we'll never get to this point. - -case $basic_machine in - score-*) - os=-elf - ;; - spu-*) - os=-elf - ;; - *-acorn) - os=-riscix1.2 - ;; - arm*-rebel) - os=-linux - ;; - arm*-semi) - os=-aout - ;; - c4x-* | tic4x-*) - os=-coff - ;; - # This must come before the *-dec entry. - pdp10-*) - os=-tops20 - ;; - pdp11-*) - os=-none - ;; - *-dec | vax-*) - os=-ultrix4.2 - ;; - m68*-apollo) - os=-domain - ;; - i386-sun) - os=-sunos4.0.2 - ;; - m68000-sun) - os=-sunos3 - # This also exists in the configure program, but was not the - # default. - # os=-sunos4 - ;; - m68*-cisco) - os=-aout - ;; - mep-*) - os=-elf - ;; - mips*-cisco) - os=-elf - ;; - mips*-*) - os=-elf - ;; - or32-*) - os=-coff - ;; - *-tti) # must be before sparc entry or we get the wrong os. - os=-sysv3 - ;; - sparc-* | *-sun) - os=-sunos4.1.1 - ;; - *-be) - os=-beos - ;; - *-haiku) - os=-haiku - ;; - *-ibm) - os=-aix - ;; - *-knuth) - os=-mmixware - ;; - *-wec) - os=-proelf - ;; - *-winbond) - os=-proelf - ;; - *-oki) - os=-proelf - ;; - *-hp) - os=-hpux - ;; - *-hitachi) - os=-hiux - ;; - i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=-sysv - ;; - *-cbm) - os=-amigaos - ;; - *-dg) - os=-dgux - ;; - *-dolphin) - os=-sysv3 - ;; - m68k-ccur) - os=-rtu - ;; - m88k-omron*) - os=-luna - ;; - *-next ) - os=-nextstep - ;; - *-sequent) - os=-ptx - ;; - *-crds) - os=-unos - ;; - *-ns) - os=-genix - ;; - i370-*) - os=-mvs - ;; - *-next) - os=-nextstep3 - ;; - *-gould) - os=-sysv - ;; - *-highlevel) - os=-bsd - ;; - *-encore) - os=-bsd - ;; - *-sgi) - os=-irix - ;; - *-siemens) - os=-sysv4 - ;; - *-masscomp) - os=-rtu - ;; - f30[01]-fujitsu | f700-fujitsu) - os=-uxpv - ;; - *-rom68k) - os=-coff - ;; - *-*bug) - os=-coff - ;; - *-apple) - os=-macos - ;; - *-atari*) - os=-mint - ;; - *) - os=-none - ;; -esac -fi - -# Here we handle the case where we know the os, and the CPU type, but not the -# manufacturer. We pick the logical manufacturer. -vendor=unknown -case $basic_machine in - *-unknown) - case $os in - -riscix*) - vendor=acorn - ;; - -sunos*) - vendor=sun - ;; - -aix*) - vendor=ibm - ;; - -beos*) - vendor=be - ;; - -hpux*) - vendor=hp - ;; - -mpeix*) - vendor=hp - ;; - -hiux*) - vendor=hitachi - ;; - -unos*) - vendor=crds - ;; - -dgux*) - vendor=dg - ;; - -luna*) - vendor=omron - ;; - -genix*) - vendor=ns - ;; - -mvs* | -opened*) - vendor=ibm - ;; - -os400*) - vendor=ibm - ;; - -ptx*) - vendor=sequent - ;; - -tpf*) - vendor=ibm - ;; - -vxsim* | -vxworks* | -windiss*) - vendor=wrs - ;; - -aux*) - vendor=apple - ;; - -hms*) - vendor=hitachi - ;; - -mpw* | -macos*) - vendor=apple - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - vendor=atari - ;; - -vos*) - vendor=stratus - ;; - esac - basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` - ;; -esac - -echo $basic_machine$os -exit - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/bundled/tdb/configure.ac b/bundled/tdb/configure.ac deleted file mode 100644 index 2843d98e..00000000 --- a/bundled/tdb/configure.ac +++ /dev/null @@ -1,51 +0,0 @@ -AC_PREREQ(2.50) -AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""]) -AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""]) -AC_DEFUN([SMB_ENABLE], [echo -n ""]) -AC_INIT(tdb, 1.2.3) -AC_CONFIG_SRCDIR([common/tdb.c]) -AC_CONFIG_HEADER(include/config.h) -AC_LIBREPLACE_ALL_CHECKS -AC_LD_SONAMEFLAG -AC_LD_VERSIONSCRIPT -AC_LD_PICFLAG -AC_LD_SHLIBEXT -AC_LIBREPLACE_SHLD -AC_LIBREPLACE_SHLD_FLAGS -AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR -m4_include(libtdb.m4) -AC_PATH_PROGS([PYTHON_CONFIG], [python2.6-config python2.5-config python2.4-config python-config]) -AC_PATH_PROGS([PYTHON], [python2.6 python2.5 python2.4 python]) - -PYTHON_BUILD_TARGET="build-python" -PYTHON_INSTALL_TARGET="install-python" -PYTHON_CHECK_TARGET="check-python" -AC_SUBST(PYTHON_BUILD_TARGET) -AC_SUBST(PYTHON_INSTALL_TARGET) -AC_SUBST(PYTHON_CHECK_TARGET) -if test -z "$PYTHON_CONFIG"; then - PYTHON_BUILD_TARGET="" - PYTHON_INSTALL_TARGET="" - PYTHON_CHECK_TARGET="" -fi - -AC_ARG_ENABLE(python, - AS_HELP_STRING([--enable-python], [Enables python binding]), - [ if test "x$enableval" = "xno" ; then - PYTHON_BUILD_TARGET="" - PYTHON_INSTALL_TARGET="" - PYTHON_CHECK_TARGET="" - fi - ]) - -AC_PATH_PROG(XSLTPROC,xsltproc) -DOC_TARGET="" -if test -n "$XSLTPROC"; then - DOC_TARGET=doc -fi -AC_SUBST(DOC_TARGET) - -m4_include(build_macros.m4) -BUILD_WITH_SHARED_BUILD_DIR - -AC_OUTPUT(Makefile tdb.pc) diff --git a/bundled/tdb/docs/README b/bundled/tdb/docs/README deleted file mode 100644 index fe0e2581..00000000 --- a/bundled/tdb/docs/README +++ /dev/null @@ -1,273 +0,0 @@ -tdb - a trivial database system -tridge@linuxcare.com December 1999 -================================== - -This is a simple database API. It was inspired by the realisation that -in Samba we have several ad-hoc bits of code that essentially -implement small databases for sharing structures between parts of -Samba. As I was about to add another I realised that a generic -database module was called for to replace all the ad-hoc bits. - -I based the interface on gdbm. I couldn't use gdbm as we need to be -able to have multiple writers to the databases at one time. - -Compilation ------------ - -add HAVE_MMAP=1 to use mmap instead of read/write -add NOLOCK=1 to disable locking code - -Testing -------- - -Compile tdbtest.c and link with gdbm for testing. tdbtest will perform -identical operations via tdb and gdbm then make sure the result is the -same - -Also included is tdbtool, which allows simple database manipulation -on the commandline. - -tdbtest and tdbtool are not built as part of Samba, but are included -for completeness. - -Interface ---------- - -The interface is very similar to gdbm except for the following: - -- different open interface. The tdb_open call is more similar to a - traditional open() -- no tdbm_reorganise() function -- no tdbm_sync() function. No operations are cached in the library anyway -- added a tdb_traverse() function for traversing the whole database -- added transactions support - -A general rule for using tdb is that the caller frees any returned -TDB_DATA structures. Just call free(p.dptr) to free a TDB_DATA -return value called p. This is the same as gdbm. - -here is a full list of tdb functions with brief descriptions. - - ----------------------------------------------------------------------- -TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode) - - open the database, creating it if necessary - - The open_flags and mode are passed straight to the open call on the database - file. A flags value of O_WRONLY is invalid - - The hash size is advisory, use zero for a default value. - - return is NULL on error - - possible tdb_flags are: - TDB_CLEAR_IF_FIRST - clear database if we are the only one with it open - TDB_INTERNAL - don't use a file, instaed store the data in - memory. The filename is ignored in this case. - TDB_NOLOCK - don't do any locking - TDB_NOMMAP - don't use mmap - TDB_NOSYNC - don't synchronise transactions to disk - TDB_SEQNUM - maintain a sequence number - TDB_VOLATILE - activate the per-hashchain freelist, default 5 - TDB_ALLOW_NESTING - allow transactions to nest - TDB_DISALLOW_NESTING - disallow transactions to nest - ----------------------------------------------------------------------- -TDB_CONTEXT *tdb_open_ex(char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode, - const struct tdb_logging_context *log_ctx, - tdb_hash_func hash_fn) - -This is like tdb_open(), but allows you to pass an initial logging and -hash function. Be careful when passing a hash function - all users of -the database must use the same hash function or you will get data -corruption. - - ----------------------------------------------------------------------- -char *tdb_error(TDB_CONTEXT *tdb); - - return a error string for the last tdb error - ----------------------------------------------------------------------- -int tdb_close(TDB_CONTEXT *tdb); - - close a database - ----------------------------------------------------------------------- -TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key); - - fetch an entry in the database given a key - if the return value has a null dptr then a error occurred - - caller must free the resulting data - ----------------------------------------------------------------------- -int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data); - - Hand a record to a parser function without allocating it. - - This function is meant as a fast tdb_fetch alternative for large records - that are frequently read. The "key" and "data" arguments point directly - into the tdb shared memory, they are not aligned at any boundary. - - WARNING: The parser is called while tdb holds a lock on the record. DO NOT - call other tdb routines from within the parser. Also, for good performance - you should make the parser fast to allow parallel operations. - - tdb_parse_record returns -1 if the record was not found. If the record was - found, the return value of "parser" is passed up to the caller. - ----------------------------------------------------------------------- -int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key); - - check if an entry in the database exists - - note that 1 is returned if the key is found and 0 is returned if not found - this doesn't match the conventions in the rest of this module, but is - compatible with gdbm - ----------------------------------------------------------------------- -int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, - TDB_DATA key, TDB_DATA dbuf, void *state), void *state); - - traverse the entire database - calling fn(tdb, key, data, state) on each - element. - - return -1 on error or the record count traversed - - if fn is NULL then it is not called - - a non-zero return value from fn() indicates that the traversal - should stop. Traversal callbacks may not start transactions. - - WARNING: The data buffer given to the callback fn does NOT meet the - alignment restrictions malloc gives you. - ----------------------------------------------------------------------- -int tdb_traverse_read(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, - TDB_DATA key, TDB_DATA dbuf, void *state), void *state); - - traverse the entire database - calling fn(tdb, key, data, state) on - each element, but marking the database read only during the - traversal, so any write operations will fail. This allows tdb to - use read locks, which increases the parallelism possible during the - traversal. - - return -1 on error or the record count traversed - - if fn is NULL then it is not called - - a non-zero return value from fn() indicates that the traversal - should stop. Traversal callbacks may not start transactions. - ----------------------------------------------------------------------- -TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb); - - find the first entry in the database and return its key - - the caller must free the returned data - ----------------------------------------------------------------------- -TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key); - - find the next entry in the database, returning its key - - the caller must free the returned data - ----------------------------------------------------------------------- -int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key); - - delete an entry in the database given a key - ----------------------------------------------------------------------- -int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag); - - store an element in the database, replacing any existing element - with the same key - - If flag==TDB_INSERT then don't overwrite an existing entry - If flag==TDB_MODIFY then don't create a new entry - - return 0 on success, -1 on failure - ----------------------------------------------------------------------- -int tdb_writelock(TDB_CONTEXT *tdb); - - lock the database. If we already have it locked then don't do anything - ----------------------------------------------------------------------- -int tdb_writeunlock(TDB_CONTEXT *tdb); - unlock the database - ----------------------------------------------------------------------- -int tdb_lockchain(TDB_CONTEXT *tdb, TDB_DATA key); - - lock one hash chain. This is meant to be used to reduce locking - contention - it cannot guarantee how many records will be locked - ----------------------------------------------------------------------- -int tdb_unlockchain(TDB_CONTEXT *tdb, TDB_DATA key); - - unlock one hash chain - ----------------------------------------------------------------------- -int tdb_transaction_start(TDB_CONTEXT *tdb) - - start a transaction. All operations after the transaction start can - either be committed with tdb_transaction_commit() or cancelled with - tdb_transaction_cancel(). - - If you call tdb_transaction_start() again on the same tdb context - while a transaction is in progress, then the same transaction - buffer is re-used. The number of tdb_transaction_{commit,cancel} - operations must match the number of successful - tdb_transaction_start() calls. - - Note that transactions are by default disk synchronous, and use a - recover area in the database to automatically recover the database - on the next open if the system crashes during a transaction. You - can disable the synchronous transaction recovery setup using the - TDB_NOSYNC flag, which will greatly speed up operations at the risk - of corrupting your database if the system crashes. - - Operations made within a transaction are not visible to other users - of the database until a successful commit. - ----------------------------------------------------------------------- -int tdb_transaction_cancel(TDB_CONTEXT *tdb) - - cancel a current transaction, discarding all write and lock - operations that have been made since the transaction started. - - ----------------------------------------------------------------------- -int tdb_transaction_commit(TDB_CONTEXT *tdb) - - commit a current transaction, updating the database and releasing - the transaction locks. - ----------------------------------------------------------------------- -int tdb_transaction_prepare_commit(TDB_CONTEXT *tdb) - - prepare to commit a current transaction, for two-phase commits. - Once prepared for commit, the only allowed calls are - tdb_transaction_commit() or tdb_transaction_cancel(). Preparing - allocates disk space for the pending updates, so a subsequent - commit should succeed (barring any hardware failures). - ----------------------------------------------------------------------- -int tdb_check(TDB_CONTEXT *tdb, - int (*check)(TDB_DATA key, TDB_DATA data, void *private_data), - void *private_data);) - - check the consistency of the database, calling back the check function - (if non-NULL) with each record. If some consistency check fails, or - the supplied check function returns -1, tdb_check returns -1, otherwise - 0. Note that logging function (if set) will be called with additional - information on the corruption found. diff --git a/bundled/tdb/docs/tdb.magic b/bundled/tdb/docs/tdb.magic deleted file mode 100644 index f5619e73..00000000 --- a/bundled/tdb/docs/tdb.magic +++ /dev/null @@ -1,10 +0,0 @@ -# Magic file(1) information about tdb files. -# -# Install this into /etc/magic or the corresponding location for your -# system, or pass as a -m argument to file(1). - -# You may use and redistribute this file without restriction. - -0 string TDB\ file TDB database ->32 lelong =0x2601196D version 6, little-endian ->>36 lelong x hash size %d bytes diff --git a/bundled/tdb/docs/tracing.txt b/bundled/tdb/docs/tracing.txt deleted file mode 100644 index 98c5db9a..00000000 --- a/bundled/tdb/docs/tracing.txt +++ /dev/null @@ -1,46 +0,0 @@ -How And Why To Use TDB Tracing -============================== - -You can trace all TDB operations, using TDB_TRACE. It is not complete -(error conditions which expect to the logged will not always be traced -correctly, so you should set up a logging function too), but is designed -to collect benchmark-style traces to allow us to optimize TDB. - -Note: tracing is not efficient, and the trace files are huge: a -traverse of the database is particularly large! But they compress very -well with rzip (http://rzip.samba.org) - -How to gather trace files: --------------------------- -1) Uncomment /* #define TDB_TRACE 1 */ in tdb_private.h. -2) Rebuild TDB, and everything that uses it. -3) Run something. - -Your trace files will be called .trace.. These files -will not be overwritten: if the same process reopens the same TDB, an -error will be logged and tracing will be disabled. - -How to replay trace files: --------------------------- -1) For benchmarking, remember to rebuild tdb with #define TDB_TRACE commented - out again! -2) Grab the latest "replace_trace.c" from CCAN's tdb module (tools/ dir): - http://ccan.ozlabs.org/tarballs/tdb.tar.bz2 -3) Compile up replay_trace, munging as necessary. -4) Run replay_trace ... - -If given more than one trace file (presumably from the same tdb) -replay_trace will try to figure out the dependencies between the operations -and fire off a child to run each trace. Occasionally it gets stuck, in -which case it will add another dependency and retry. Eventually it will -give a speed value. - -replay_trace can intuit the existence of previous data in the tdb (ie. -activity prior to the trace(s) supplied) and will prepopulate as -neccessary. - -You can run --quiet for straight benchmark results, and -n to run multiple -times (this saves time, since it need only calculate dependencies once). - -Good luck! -Rusty Russell diff --git a/bundled/tdb/include/tdb.h b/bundled/tdb/include/tdb.h deleted file mode 100644 index 050f398e..00000000 --- a/bundled/tdb/include/tdb.h +++ /dev/null @@ -1,176 +0,0 @@ -#ifndef __TDB_H__ -#define __TDB_H__ - -/* - Unix SMB/CIFS implementation. - - trivial database library - - Copyright (C) Andrew Tridgell 1999-2004 - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "signal.h" - -/* flags to tdb_store() */ -#define TDB_REPLACE 1 /* Unused */ -#define TDB_INSERT 2 /* Don't overwrite an existing entry */ -#define TDB_MODIFY 3 /* Don't create an existing entry */ - -/* flags for tdb_open() */ -#define TDB_DEFAULT 0 /* just a readability place holder */ -#define TDB_CLEAR_IF_FIRST 1 -#define TDB_INTERNAL 2 /* don't store on disk */ -#define TDB_NOLOCK 4 /* don't do any locking */ -#define TDB_NOMMAP 8 /* don't use mmap */ -#define TDB_CONVERT 16 /* convert endian (internal use) */ -#define TDB_BIGENDIAN 32 /* header is big-endian (internal use) */ -#define TDB_NOSYNC 64 /* don't use synchronous transactions */ -#define TDB_SEQNUM 128 /* maintain a sequence number */ -#define TDB_VOLATILE 256 /* Activate the per-hashchain freelist, default 5 */ -#define TDB_ALLOW_NESTING 512 /* Allow transactions to nest */ -#define TDB_DISALLOW_NESTING 1024 /* Disallow transactions to nest */ - -/* error codes */ -enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK, - TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT, - TDB_ERR_NOEXIST, TDB_ERR_EINVAL, TDB_ERR_RDONLY, - TDB_ERR_NESTING}; - -/* debugging uses one of the following levels */ -enum tdb_debug_level {TDB_DEBUG_FATAL = 0, TDB_DEBUG_ERROR, - TDB_DEBUG_WARNING, TDB_DEBUG_TRACE}; - -typedef struct TDB_DATA { - unsigned char *dptr; - size_t dsize; -} TDB_DATA; - -#ifndef PRINTF_ATTRIBUTE -#if (__GNUC__ >= 3) -/** Use gcc attribute to check printf fns. a1 is the 1-based index of - * the parameter containing the format, and a2 the index of the first - * argument. Note that some gcc 2.x versions don't handle this - * properly **/ -#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2))) -#else -#define PRINTF_ATTRIBUTE(a1, a2) -#endif -#endif - -/* this is the context structure that is returned from a db open */ -typedef struct tdb_context TDB_CONTEXT; - -typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *); -typedef void (*tdb_log_func)(struct tdb_context *, enum tdb_debug_level, const char *, ...) PRINTF_ATTRIBUTE(3, 4); -typedef unsigned int (*tdb_hash_func)(TDB_DATA *key); - -struct tdb_logging_context { - tdb_log_func log_fn; - void *log_private; -}; - -_PUBLIC_ struct tdb_context *tdb_open(const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode); -_PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode, - const struct tdb_logging_context *log_ctx, - tdb_hash_func hash_fn); -_PUBLIC_ void tdb_set_max_dead(struct tdb_context *tdb, int max_dead); - -_PUBLIC_ int tdb_reopen(struct tdb_context *tdb); -_PUBLIC_ int tdb_reopen_all(int parent_longlived); -_PUBLIC_ void tdb_set_logging_function(struct tdb_context *tdb, const struct tdb_logging_context *log_ctx); -_PUBLIC_ enum TDB_ERROR tdb_error(struct tdb_context *tdb); -_PUBLIC_ const char *tdb_errorstr(struct tdb_context *tdb); -_PUBLIC_ TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key); -_PUBLIC_ int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data); -_PUBLIC_ int tdb_delete(struct tdb_context *tdb, TDB_DATA key); -_PUBLIC_ int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag); -_PUBLIC_ int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf); -_PUBLIC_ int tdb_close(struct tdb_context *tdb); -_PUBLIC_ TDB_DATA tdb_firstkey(struct tdb_context *tdb); -_PUBLIC_ TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key); -_PUBLIC_ int tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *); -_PUBLIC_ int tdb_traverse_read(struct tdb_context *tdb, tdb_traverse_func fn, void *); -_PUBLIC_ int tdb_exists(struct tdb_context *tdb, TDB_DATA key); -_PUBLIC_ int tdb_lockall(struct tdb_context *tdb); -_PUBLIC_ int tdb_lockall_nonblock(struct tdb_context *tdb); -_PUBLIC_ int tdb_unlockall(struct tdb_context *tdb); -_PUBLIC_ int tdb_lockall_read(struct tdb_context *tdb); -_PUBLIC_ int tdb_lockall_read_nonblock(struct tdb_context *tdb); -_PUBLIC_ int tdb_unlockall_read(struct tdb_context *tdb); -_PUBLIC_ int tdb_lockall_mark(struct tdb_context *tdb); -_PUBLIC_ int tdb_lockall_unmark(struct tdb_context *tdb); -_PUBLIC_ const char *tdb_name(struct tdb_context *tdb); -_PUBLIC_ int tdb_fd(struct tdb_context *tdb); -_PUBLIC_ tdb_log_func tdb_log_fn(struct tdb_context *tdb); -_PUBLIC_ void *tdb_get_logging_private(struct tdb_context *tdb); -_PUBLIC_ int tdb_transaction_start(struct tdb_context *tdb); -_PUBLIC_ int tdb_transaction_start_nonblock(struct tdb_context *tdb); -_PUBLIC_ int tdb_transaction_prepare_commit(struct tdb_context *tdb); -_PUBLIC_ int tdb_transaction_commit(struct tdb_context *tdb); -_PUBLIC_ int tdb_transaction_cancel(struct tdb_context *tdb); -_PUBLIC_ int tdb_get_seqnum(struct tdb_context *tdb); -_PUBLIC_ int tdb_hash_size(struct tdb_context *tdb); -_PUBLIC_ size_t tdb_map_size(struct tdb_context *tdb); -_PUBLIC_ int tdb_get_flags(struct tdb_context *tdb); -_PUBLIC_ void tdb_add_flags(struct tdb_context *tdb, unsigned flag); -_PUBLIC_ void tdb_remove_flags(struct tdb_context *tdb, unsigned flag); -_PUBLIC_ void tdb_enable_seqnum(struct tdb_context *tdb); -_PUBLIC_ void tdb_increment_seqnum_nonblock(struct tdb_context *tdb); -_PUBLIC_ int tdb_check(struct tdb_context *tdb, - int (*check) (TDB_DATA key, TDB_DATA data, void *private_data), - void *private_data); - -/* Low level locking functions: use with care */ -_PUBLIC_ int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key); -_PUBLIC_ int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key); -_PUBLIC_ int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key); -_PUBLIC_ int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key); -_PUBLIC_ int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key); -_PUBLIC_ int tdb_chainlock_mark(struct tdb_context *tdb, TDB_DATA key); -_PUBLIC_ int tdb_chainlock_unmark(struct tdb_context *tdb, TDB_DATA key); - -_PUBLIC_ void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *sigptr); - -/* wipe and repack */ -_PUBLIC_ int tdb_wipe_all(struct tdb_context *tdb); -_PUBLIC_ int tdb_repack(struct tdb_context *tdb); - -/* Debug functions. Not used in production. */ -_PUBLIC_ void tdb_dump_all(struct tdb_context *tdb); -_PUBLIC_ int tdb_printfreelist(struct tdb_context *tdb); -_PUBLIC_ int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries); -_PUBLIC_ int tdb_freelist_size(struct tdb_context *tdb); - -_PUBLIC_ extern TDB_DATA tdb_null; - -#ifdef __cplusplus -} -#endif - -#endif /* tdb.h */ diff --git a/bundled/tdb/install-sh b/bundled/tdb/install-sh deleted file mode 100755 index 58719246..00000000 --- a/bundled/tdb/install-sh +++ /dev/null @@ -1,238 +0,0 @@ -#! /bin/sh -# -# install - install a program, script, or datafile -# This comes from X11R5. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. -# - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -transformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 -else - true -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d $dst ]; then - instcmd=: - else - instcmd=mkdir - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f $src -o -d $src ] - then - true - else - echo "install: $src does not exist" - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "install: no destination specified" - exit 1 - else - true - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d $dst ] - then - dst="$dst"/`basename $src` - else - true - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' -' -IFS="${IFS-${defaultIFS}}" - -oIFS="${IFS}" -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS="${oIFS}" - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp="${pathcomp}${1}" - shift - - if [ ! -d "${pathcomp}" ] ; - then - $mkdirprog "${pathcomp}" - else - true - fi - - pathcomp="${pathcomp}/" -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd $dst && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename $dst` - else - dstfile=`basename $dst $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename $dst` - else - true - fi - -# Make a temp file name in the proper directory. - - dsttmp=$dstdir/#inst.$$# - -# Move or copy the file name to the temp name - - $doit $instcmd $src $dsttmp && - - trap "rm -f ${dsttmp}" 0 && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && - -# Now rename the file to the real destination. - - $doit $rmcmd -f $dstdir/$dstfile && - $doit $mvcmd $dsttmp $dstdir/$dstfile - -fi && - - -exit 0 diff --git a/bundled/tdb/libtdb.m4 b/bundled/tdb/libtdb.m4 deleted file mode 100644 index fb8913aa..00000000 --- a/bundled/tdb/libtdb.m4 +++ /dev/null @@ -1,41 +0,0 @@ -dnl find the tdb sources. This is meant to work both for -dnl tdb standalone builds, and builds of packages using tdb -tdbdir="" -tdbpaths=". lib/tdb tdb ../tdb ../lib/tdb" -for d in $tdbpaths; do - if test -f "$srcdir/$d/common/tdb.c"; then - tdbdir="$d" - AC_SUBST(tdbdir) - break; - fi -done -if test x"$tdbdir" = "x"; then - AC_MSG_ERROR([cannot find tdb source in $tdbpaths]) -fi -TDB_OBJ="common/tdb.o common/dump.o common/transaction.o common/error.o common/traverse.o" -TDB_OBJ="$TDB_OBJ common/freelist.o common/freelistcheck.o common/io.o common/lock.o common/open.o common/check.o" -AC_SUBST(TDB_OBJ) -AC_SUBST(LIBREPLACEOBJ) - -TDB_LIBS="" -AC_SUBST(TDB_LIBS) - -TDB_DEPS="" -if test x$libreplace_cv_HAVE_FDATASYNC_IN_LIBRT = xyes ; then - TDB_DEPS="$TDB_DEPS -lrt" -fi -AC_SUBST(TDB_DEPS) - -TDB_CFLAGS="-I$tdbdir/include" -AC_SUBST(TDB_CFLAGS) - -AC_CHECK_FUNCS(mmap pread pwrite getpagesize utime) -AC_CHECK_HEADERS(getopt.h sys/select.h sys/time.h) - -AC_HAVE_DECL(pread, [#include ]) -AC_HAVE_DECL(pwrite, [#include ]) - -if test x"$VERSIONSCRIPT" != "x"; then - EXPORTSFILE=tdb.exports - AC_SUBST(EXPORTSFILE) -fi diff --git a/bundled/tdb/manpages/tdbbackup.8.xml b/bundled/tdb/manpages/tdbbackup.8.xml deleted file mode 100644 index 78fe32eb..00000000 --- a/bundled/tdb/manpages/tdbbackup.8.xml +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - tdbbackup - 8 - Samba - System Administration tools - 3.6 - - - - - tdbbackup - tool for backing up and for validating the integrity of samba .tdb files - - - - - tdbbackup - -s suffix - -v - -h - - - - - DESCRIPTION - - This tool is part of the samba - 1 suite. - - tdbbackup is a tool that may be used to backup samba .tdb - files. This tool may also be used to verify the integrity of the .tdb files prior - to samba startup or during normal operation. If it finds file damage and it finds - a prior backup the backup file will be restored. - - - - - - OPTIONS - - - - - -h - - Get help information. - - - - - -s suffix - - The -s option allows the adminisistrator to specify a file - backup extension. This way it is possible to keep a history of tdb backup - files by using a new suffix for each backup. - - - - - -v - - The -v will check the database for damages (currupt data) - which if detected causes the backup to be restored. - - - - - - - - - COMMANDS - - GENERAL INFORMATION - - - The tdbbackup utility can safely be run at any time. It was designed so - that it can be used at any time to validate the integrity of tdb files, even during Samba - operation. Typical usage for the command will be: - - - tdbbackup [-s suffix] *.tdb - - - Before restarting samba the following command may be run to validate .tdb files: - - - tdbbackup -v [-s suffix] *.tdb - - - Samba .tdb files are stored in various locations, be sure to run backup all - .tdb file on the system. Important files includes: - - - - - secrets.tdb - usual location is in the /usr/local/samba/private - directory, or on some systems in /etc/samba. - - - - passdb.tdb - usual location is in the /usr/local/samba/private - directory, or on some systems in /etc/samba. - - - - *.tdb located in the /usr/local/samba/var directory or on some - systems in the /var/cache or /var/lib/samba directories. - - - - - - - VERSION - - This man page is correct for version 3 of the Samba suite. - - - - AUTHOR - - - The original Samba software and related utilities were created by Andrew Tridgell. - Samba is now developed by the Samba Team as an Open Source project similar to the way - the Linux kernel is developed. - - - The tdbbackup man page was written by John H Terpstra. - - - diff --git a/bundled/tdb/manpages/tdbdump.8.xml b/bundled/tdb/manpages/tdbdump.8.xml deleted file mode 100644 index 90465e53..00000000 --- a/bundled/tdb/manpages/tdbdump.8.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - tdbdump - 8 - Samba - System Administration tools - 3.6 - - - - - tdbdump - tool for printing the contents of a TDB file - - - - - tdbdump - filename - - - - - DESCRIPTION - - This tool is part of the samba - 1 suite. - - tdbdump is a very simple utility that 'dumps' the - contents of a TDB (Trivial DataBase) file to standard output in a - human-readable format. - - - This tool can be used when debugging problems with TDB files. It is - intended for those who are somewhat familiar with Samba internals. - - - - - - VERSION - - This man page is correct for version 3 of the Samba suite. - - - - AUTHOR - - - The original Samba software and related utilities were created by Andrew Tridgell. - Samba is now developed by the Samba Team as an Open Source project similar to the way - the Linux kernel is developed. - - - The tdbdump man page was written by Jelmer Vernooij. - - - diff --git a/bundled/tdb/manpages/tdbtool.8.xml b/bundled/tdb/manpages/tdbtool.8.xml deleted file mode 100644 index 9f96db27..00000000 --- a/bundled/tdb/manpages/tdbtool.8.xml +++ /dev/null @@ -1,235 +0,0 @@ - - - - - - tdbtool - 8 - Samba - System Administration tools - 3.6 - - - - - tdbtool - manipulate the contents TDB files - - - - - - tdbtool - - - - tdbtool - - TDBFILE - - - COMMANDS - - - - - - - DESCRIPTION - - This tool is part of the - samba - 1 suite. - - tdbtool a tool for displaying and - altering the contents of Samba TDB (Trivial DataBase) files. Each - of the commands listed below can be entered interactively or - provided on the command line. - - - - - - COMMANDS - - - - - - TDBFILE - Create a new database named - TDBFILE. - - - - - - TDBFILE - Open an existing database named - TDBFILE. - - - - - - Erase the current database. - - - - - - Dump the current database as strings. - - - - - - Dump the current database as connection records. - - - - - - Dump the current database keys as strings. - - - - - - Dump the current database keys as hex values. - - - - - - Print summary information about the - current database. - - - - - - KEY - DATA - - Insert a record into the - current database. - - - - - - KEY - TDBFILE - - Move a record from the - current database into TDBFILE. - - - - - - KEY - DATA - - Store (replace) a record in the - current database. - - - - - - KEY - - Show a record by key. - - - - - - KEY - - Delete a record by key. - - - - - - - Print the current database hash table and free list. - - - - - - - Print the current database and free list. - - - - - - COMMAND - - Execute the given system command. - - - - - - - - Print the first record in the current database. - - - - - - - - Print the next record in the current database. - - - - - - - - Check the integrity of the current database. - - - - - - - - Exit tdbtool. - - - - - - - - CAVEATS - The contents of the Samba TDB files are private - to the implementation and should not be altered with - tdbtool. - - - - - VERSION - This man page is correct for version 3.0.25 of the Samba suite. - - - - AUTHOR - - The original Samba software and related utilities were - created by Andrew Tridgell. Samba is now developed by the - Samba Team as an Open Source project similar to the way the - Linux kernel is developed. - - - diff --git a/bundled/tdb/pytdb.c b/bundled/tdb/pytdb.c deleted file mode 100644 index 7a9205b8..00000000 --- a/bundled/tdb/pytdb.c +++ /dev/null @@ -1,506 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - Python interface to tdb. - - Copyright (C) 2004-2006 Tim Potter - Copyright (C) 2007-2008 Jelmer Vernooij - - ** NOTE! The following LGPL license applies to the tdb - ** library. This does NOT imply that all of Samba is released - ** under the LGPL - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 3 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . -*/ - -#include "replace.h" -#include "system/filesys.h" - -#include -#ifndef Py_RETURN_NONE -#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None -#endif - -/* Include tdb headers */ -#include - -typedef struct { - PyObject_HEAD - TDB_CONTEXT *ctx; - bool closed; -} PyTdbObject; - -PyAPI_DATA(PyTypeObject) PyTdb; - -static void PyErr_SetTDBError(TDB_CONTEXT *tdb) -{ - PyErr_SetObject(PyExc_RuntimeError, - Py_BuildValue("(i,s)", tdb_error(tdb), tdb_errorstr(tdb))); -} - -static TDB_DATA PyString_AsTDB_DATA(PyObject *data) -{ - TDB_DATA ret; - ret.dptr = (unsigned char *)PyString_AsString(data); - ret.dsize = PyString_Size(data); - return ret; -} - -static PyObject *PyString_FromTDB_DATA(TDB_DATA data) -{ - if (data.dptr == NULL && data.dsize == 0) { - Py_RETURN_NONE; - } else { - PyObject *ret = PyString_FromStringAndSize((const char *)data.dptr, - data.dsize); - free(data.dptr); - return ret; - } -} - -#define PyErr_TDB_ERROR_IS_ERR_RAISE(ret, tdb) \ - if (ret != 0) { \ - PyErr_SetTDBError(tdb); \ - return NULL; \ - } - -static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwargs) -{ - char *name; - int hash_size = 0, tdb_flags = TDB_DEFAULT, flags = O_RDWR, mode = 0600; - TDB_CONTEXT *ctx; - PyTdbObject *ret; - const char *kwnames[] = { "name", "hash_size", "tdb_flags", "flags", "mode", NULL }; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", (char **)kwnames, &name, &hash_size, &tdb_flags, &flags, &mode)) - return NULL; - - ctx = tdb_open(name, hash_size, tdb_flags, flags, mode); - if (ctx == NULL) { - PyErr_SetFromErrno(PyExc_IOError); - return NULL; - } - - ret = PyObject_New(PyTdbObject, &PyTdb); - ret->ctx = ctx; - ret->closed = false; - return (PyObject *)ret; -} - -static PyObject *obj_transaction_cancel(PyTdbObject *self) -{ - int ret = tdb_transaction_cancel(self->ctx); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_transaction_commit(PyTdbObject *self) -{ - int ret = tdb_transaction_commit(self->ctx); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_transaction_start(PyTdbObject *self) -{ - int ret = tdb_transaction_start(self->ctx); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_reopen(PyTdbObject *self) -{ - int ret = tdb_reopen(self->ctx); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_lockall(PyTdbObject *self) -{ - int ret = tdb_lockall(self->ctx); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_unlockall(PyTdbObject *self) -{ - int ret = tdb_unlockall(self->ctx); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_lockall_read(PyTdbObject *self) -{ - int ret = tdb_lockall_read(self->ctx); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_unlockall_read(PyTdbObject *self) -{ - int ret = tdb_unlockall_read(self->ctx); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_close(PyTdbObject *self) -{ - int ret; - if (self->closed) - Py_RETURN_NONE; - ret = tdb_close(self->ctx); - self->closed = true; - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_get(PyTdbObject *self, PyObject *args) -{ - TDB_DATA key; - PyObject *py_key; - if (!PyArg_ParseTuple(args, "O", &py_key)) - return NULL; - - key = PyString_AsTDB_DATA(py_key); - - return PyString_FromTDB_DATA(tdb_fetch(self->ctx, key)); -} - -static PyObject *obj_append(PyTdbObject *self, PyObject *args) -{ - TDB_DATA key, data; - PyObject *py_key, *py_data; - int ret; - if (!PyArg_ParseTuple(args, "OO", &py_key, &py_data)) - return NULL; - - key = PyString_AsTDB_DATA(py_key); - data = PyString_AsTDB_DATA(py_data); - - ret = tdb_append(self->ctx, key, data); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_firstkey(PyTdbObject *self) -{ - return PyString_FromTDB_DATA(tdb_firstkey(self->ctx)); -} - -static PyObject *obj_nextkey(PyTdbObject *self, PyObject *args) -{ - TDB_DATA key; - PyObject *py_key; - if (!PyArg_ParseTuple(args, "O", &py_key)) - return NULL; - - key = PyString_AsTDB_DATA(py_key); - - return PyString_FromTDB_DATA(tdb_nextkey(self->ctx, key)); -} - -static PyObject *obj_delete(PyTdbObject *self, PyObject *args) -{ - TDB_DATA key; - PyObject *py_key; - int ret; - if (!PyArg_ParseTuple(args, "O", &py_key)) - return NULL; - - key = PyString_AsTDB_DATA(py_key); - ret = tdb_delete(self->ctx, key); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyObject *obj_has_key(PyTdbObject *self, PyObject *args) -{ - TDB_DATA key; - int ret; - PyObject *py_key; - if (!PyArg_ParseTuple(args, "O", &py_key)) - return NULL; - - key = PyString_AsTDB_DATA(py_key); - ret = tdb_exists(self->ctx, key); - if (ret != TDB_ERR_NOEXIST) { - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - } - - return (ret == TDB_ERR_NOEXIST)?Py_False:Py_True; -} - -static PyObject *obj_store(PyTdbObject *self, PyObject *args) -{ - TDB_DATA key, value; - int ret; - int flag = TDB_REPLACE; - PyObject *py_key, *py_value; - - if (!PyArg_ParseTuple(args, "OO|i", &py_key, &py_value, &flag)) - return NULL; - - key = PyString_AsTDB_DATA(py_key); - value = PyString_AsTDB_DATA(py_value); - - ret = tdb_store(self->ctx, key, value, flag); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - - -typedef struct { - PyObject_HEAD - TDB_DATA current; - PyTdbObject *iteratee; -} PyTdbIteratorObject; - -static PyObject *tdb_iter_next(PyTdbIteratorObject *self) -{ - TDB_DATA current; - PyObject *ret; - if (self->current.dptr == NULL && self->current.dsize == 0) - return NULL; - current = self->current; - self->current = tdb_nextkey(self->iteratee->ctx, self->current); - ret = PyString_FromTDB_DATA(current); - return ret; -} - -static void tdb_iter_dealloc(PyTdbIteratorObject *self) -{ - Py_DECREF(self->iteratee); - PyObject_Del(self); -} - -PyTypeObject PyTdbIterator = { - .tp_name = "Iterator", - .tp_basicsize = sizeof(PyTdbIteratorObject), - .tp_iternext = (iternextfunc)tdb_iter_next, - .tp_dealloc = (destructor)tdb_iter_dealloc, - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_iter = PyObject_SelfIter, -}; - -static PyObject *tdb_object_iter(PyTdbObject *self) -{ - PyTdbIteratorObject *ret; - - ret = PyObject_New(PyTdbIteratorObject, &PyTdbIterator); - ret->current = tdb_firstkey(self->ctx); - ret->iteratee = self; - Py_INCREF(self); - return (PyObject *)ret; -} - -static PyObject *obj_clear(PyTdbObject *self) -{ - int ret = tdb_wipe_all(self->ctx); - PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx); - Py_RETURN_NONE; -} - -static PyMethodDef tdb_object_methods[] = { - { "transaction_cancel", (PyCFunction)obj_transaction_cancel, METH_NOARGS, - "S.transaction_cancel() -> None\n" - "Cancel the currently active transaction." }, - { "transaction_commit", (PyCFunction)obj_transaction_commit, METH_NOARGS, - "S.transaction_commit() -> None\n" - "Commit the currently active transaction." }, - { "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS, - "S.transaction_start() -> None\n" - "Start a new transaction." }, - { "reopen", (PyCFunction)obj_reopen, METH_NOARGS, "Reopen this file." }, - { "lock_all", (PyCFunction)obj_lockall, METH_NOARGS, NULL }, - { "unlock_all", (PyCFunction)obj_unlockall, METH_NOARGS, NULL }, - { "read_lock_all", (PyCFunction)obj_lockall_read, METH_NOARGS, NULL }, - { "read_unlock_all", (PyCFunction)obj_unlockall_read, METH_NOARGS, NULL }, - { "close", (PyCFunction)obj_close, METH_NOARGS, NULL }, - { "get", (PyCFunction)obj_get, METH_VARARGS, "S.get(key) -> value\n" - "Fetch a value." }, - { "append", (PyCFunction)obj_append, METH_VARARGS, "S.append(key, value) -> None\n" - "Append data to an existing key." }, - { "firstkey", (PyCFunction)obj_firstkey, METH_NOARGS, "S.firstkey() -> data\n" - "Return the first key in this database." }, - { "nextkey", (PyCFunction)obj_nextkey, METH_NOARGS, "S.nextkey(key) -> data\n" - "Return the next key in this database." }, - { "delete", (PyCFunction)obj_delete, METH_VARARGS, "S.delete(key) -> None\n" - "Delete an entry." }, - { "has_key", (PyCFunction)obj_has_key, METH_VARARGS, "S.has_key(key) -> None\n" - "Check whether key exists in this database." }, - { "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, flag=REPLACE) -> None" - "Store data." }, - { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" }, - { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n" - "Wipe the entire database." }, - { NULL } -}; - -static PyObject *obj_get_hash_size(PyTdbObject *self, void *closure) -{ - return PyInt_FromLong(tdb_hash_size(self->ctx)); -} - -static int obj_set_max_dead(PyTdbObject *self, PyObject *max_dead, void *closure) -{ - if (!PyInt_Check(max_dead)) - return -1; - tdb_set_max_dead(self->ctx, PyInt_AsLong(max_dead)); - return 0; -} - -static PyObject *obj_get_map_size(PyTdbObject *self, void *closure) -{ - return PyInt_FromLong(tdb_map_size(self->ctx)); -} - -static PyObject *obj_get_flags(PyTdbObject *self, void *closure) -{ - return PyInt_FromLong(tdb_get_flags(self->ctx)); -} - -static PyObject *obj_get_filename(PyTdbObject *self, void *closure) -{ - return PyString_FromString(tdb_name(self->ctx)); -} - -static PyGetSetDef tdb_object_getsetters[] = { - { (char *)"hash_size", (getter)obj_get_hash_size, NULL, NULL }, - { (char *)"map_size", (getter)obj_get_map_size, NULL, NULL }, - { (char *)"flags", (getter)obj_get_flags, NULL, NULL }, - { (char *)"max_dead", NULL, (setter)obj_set_max_dead, NULL }, - { (char *)"filename", (getter)obj_get_filename, NULL, (char *)"The filename of this TDB file."}, - { NULL } -}; - -static PyObject *tdb_object_repr(PyTdbObject *self) -{ - return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx)); -} - -static void tdb_object_dealloc(PyTdbObject *self) -{ - if (!self->closed) - tdb_close(self->ctx); - PyObject_Del(self); -} - -static PyObject *obj_getitem(PyTdbObject *self, PyObject *key) -{ - TDB_DATA tkey, val; - if (!PyString_Check(key)) { - PyErr_SetString(PyExc_TypeError, "Expected string as key"); - return NULL; - } - - tkey.dptr = (unsigned char *)PyString_AsString(key); - tkey.dsize = PyString_Size(key); - - val = tdb_fetch(self->ctx, tkey); - if (val.dptr == NULL) { - PyErr_SetString(PyExc_KeyError, "No such TDB entry"); - return NULL; - } else { - return PyString_FromTDB_DATA(val); - } -} - -static int obj_setitem(PyTdbObject *self, PyObject *key, PyObject *value) -{ - TDB_DATA tkey, tval; - int ret; - if (!PyString_Check(key)) { - PyErr_SetString(PyExc_TypeError, "Expected string as key"); - return -1; - } - - tkey = PyString_AsTDB_DATA(key); - - if (value == NULL) { - ret = tdb_delete(self->ctx, tkey); - } else { - if (!PyString_Check(value)) { - PyErr_SetString(PyExc_TypeError, "Expected string as value"); - return -1; - } - - tval = PyString_AsTDB_DATA(value); - - ret = tdb_store(self->ctx, tkey, tval, TDB_REPLACE); - } - - if (ret != 0) { - PyErr_SetTDBError(self->ctx); - return -1; - } - - return ret; -} - -static PyMappingMethods tdb_object_mapping = { - .mp_subscript = (binaryfunc)obj_getitem, - .mp_ass_subscript = (objobjargproc)obj_setitem, -}; -PyTypeObject PyTdb = { - .tp_name = "Tdb", - .tp_basicsize = sizeof(PyTdbObject), - .tp_methods = tdb_object_methods, - .tp_getset = tdb_object_getsetters, - .tp_new = py_tdb_open, - .tp_doc = "A TDB file", - .tp_repr = (reprfunc)tdb_object_repr, - .tp_dealloc = (destructor)tdb_object_dealloc, - .tp_as_mapping = &tdb_object_mapping, - .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_ITER, - .tp_iter = (getiterfunc)tdb_object_iter, -}; - -static PyMethodDef tdb_methods[] = { - { "open", (PyCFunction)py_tdb_open, METH_VARARGS|METH_KEYWORDS, "open(name, hash_size=0, tdb_flags=TDB_DEFAULT, flags=O_RDWR, mode=0600)\n" - "Open a TDB file." }, - { NULL } -}; - -void inittdb(void) -{ - PyObject *m; - - if (PyType_Ready(&PyTdb) < 0) - return; - - if (PyType_Ready(&PyTdbIterator) < 0) - return; - - m = Py_InitModule3("tdb", tdb_methods, "TDB is a simple key-value database similar to GDBM that supports multiple writers."); - if (m == NULL) - return; - - PyModule_AddObject(m, "REPLACE", PyInt_FromLong(TDB_REPLACE)); - PyModule_AddObject(m, "INSERT", PyInt_FromLong(TDB_INSERT)); - PyModule_AddObject(m, "MODIFY", PyInt_FromLong(TDB_MODIFY)); - - PyModule_AddObject(m, "DEFAULT", PyInt_FromLong(TDB_DEFAULT)); - PyModule_AddObject(m, "CLEAR_IF_FIRST", PyInt_FromLong(TDB_CLEAR_IF_FIRST)); - PyModule_AddObject(m, "INTERNAL", PyInt_FromLong(TDB_INTERNAL)); - PyModule_AddObject(m, "NOLOCK", PyInt_FromLong(TDB_NOLOCK)); - PyModule_AddObject(m, "NOMMAP", PyInt_FromLong(TDB_NOMMAP)); - PyModule_AddObject(m, "CONVERT", PyInt_FromLong(TDB_CONVERT)); - PyModule_AddObject(m, "BIGENDIAN", PyInt_FromLong(TDB_BIGENDIAN)); - PyModule_AddObject(m, "__docformat__", PyString_FromString("restructuredText")); - - Py_INCREF(&PyTdb); - PyModule_AddObject(m, "Tdb", (PyObject *)&PyTdb); - - Py_INCREF(&PyTdbIterator); -} diff --git a/bundled/tdb/python.mk b/bundled/tdb/python.mk deleted file mode 100644 index 1f2d4ca4..00000000 --- a/bundled/tdb/python.mk +++ /dev/null @@ -1,6 +0,0 @@ -[PYTHON::pytdb] -LIBRARY_REALNAME = tdb.$(SHLIBEXT) -PUBLIC_DEPENDENCIES = LIBTDB DYNCONFIG - -pytdb_OBJ_FILES = $(tdbsrcdir)/pytdb.o - diff --git a/bundled/tdb/python/tdbdump.py b/bundled/tdb/python/tdbdump.py deleted file mode 100644 index 01859ebc..00000000 --- a/bundled/tdb/python/tdbdump.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python -# Trivial reimplementation of tdbdump in Python - -import tdb, sys - -if len(sys.argv) < 2: - print "Usage: tdbdump.py " - sys.exit(1) - -db = tdb.Tdb(sys.argv[1]) -for (k, v) in db.iteritems(): - print "{\nkey(%d) = %r\ndata(%d) = %r\n}" % (len(k), k, len(v), v) diff --git a/bundled/tdb/python/tests/simple.py b/bundled/tdb/python/tests/simple.py deleted file mode 100644 index 6b1e840f..00000000 --- a/bundled/tdb/python/tests/simple.py +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/env python -# Some simple tests for the Python bindings for TDB -# Note that this tests the interface of the Python bindings -# It does not test tdb itself. -# -# Copyright (C) 2007-2008 Jelmer Vernooij -# Published under the GNU LGPLv3 or later - -import tdb -from unittest import TestCase -import os, tempfile - - -class OpenTdbTests(TestCase): - - def test_nonexistant_read(self): - self.assertRaises(IOError, tdb.Tdb, "/some/nonexistant/file", 0, - tdb.DEFAULT, os.O_RDWR) - -class CloseTdbTests(TestCase): - def test_double_close(self): - self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT, - os.O_CREAT|os.O_RDWR) - self.assertNotEqual(None, self.tdb) - - # ensure that double close does not crash python - self.tdb.close() - self.tdb.close() - - -class SimpleTdbTests(TestCase): - - def setUp(self): - super(SimpleTdbTests, self).setUp() - self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT, - os.O_CREAT|os.O_RDWR) - self.assertNotEqual(None, self.tdb) - - def tearDown(self): - del self.tdb - - def test_repr(self): - self.assertTrue(repr(self.tdb).startswith("Tdb('")) - - def test_lockall(self): - self.tdb.lock_all() - - def test_max_dead(self): - self.tdb.max_dead = 20 - - def test_unlockall(self): - self.tdb.lock_all() - self.tdb.unlock_all() - - def test_lockall_read(self): - self.tdb.read_lock_all() - self.tdb.read_unlock_all() - - def test_reopen(self): - self.tdb.reopen() - - def test_store(self): - self.tdb.store("bar", "bla") - self.assertEquals("bla", self.tdb.get("bar")) - - def test_getitem(self): - self.tdb["bar"] = "foo" - self.tdb.reopen() - self.assertEquals("foo", self.tdb["bar"]) - - def test_delete(self): - self.tdb["bar"] = "foo" - del self.tdb["bar"] - self.assertRaises(KeyError, lambda: self.tdb["bar"]) - - def test_contains(self): - self.tdb["bla"] = "bloe" - self.assertTrue("bla" in self.tdb) - - def test_keyerror(self): - self.assertRaises(KeyError, lambda: self.tdb["bla"]) - - def test_hash_size(self): - self.tdb.hash_size - - def test_map_size(self): - self.tdb.map_size - - def test_name(self): - self.tdb.filename - - def test_iterator(self): - self.tdb["bla"] = "1" - self.tdb["brainslug"] = "2" - self.assertEquals(["bla", "brainslug"], list(self.tdb)) - - def test_transaction_cancel(self): - self.tdb["bloe"] = "2" - self.tdb.transaction_start() - self.tdb["bloe"] = "1" - self.tdb.transaction_cancel() - self.assertEquals("2", self.tdb["bloe"]) - - def test_transaction_commit(self): - self.tdb["bloe"] = "2" - self.tdb.transaction_start() - self.tdb["bloe"] = "1" - self.tdb.transaction_commit() - self.assertEquals("1", self.tdb["bloe"]) - - def test_iterator(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "hoi" - i = iter(self.tdb) - self.assertEquals(set(["bloe", "bla"]), set([i.next(), i.next()])) - - def test_iterkeys(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "25" - i = self.tdb.iterkeys() - self.assertEquals(set(["bloe", "bla"]), set([i.next(), i.next()])) - - def test_clear(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "25" - self.assertEquals(2, len(list(self.tdb))) - self.tdb.clear() - self.assertEquals(0, len(list(self.tdb))) - - def test_len(self): - self.assertEquals(0, len(list(self.tdb))) - self.tdb["entry"] = "value" - self.assertEquals(1, len(list(self.tdb))) - - -if __name__ == '__main__': - import unittest - unittest.TestProgram() diff --git a/bundled/tdb/rules.mk b/bundled/tdb/rules.mk deleted file mode 100644 index 023e0ce5..00000000 --- a/bundled/tdb/rules.mk +++ /dev/null @@ -1,16 +0,0 @@ -showflags:: - @echo 'tdb will be compiled with flags:' - @echo ' CFLAGS = $(CFLAGS)' - @echo ' CPPFLAGS = $(CPPFLAGS)' - @echo ' LDFLAGS = $(LDFLAGS)' - @echo ' LIBS = $(LIBS)' - -.SUFFIXES: .c .o - -.c.o: - @echo Compiling $*.c - @mkdir -p `dirname $@` - @$(CC) $(PICFLAG) $(CFLAGS) $(ABI_CHECK) -c $< -o $@ - -distclean:: - rm -f *~ */*~ diff --git a/bundled/tdb/script/abi_checks.sh b/bundled/tdb/script/abi_checks.sh deleted file mode 100755 index ba60ed00..00000000 --- a/bundled/tdb/script/abi_checks.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/sh - -# -# abi_checks.sh - check for possible abi changes -# -# Copyright (C) 2009 Michael Adam -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the Free -# Software Foundation; either version 3 of the License, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along with -# this program; if not, see . -# - -# -# USAGE: abi_checks.sh LIBNAME header1 [header2 ...] -# -# This script creates symbol and signature lists from the provided header -# files with the aid of the mksyms.sh and mksigs.pl scripts (saved as -# $LIBNAME.exports.check and $LIBNAME.sigatures.check). It then compares -# the resulting files with the files $LIBNAME.exports and $LIBNME.signatures -# which it expects to find in the current directory. -# - -LANG=C; export LANG -LC_ALL=C; export LC_ALL -LC_COLLATE=C; export LC_COLLATE - -script=$0 -dir_name=$(dirname ${script}) - -if test x"$1" = "x" ; then - echo "USAGE: ${script} libname header [header ...]" - exit 1 -fi - -libname="$1" -shift - -if test x"$1" = "x" ; then - echo "USAGE: ${script} libname header [header ...]" - exit 1 -fi - -headers="$*" - -exports_file=${libname}.exports -exports_file_check=${exports_file}.check -signatures_file=${libname}.signatures -signatures_file_check=${signatures_file}.check - - -${dir_name}/mksyms.sh awk ${exports_file_check} ${headers} 2>&1 > /dev/null - -cat ${headers} | ${dir_name}/mksigs.pl > ${signatures_file_check} 2> /dev/null - -normalize_exports_file() { - filename=$1 - cat ${filename} \ - | sed -e 's/^[ \t]*//g' \ - | sed -e 's/^$//g' \ - | sed -e 's/^#.*$//g' \ - | sort | uniq > ${filename}.sort -} - -normalize_exports_file ${exports_file} -normalize_exports_file ${exports_file_check} - -normalize_exports_file ${signatures_file} -normalize_exports_file ${signatures_file_check} - -diff -u ${exports_file}.sort ${exports_file_check}.sort -if test "x$?" != "x0" ; then - echo "WARNING: possible ABI change detected in exports!" -else - echo "exports check: OK" -fi - -diff -u ${signatures_file}.sort ${signatures_file_check}.sort -if test "x$?" != "x0" ; then - echo "WARNING: possible ABI change detected in signatures!" -else - echo "signatures check: OK" -fi diff --git a/bundled/tdb/script/abi_checks_gcc.sh b/bundled/tdb/script/abi_checks_gcc.sh deleted file mode 100755 index f0e02f48..00000000 --- a/bundled/tdb/script/abi_checks_gcc.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -make clean - -mkdir -p abi/common -mkdir -p abi/tools -ABI_CHECKS="-aux-info abi/\$@.X" -make ABI_CHECK="$ABI_CHECKS" CC="/usr/bin/gcc" - -for i in abi/*/*.X; do cat $i | grep 'tdb\.h'; done | sort | uniq | awk -F "extern " '{ print $2 }' | sort > abi/signatures -grep '^extern' include/tdb.h | grep -v '"C"' | sort | uniq | awk -F "extern " '{ print $2 }' >> abi/signatures - -cat > abi/exports << EOF -{ - global: -EOF -#Functions -cat abi/signatures | grep "(" | awk -F '(' '{ print $1 }' | awk -F ' ' '{ print " "$NF";" }' | tr -d '*' | sort >> abi/exports -#global vars -cat abi/signatures | grep -v "(" | awk -F ';' '{print $1 }' | awk -F ' ' '{ print " "$NF";" }' | tr -d '*' | sort >> abi/exports -cat >> abi/exports << EOF - - local: *; -}; -EOF - -diff -u tdb.signatures abi/signatures -if [ "$?" != "0" ]; then - echo "WARNING: Possible ABI Change!!" -fi - -diff -u tdb.exports abi/exports -if [ "$?" != "0" ]; then - echo "WARNING: Export file may be outdated!!" -fi diff --git a/bundled/tdb/script/mksigs.pl b/bundled/tdb/script/mksigs.pl deleted file mode 100755 index 755cd796..00000000 --- a/bundled/tdb/script/mksigs.pl +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/perl - -# mksigs.pl - extract signatures from C headers -# -# Copyright (C) Michael Adam 2009 -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the Free -# Software Foundation; either version 3 of the License, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. -# -# You should have received a copy of the GNU General Public License along with -# this program; if not, see . - -# USAGE: cat $header_files | mksigs.pl > $signature_file -# -# The header files to parse are read from stdin. -# The output is in a form as produced by gcc with the -aux-info switch -# and printed to stdout. - -use strict; -use warnings; - -my $in_comment = 0; -my $extern_C_block = 0; - -while (my $LINE = <>) { - # find end of started multi-line-comment - if ($in_comment) { - if ($LINE =~ /^.*?\*\/(.*)$/) { - $LINE = $1; - $in_comment = 0; - } else { - # whole line within comment - next; - } - } - - # strip C++-style comments - $LINE =~ s/^(.*?)\/\/.*$/$1/; - - # strip in-line-comments: - while ($LINE =~ /\/\*.*?\*\//) { - $LINE =~ s/\/\*.*?\*\///; - } - - # find starts of multi-line-comments - if ($LINE =~ /^(.*)\/\*/) { - $in_comment = 1; - $LINE = $1; - } - - # skip empty lines - next if $LINE =~ /^\s*$/; - - # remove leading spaces - $LINE =~ s/^\s*(.*)$/$1/; - - # concatenate lines split with "\" (usually macro defines) - while ($LINE =~ /^(.*?)\s+\\$/) { - my $LINE2 = <>; - $LINE = $1; - $LINE2 =~ s/^\s*(.*)$/$1/; - $LINE .= " " . $LINE2; - } - - # remove all preprocessor directives - next if ($LINE =~ /^#/); - - if ($LINE =~ /^extern\s+"C"\s+\{/) { - $extern_C_block = 1; - next; - } - - if (($LINE =~ /^[^\{]*\}/) and $extern_C_block) { - $extern_C_block = 0; - next; - } - - $LINE =~ s/^extern\s//; - - # concatenate braces stretched over multiple lines - # (from structs or enums) - my $REST = $LINE; - my $braces = 0; - while (($REST =~ /[\{\}]/) or ($braces)) { - while ($REST =~ /[\{\}]/) { - # collect opening - while ($REST =~ /^[^\{\}]*\{(.*)$/) { - $braces++; - $REST = $1; - } - - # collect closing - while ($REST =~ /^[^\{\}]*\}(.*)$/) { - $braces--; - $REST = $1; - } - } - - # concatenate if not balanced - if ($braces) { - if (my $LINE2 = <>) { - $LINE2 =~ s/^\s*(.*)$/$1/; - chomp($LINE); - $LINE .= " " . $LINE2; - chomp $REST; - $REST .= " " . $LINE2; - } else { - print "ERROR: unbalanced braces ($braces)\n"; - last; - } - } - } - - # concetenate function prototypes that stretch over multiple lines - $REST = $LINE; - my $parenthesis = 0; - while (($REST =~ /[\(\)]/) or ($parenthesis)) { - while ($REST =~ /[\(\)]/) { - # collect opening - while ($REST =~ /^[^\(\)]*\((.*)$/) { - $parenthesis++; - $REST = $1; - } - - # collect closing - while ($REST =~ /^[^\(\)]*\)(.*)$/) { - $parenthesis--; - $REST = $1; - } - } - - # concatenate if not balanced - if ($parenthesis) { - if (my $LINE2 = <>) { - $LINE2 =~ s/^\s*(.*)$/$1/; - chomp($LINE); - $LINE .= " " . $LINE2; - chomp($REST); - $REST .= " " . $LINE2; - } else { - print "ERROR: unbalanced parantheses ($parenthesis)\n"; - last; - } - } - } - - next if ($LINE =~ /^typedef\s/); - next if ($LINE =~ /^enum\s+[^\{\(]+\s+\{/); - next if ($LINE =~ /^struct\s+[^\{\(]+\s+\{.*\}\s*;/); - next if ($LINE =~ /^struct\s+[a-zA-Z0-9_]+\s*;/); - - # remove trailing spaces - $LINE =~ s/(.*?)\s*$/$1/; - - $LINE =~ s/^(.*\))\s+PRINTF_ATTRIBUTE\([^\)]*\)(\s*[;,])/$1$2/; - $LINE =~ s/^(.*\))\s*[a-zA-Z0-9_]+\s*;$/$1;/; - - # remove parameter names - slightly too coarse probably - $LINE =~ s/([\s\(]\*?)[_0-9a-zA-Z]+\s*([,\)])/$1$2/g; - - # remedy (void) from last line - $LINE =~ s/\(\)/(void)/g; - - # normalize spaces - $LINE =~ s/\s*\)\s*/)/g; - $LINE =~ s/\s*\(\s*/ (/g; - $LINE =~ s/\s*,\s*/, /g; - - # normalize unsigned - $LINE =~ s/([\s,\(])unsigned([,\)])/$1unsigned int$2/g; - - # normalize bool - $LINE =~ s/(\b)bool(\b)/_Bool/g; - - print $LINE . "\n"; -} diff --git a/bundled/tdb/script/mksyms.awk b/bundled/tdb/script/mksyms.awk deleted file mode 100644 index ca14da0f..00000000 --- a/bundled/tdb/script/mksyms.awk +++ /dev/null @@ -1,76 +0,0 @@ -# -# mksyms.awk -# -# Extract symbols to export from C-header files. -# output in version-script format for linking shared libraries. -# -# Copyright (C) 2008 Micheal Adam -# -BEGIN { - inheader=0; - current_file=""; - print "#" - print "# This file is automatically generated with \"make symbols\". DO NOT EDIT " - print "#" - print "{" - print "\tglobal:" -} - -END { - print"" - print "\tlocal: *;" - print "};" -} - -{ - if (FILENAME!=current_file) { - print "\t\t# The following definitions come from",FILENAME - current_file=FILENAME - } - if (inheader) { - if (match($0,"[)][^()]*[;][ \t]*$")) { - inheader = 0; - } - next; - } -} - -/^static/ || /^[ \t]*typedef/ || !/^[a-zA-Z\_]/ { - next; -} - -/^extern[ \t]+[^()]+[;][ \t]*$/ { - gsub(/[^ \t]+[ \t]+/, ""); - sub(/[;][ \t]*$/, ""); - printf "\t\t%s;\n", $0; - next; -} - -# look for function headers: -{ - gotstart = 0; - if ($0 ~ /^[A-Za-z_][A-Za-z0-9_]+/) { - gotstart = 1; - } - if(!gotstart) { - next; - } -} - -/[_A-Za-z0-9]+[ \t]*[(].*[)][^()]*;[ \t]*$/ { - sub(/[(].*$/, ""); - gsub(/[^ \t]+[ \t]+/, ""); - gsub(/^[*]+/, ""); - printf "\t\t%s;\n",$0; - next; -} - -/[_A-Za-z0-9]+[ \t]*[(]/ { - inheader=1; - sub(/[(].*$/, ""); - gsub(/[^ \t]+[ \t]+/, ""); - gsub(/^[*]/, ""); - printf "\t\t%s;\n",$0; - next; -} - diff --git a/bundled/tdb/script/mksyms.sh b/bundled/tdb/script/mksyms.sh deleted file mode 100755 index 714d55ab..00000000 --- a/bundled/tdb/script/mksyms.sh +++ /dev/null @@ -1,45 +0,0 @@ -#! /bin/sh - -# -# mksyms.sh -# -# Extract symbols to export from C-header files. -# output in version-script format for linking shared libraries. -# -# This is the shell wrapper for the mksyms.awk core script. -# -# Copyright (C) 2008 Micheal Adam -# - -LANG=C; export LANG -LC_ALL=C; export LC_ALL -LC_COLLATE=C; export LC_COLLATE - -if [ $# -lt 2 ] -then - echo "Usage: $0 awk output_file header_files" - exit 1 -fi - -awk="$1" -shift - -symsfile="$1" -shift -symsfile_tmp="$symsfile.$$.tmp~" - -proto_src="`echo $@ | tr ' ' '\n' | sort | uniq `" - -echo creating $symsfile - -mkdir -p `dirname $symsfile` - -${awk} -f `dirname $0`/mksyms.awk $proto_src > $symsfile_tmp - -if cmp -s $symsfile $symsfile_tmp 2>/dev/null -then - echo "$symsfile unchanged" - rm $symsfile_tmp -else - mv $symsfile_tmp $symsfile -fi diff --git a/bundled/tdb/script/release-script.sh b/bundled/tdb/script/release-script.sh deleted file mode 100755 index e9a023d7..00000000 --- a/bundled/tdb/script/release-script.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -LNAME=tdb -LINCLUDE=include/tdb.h - -if [ "$1" = "" ]; then - echo "Please provide version string, eg: 1.2.0" - exit 1 -fi - -if [ ! -d "lib/${LNAME}" ]; then - echo "Run this script from the samba base directory." - exit 1 -fi - -curbranch=`git branch |grep "^*" | tr -d "* "` - -version=$1 -strver=`echo ${version} | tr "." "-"` - -# Checkout the release tag -git branch -f ${LNAME}-release-script-${strver} ${LNAME}-${strver} -if [ ! "$?" = "0" ]; then - echo "Unable to checkout ${LNAME}-${strver} release" - exit 1 -fi - -function cleanquit { - #Clean up - git checkout $curbranch - git branch -d ${LNAME}-release-script-${strver} - exit $1 -} - -# NOTE: use cleanquit after this point -git checkout ${LNAME}-release-script-${strver} - -# Test configure agrees with us -confver=`grep "^AC_INIT" lib/${LNAME}/configure.ac | tr -d "AC_INIT(${LNAME}, " | tr -d ")"` -if [ ! "$confver" = "$version" ]; then - echo "Wrong version, requested release for ${version}, found ${confver}" - exit 1 -fi - -# Check exports and signatures are up to date -pushd lib/${LNAME} -./script/abi_checks.sh ${LNAME} ${LINCLUDE} -abicheck=$? -popd -if [ ! "$abicheck" = "0" ]; then - echo "ERROR: ABI Checks produced warnings!" - cleanquit 1 -fi - -git clean -f -x -d lib/${LNAME} -git clean -f -x -d lib/replace - -# Now build tarball -cp -a lib/${LNAME} ${LNAME}-${version} -cp -a lib/replace ${LNAME}-${version}/libreplace -pushd ${LNAME}-${version} -./autogen.sh -popd -tar cvzf ${LNAME}-${version}.tar.gz ${LNAME}-${version} -rm -fr ${LNAME}-${version} - -cleanquit 0 diff --git a/bundled/tdb/tdb.exports b/bundled/tdb/tdb.exports deleted file mode 100644 index 73b8fd63..00000000 --- a/bundled/tdb/tdb.exports +++ /dev/null @@ -1,65 +0,0 @@ -{ - global: - tdb_add_flags; - tdb_append; - tdb_chainlock; - tdb_chainlock_mark; - tdb_chainlock_nonblock; - tdb_chainlock_read; - tdb_chainlock_unmark; - tdb_chainunlock; - tdb_chainunlock_read; - tdb_check; - tdb_close; - tdb_delete; - tdb_dump_all; - tdb_enable_seqnum; - tdb_error; - tdb_errorstr; - tdb_exists; - tdb_fd; - tdb_fetch; - tdb_firstkey; - tdb_freelist_size; - tdb_get_flags; - tdb_get_logging_private; - tdb_get_seqnum; - tdb_hash_size; - tdb_increment_seqnum_nonblock; - tdb_lockall; - tdb_lockall_mark; - tdb_lockall_nonblock; - tdb_lockall_read; - tdb_lockall_read_nonblock; - tdb_lockall_unmark; - tdb_log_fn; - tdb_map_size; - tdb_name; - tdb_nextkey; - tdb_open; - tdb_open_ex; - tdb_parse_record; - tdb_printfreelist; - tdb_remove_flags; - tdb_reopen; - tdb_reopen_all; - tdb_repack; - tdb_setalarm_sigptr; - tdb_set_logging_function; - tdb_set_max_dead; - tdb_store; - tdb_transaction_cancel; - tdb_transaction_commit; - tdb_transaction_prepare_commit; - tdb_transaction_start; - tdb_transaction_start_nonblock; - tdb_traverse; - tdb_traverse_read; - tdb_unlockall; - tdb_unlockall_read; - tdb_validate_freelist; - tdb_wipe_all; - tdb_null; - - local: *; -}; diff --git a/bundled/tdb/tdb.mk b/bundled/tdb/tdb.mk deleted file mode 100644 index 0dcd419d..00000000 --- a/bundled/tdb/tdb.mk +++ /dev/null @@ -1,106 +0,0 @@ -dirs:: - @mkdir -p bin common tools - -PROGS = bin/tdbtool$(EXEEXT) bin/tdbdump$(EXEEXT) bin/tdbbackup$(EXEEXT) -PROGS_NOINSTALL = bin/tdbtest$(EXEEXT) bin/tdbtorture$(EXEEXT) -ALL_PROGS = $(PROGS) $(PROGS_NOINSTALL) - -TDB_SONAME = libtdb.$(SHLIBEXT).1 -TDB_SOLIB = libtdb.$(SHLIBEXT).$(PACKAGE_VERSION) -TDB_STLIB = libtdb.a - -TDB_LIB = $(TDB_STLIB) - -bin/tdbtest$(EXEEXT): tools/tdbtest.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtest tools/tdbtest.o -L. -ltdb -lgdbm $(TDB_DEPS) - -bin/tdbtool$(EXEEXT): tools/tdbtool.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtool tools/tdbtool.o -L. -ltdb $(TDB_DEPS) - -bin/tdbtorture$(EXEEXT): tools/tdbtorture.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtorture tools/tdbtorture.o -L. -ltdb $(TDB_DEPS) - -bin/tdbdump$(EXEEXT): tools/tdbdump.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbdump tools/tdbdump.o -L. -ltdb $(TDB_DEPS) - -bin/tdbbackup$(EXEEXT): tools/tdbbackup.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbbackup tools/tdbbackup.o -L. -ltdb $(TDB_DEPS) - -test:: abi_checks - -test:: bin/tdbtorture$(EXEEXT) $(TDB_SONAME) - $(LIB_PATH_VAR)=. bin/tdbtorture$(EXEEXT) - -abi_checks:: - @echo ABI checks: - @./script/abi_checks.sh tdb include/tdb.h - -clean:: - rm -f test.db test.tdb torture.tdb test.gdbm - rm -f $(TDB_SONAME) $(TDB_SOLIB) $(TDB_STLIB) libtdb.$(SHLIBEXT) - rm -f $(ALL_PROGS) tdb.pc - rm -f tdb.exports.sort tdb.exports.check tdb.exports.check.sort - rm -f tdb.signatures.sort tdb.signatures.check tdb.signatures.check.sort - -build-python:: tdb.$(SHLIBEXT) - -pytdb.o: $(tdbdir)/pytdb.c - $(CC) $(PICFLAG) -c $(tdbdir)/pytdb.c $(CFLAGS) `$(PYTHON_CONFIG) --cflags` - -tdb.$(SHLIBEXT): libtdb.$(SHLIBEXT) pytdb.o - $(SHLD) $(SHLD_FLAGS) -o $@ pytdb.o -L. -ltdb `$(PYTHON_CONFIG) --ldflags` $(TDB_DEPS) - -install:: installdirs installbin installheaders installlibs \ - $(PYTHON_INSTALL_TARGET) installdocs - -doc:: manpages/tdbbackup.8 manpages/tdbdump.8 manpages/tdbtool.8 - -.SUFFIXES: .8.xml .8 - -.8.xml.8: - -test -z "$(XSLTPROC)" || $(XSLTPROC) -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $< - -installdocs:: - ${INSTALLCMD} -d $(DESTDIR)$(mandir)/man8 - for I in manpages/*.8; do \ - ${INSTALLCMD} -m 644 $$I $(DESTDIR)$(mandir)/man8; \ - done - -install-python:: build-python - mkdir -p $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1, prefix='$(prefix)')"` - cp tdb.$(SHLIBEXT) $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1, prefix='$(prefix)')"` - -check-python:: build-python $(TDB_SONAME) - $(LIB_PATH_VAR)=. PYTHONPATH=".:$(tdbdir)" $(PYTHON) $(tdbdir)/python/tests/simple.py - -clean:: - rm -f tdb.$(SHLIBEXT) - -installdirs:: - mkdir -p $(DESTDIR)$(bindir) - mkdir -p $(DESTDIR)$(includedir) - mkdir -p $(DESTDIR)$(libdir) - mkdir -p $(DESTDIR)$(libdir)/pkgconfig - -installbin:: all installdirs - cp $(PROGS) $(DESTDIR)$(bindir) - -installheaders:: installdirs - cp $(srcdir)/include/tdb.h $(DESTDIR)$(includedir) - -installlibs:: all installdirs - cp tdb.pc $(DESTDIR)$(libdir)/pkgconfig - cp $(TDB_STLIB) $(TDB_SOLIB) $(DESTDIR)$(libdir) - rm -f $(DESTDIR)$(libdir)/libtdb.$(SHLIBEXT) - ln -s $(TDB_SOLIB) $(DESTDIR)$(libdir)/libtdb.$(SHLIBEXT) - rm -f $(DESTDIR)$(libdir)/$(TDB_SONAME) - ln -s $(TDB_SOLIB) $(DESTDIR)$(libdir)/$(TDB_SONAME) - -$(TDB_STLIB): $(TDB_OBJ) - ar -rv $(TDB_STLIB) $(TDB_OBJ) - -libtdb.$(SHLIBEXT): $(TDB_SOLIB) - ln -fs $< $@ - -$(TDB_SONAME): $(TDB_SOLIB) - ln -fs $< $@ diff --git a/bundled/tdb/tdb.pc.in b/bundled/tdb/tdb.pc.in deleted file mode 100644 index 6f8f5537..00000000 --- a/bundled/tdb/tdb.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: tdb -Description: A trivial database -Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -ltdb -Cflags: -I${includedir} -URL: http://tdb.samba.org/ diff --git a/bundled/tdb/tdb.signatures b/bundled/tdb/tdb.signatures deleted file mode 100644 index 7706d186..00000000 --- a/bundled/tdb/tdb.signatures +++ /dev/null @@ -1,61 +0,0 @@ -const char *tdb_errorstr (struct tdb_context *); -const char *tdb_name (struct tdb_context *); -enum TDB_ERROR tdb_error (struct tdb_context *); -int tdb_append (struct tdb_context *, TDB_DATA, TDB_DATA); -int tdb_chainlock_mark (struct tdb_context *, TDB_DATA); -int tdb_chainlock_nonblock (struct tdb_context *, TDB_DATA); -int tdb_chainlock_read (struct tdb_context *, TDB_DATA); -int tdb_chainlock (struct tdb_context *, TDB_DATA); -int tdb_chainlock_unmark (struct tdb_context *, TDB_DATA); -int tdb_chainunlock_read (struct tdb_context *, TDB_DATA); -int tdb_chainunlock (struct tdb_context *, TDB_DATA); -int tdb_close (struct tdb_context *); -int tdb_delete (struct tdb_context *, TDB_DATA); -int tdb_exists (struct tdb_context *, TDB_DATA); -int tdb_fd (struct tdb_context *); -int tdb_freelist_size (struct tdb_context *); -int tdb_get_flags (struct tdb_context *); -int tdb_get_seqnum (struct tdb_context *); -int tdb_hash_size (struct tdb_context *); -int tdb_lockall_mark (struct tdb_context *); -int tdb_lockall_nonblock (struct tdb_context *); -int tdb_lockall_read_nonblock (struct tdb_context *); -int tdb_lockall_read (struct tdb_context *); -int tdb_lockall (struct tdb_context *); -int tdb_lockall_unmark (struct tdb_context *); -int tdb_parse_record (struct tdb_context *, TDB_DATA, int (*) (TDB_DATA, TDB_DATA, void *), void *); -int tdb_printfreelist (struct tdb_context *); -int tdb_reopen_all (int); -int tdb_reopen (struct tdb_context *); -int tdb_repack (struct tdb_context *); -int tdb_store (struct tdb_context *, TDB_DATA, TDB_DATA, int); -int tdb_transaction_cancel (struct tdb_context *); -int tdb_transaction_commit (struct tdb_context *); -int tdb_transaction_prepare_commit (struct tdb_context *); -int tdb_transaction_recover (struct tdb_context *); -int tdb_transaction_start (struct tdb_context *); -int tdb_transaction_start_nonblock (struct tdb_context *); -int tdb_traverse_read (struct tdb_context *, tdb_traverse_func, void *); -int tdb_traverse (struct tdb_context *, tdb_traverse_func, void *); -int tdb_unlockall_read (struct tdb_context *); -int tdb_unlockall (struct tdb_context *); -int tdb_validate_freelist (struct tdb_context *, int *); -int tdb_wipe_all (struct tdb_context *); -size_t tdb_map_size (struct tdb_context *); -struct tdb_context *tdb_open (const char *, int, int, int, mode_t); -struct tdb_context *tdb_open_ex (const char *, int, int, int, mode_t, const struct tdb_logging_context *, tdb_hash_func); -TDB_DATA tdb_fetch (struct tdb_context *, TDB_DATA); -TDB_DATA tdb_firstkey (struct tdb_context *); -TDB_DATA tdb_nextkey (struct tdb_context *, TDB_DATA); -tdb_log_func tdb_log_fn (struct tdb_context *); -void tdb_add_flags (struct tdb_context *, unsigned int); -void tdb_dump_all (struct tdb_context *); -void tdb_enable_seqnum (struct tdb_context *); -void *tdb_get_logging_private (struct tdb_context *); -void tdb_increment_seqnum_nonblock (struct tdb_context *); -void tdb_remove_flags (struct tdb_context *, unsigned int); -void tdb_setalarm_sigptr (struct tdb_context *, volatile sig_atomic_t *); -void tdb_set_logging_function (struct tdb_context *, const struct tdb_logging_context *); -void tdb_set_max_dead (struct tdb_context *, int); -int tdb_check (struct tdb_context *, int (*) (TDB_DATA, TDB_DATA, void *), void *); -TDB_DATA tdb_null; diff --git a/bundled/tdb/tools/tdbbackup.c b/bundled/tdb/tools/tdbbackup.c deleted file mode 100644 index 6aca8dd9..00000000 --- a/bundled/tdb/tools/tdbbackup.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - Unix SMB/CIFS implementation. - low level tdb backup and restore utility - Copyright (C) Andrew Tridgell 2002 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/* - - This program is meant for backup/restore of tdb databases. Typical usage would be: - tdbbackup *.tdb - when Samba shuts down cleanly, which will make a backup of all the local databases - to *.bak files. Then on Samba startup you would use: - tdbbackup -v *.tdb - and this will check the databases for corruption and if corruption is detected then - the backup will be restored. - - You may also like to do a backup on a regular basis while Samba is - running, perhaps using cron. - - The reason this program is needed is to cope with power failures - while Samba is running. A power failure could lead to database - corruption and Samba will then not start correctly. - - Note that many of the databases in Samba are transient and thus - don't need to be backed up, so you can optimise the above a little - by only running the backup on the critical databases. - - */ - -#include "replace.h" -#include "system/locale.h" -#include "system/time.h" -#include "system/filesys.h" -#include "system/wait.h" -#include "tdb.h" - -#ifdef HAVE_GETOPT_H -#include -#endif - -static int failed; - -static struct tdb_logging_context log_ctx; - -#ifdef PRINTF_ATTRIBUTE -static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); -#endif -static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - vfprintf(stdout, format, ap); - va_end(ap); - fflush(stdout); -} - -static char *add_suffix(const char *name, const char *suffix) -{ - char *ret; - int len = strlen(name) + strlen(suffix) + 1; - ret = (char *)malloc(len); - if (!ret) { - fprintf(stderr,"Out of memory!\n"); - exit(1); - } - snprintf(ret, len, "%s%s", name, suffix); - return ret; -} - -static int copy_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) -{ - TDB_CONTEXT *tdb_new = (TDB_CONTEXT *)state; - - if (tdb_store(tdb_new, key, dbuf, TDB_INSERT) != 0) { - fprintf(stderr,"Failed to insert into %s\n", tdb_name(tdb_new)); - failed = 1; - return 1; - } - return 0; -} - - -static int test_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) -{ - return 0; -} - -/* - carefully backup a tdb, validating the contents and - only doing the backup if its OK - this function is also used for restore -*/ -static int backup_tdb(const char *old_name, const char *new_name, int hash_size) -{ - TDB_CONTEXT *tdb; - TDB_CONTEXT *tdb_new; - char *tmp_name; - struct stat st; - int count1, count2; - - tmp_name = add_suffix(new_name, ".tmp"); - - /* stat the old tdb to find its permissions */ - if (stat(old_name, &st) != 0) { - perror(old_name); - free(tmp_name); - return 1; - } - - /* open the old tdb */ - tdb = tdb_open_ex(old_name, 0, 0, - O_RDWR, 0, &log_ctx, NULL); - if (!tdb) { - printf("Failed to open %s\n", old_name); - free(tmp_name); - return 1; - } - - /* create the new tdb */ - unlink(tmp_name); - tdb_new = tdb_open_ex(tmp_name, - hash_size ? hash_size : tdb_hash_size(tdb), - TDB_DEFAULT, - O_RDWR|O_CREAT|O_EXCL, st.st_mode & 0777, - &log_ctx, NULL); - if (!tdb_new) { - perror(tmp_name); - free(tmp_name); - return 1; - } - - if (tdb_transaction_start(tdb) != 0) { - printf("Failed to start transaction on old tdb\n"); - tdb_close(tdb); - tdb_close(tdb_new); - unlink(tmp_name); - free(tmp_name); - return 1; - } - - if (tdb_transaction_start(tdb_new) != 0) { - printf("Failed to start transaction on new tdb\n"); - tdb_close(tdb); - tdb_close(tdb_new); - unlink(tmp_name); - free(tmp_name); - return 1; - } - - failed = 0; - - /* traverse and copy */ - count1 = tdb_traverse(tdb, copy_fn, (void *)tdb_new); - if (count1 < 0 || failed) { - fprintf(stderr,"failed to copy %s\n", old_name); - tdb_close(tdb); - tdb_close(tdb_new); - unlink(tmp_name); - free(tmp_name); - return 1; - } - - /* close the old tdb */ - tdb_close(tdb); - - if (tdb_transaction_commit(tdb_new) != 0) { - fprintf(stderr, "Failed to commit new tdb\n"); - tdb_close(tdb_new); - unlink(tmp_name); - free(tmp_name); - return 1; - } - - /* close the new tdb and re-open read-only */ - tdb_close(tdb_new); - tdb_new = tdb_open_ex(tmp_name, - 0, - TDB_DEFAULT, - O_RDONLY, 0, - &log_ctx, NULL); - if (!tdb_new) { - fprintf(stderr,"failed to reopen %s\n", tmp_name); - unlink(tmp_name); - perror(tmp_name); - free(tmp_name); - return 1; - } - - /* traverse the new tdb to confirm */ - count2 = tdb_traverse(tdb_new, test_fn, NULL); - if (count2 != count1) { - fprintf(stderr,"failed to copy %s\n", old_name); - tdb_close(tdb_new); - unlink(tmp_name); - free(tmp_name); - return 1; - } - - /* close the new tdb and rename it to .bak */ - tdb_close(tdb_new); - if (rename(tmp_name, new_name) != 0) { - perror(new_name); - free(tmp_name); - return 1; - } - - free(tmp_name); - - return 0; -} - -/* - verify a tdb and if it is corrupt then restore from *.bak -*/ -static int verify_tdb(const char *fname, const char *bak_name) -{ - TDB_CONTEXT *tdb; - int count = -1; - - /* open the tdb */ - tdb = tdb_open_ex(fname, 0, 0, - O_RDONLY, 0, &log_ctx, NULL); - - /* traverse the tdb, then close it */ - if (tdb) { - count = tdb_traverse(tdb, test_fn, NULL); - tdb_close(tdb); - } - - /* count is < 0 means an error */ - if (count < 0) { - printf("restoring %s\n", fname); - return backup_tdb(bak_name, fname, 0); - } - - printf("%s : %d records\n", fname, count); - - return 0; -} - -/* - see if one file is newer than another -*/ -static int file_newer(const char *fname1, const char *fname2) -{ - struct stat st1, st2; - if (stat(fname1, &st1) != 0) { - return 0; - } - if (stat(fname2, &st2) != 0) { - return 1; - } - return (st1.st_mtime > st2.st_mtime); -} - -static void usage(void) -{ - printf("Usage: tdbbackup [options] \n\n"); - printf(" -h this help message\n"); - printf(" -s suffix set the backup suffix\n"); - printf(" -v verify mode (restore if corrupt)\n"); - printf(" -n hashsize set the new hash size for the backup\n"); -} - - - int main(int argc, char *argv[]) -{ - int i; - int ret = 0; - int c; - int verify = 0; - int hashsize = 0; - const char *suffix = ".bak"; - - log_ctx.log_fn = tdb_log; - - while ((c = getopt(argc, argv, "vhs:n:")) != -1) { - switch (c) { - case 'h': - usage(); - exit(0); - case 'v': - verify = 1; - break; - case 's': - suffix = optarg; - break; - case 'n': - hashsize = atoi(optarg); - break; - } - } - - argc -= optind; - argv += optind; - - if (argc < 1) { - usage(); - exit(1); - } - - for (i=0; i. -*/ - -#include "replace.h" -#include "system/locale.h" -#include "system/time.h" -#include "system/filesys.h" -#include "system/wait.h" -#include "tdb.h" - -static void print_data(TDB_DATA d) -{ - unsigned char *p = (unsigned char *)d.dptr; - int len = d.dsize; - while (len--) { - if (isprint(*p) && !strchr("\"\\", *p)) { - fputc(*p, stdout); - } else { - printf("\\%02X", *p); - } - p++; - } -} - -static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state) -{ - printf("{\n"); - printf("key(%d) = \"", (int)key.dsize); - print_data(key); - printf("\"\n"); - printf("data(%d) = \"", (int)dbuf.dsize); - print_data(dbuf); - printf("\"\n"); - printf("}\n"); - return 0; -} - -static int dump_tdb(const char *fname, const char *keyname) -{ - TDB_CONTEXT *tdb; - TDB_DATA key, value; - - tdb = tdb_open(fname, 0, 0, O_RDONLY, 0); - if (!tdb) { - printf("Failed to open %s\n", fname); - return 1; - } - - if (!keyname) { - tdb_traverse(tdb, traverse_fn, NULL); - } else { - key.dptr = discard_const_p(uint8_t, keyname); - key.dsize = strlen(keyname); - value = tdb_fetch(tdb, key); - if (!value.dptr) { - return 1; - } else { - print_data(value); - free(value.dptr); - } - } - - return 0; -} - -static void usage( void) -{ - printf( "Usage: tdbdump [options] \n\n"); - printf( " -h this help message\n"); - printf( " -k keyname dumps value of keyname\n"); -} - - int main(int argc, char *argv[]) -{ - char *fname, *keyname=NULL; - int c; - - if (argc < 2) { - printf("Usage: tdbdump \n"); - exit(1); - } - - while ((c = getopt( argc, argv, "hk:")) != -1) { - switch (c) { - case 'h': - usage(); - exit( 0); - case 'k': - keyname = optarg; - break; - default: - usage(); - exit( 1); - } - } - - fname = argv[optind]; - - return dump_tdb(fname, keyname); -} diff --git a/bundled/tdb/tools/tdbtest.c b/bundled/tdb/tools/tdbtest.c deleted file mode 100644 index 416bc50a..00000000 --- a/bundled/tdb/tools/tdbtest.c +++ /dev/null @@ -1,265 +0,0 @@ -/* a test program for tdb - the trivial database */ - -#include "replace.h" -#include "tdb.h" -#include "system/filesys.h" -#include "system/time.h" - -#include - - -#define DELETE_PROB 7 -#define STORE_PROB 5 - -static struct tdb_context *db; -static GDBM_FILE gdbm; - -struct timeval tp1,tp2; - -static void _start_timer(void) -{ - gettimeofday(&tp1,NULL); -} - -static double _end_timer(void) -{ - gettimeofday(&tp2,NULL); - return((tp2.tv_sec - tp1.tv_sec) + - (tp2.tv_usec - tp1.tv_usec)*1.0e-6); -} - -static void fatal(const char *why) -{ - perror(why); - exit(1); -} - -#ifdef PRINTF_ATTRIBUTE -static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); -#endif -static void tdb_log(struct tdb_context *tdb, int level, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - vfprintf(stdout, format, ap); - va_end(ap); - fflush(stdout); -} - -static void compare_db(void) -{ - TDB_DATA d, key, nextkey; - datum gd, gkey, gnextkey; - - key = tdb_firstkey(db); - while (key.dptr) { - d = tdb_fetch(db, key); - gkey.dptr = key.dptr; - gkey.dsize = key.dsize; - - gd = gdbm_fetch(gdbm, gkey); - - if (!gd.dptr) fatal("key not in gdbm"); - if (gd.dsize != d.dsize) fatal("data sizes differ"); - if (memcmp(gd.dptr, d.dptr, d.dsize)) { - fatal("data differs"); - } - - nextkey = tdb_nextkey(db, key); - free(key.dptr); - free(d.dptr); - free(gd.dptr); - key = nextkey; - } - - gkey = gdbm_firstkey(gdbm); - while (gkey.dptr) { - gd = gdbm_fetch(gdbm, gkey); - key.dptr = gkey.dptr; - key.dsize = gkey.dsize; - - d = tdb_fetch(db, key); - - if (!d.dptr) fatal("key not in db"); - if (d.dsize != gd.dsize) fatal("data sizes differ"); - if (memcmp(d.dptr, gd.dptr, gd.dsize)) { - fatal("data differs"); - } - - gnextkey = gdbm_nextkey(gdbm, gkey); - free(gkey.dptr); - free(gd.dptr); - free(d.dptr); - gkey = gnextkey; - } -} - -static char *randbuf(int len) -{ - char *buf; - int i; - buf = (char *)malloc(len+1); - - for (i=0;i. -*/ - -#include "replace.h" -#include "system/locale.h" -#include "system/time.h" -#include "system/filesys.h" -#include "system/wait.h" -#include "tdb.h" - -static int do_command(void); -const char *cmdname; -char *arg1, *arg2; -size_t arg1len, arg2len; -int bIterate = 0; -char *line; -TDB_DATA iterate_kbuf; -char cmdline[1024]; -static int disable_mmap; - -enum commands { - CMD_CREATE_TDB, - CMD_OPEN_TDB, - CMD_TRANSACTION_START, - CMD_TRANSACTION_COMMIT, - CMD_TRANSACTION_CANCEL, - CMD_ERASE, - CMD_DUMP, - CMD_INSERT, - CMD_MOVE, - CMD_STORE, - CMD_SHOW, - CMD_KEYS, - CMD_HEXKEYS, - CMD_DELETE, - CMD_LIST_HASH_FREE, - CMD_LIST_FREE, - CMD_INFO, - CMD_MMAP, - CMD_SPEED, - CMD_FIRST, - CMD_NEXT, - CMD_SYSTEM, - CMD_CHECK, - CMD_QUIT, - CMD_HELP -}; - -typedef struct { - const char *name; - enum commands cmd; -} COMMAND_TABLE; - -COMMAND_TABLE cmd_table[] = { - {"create", CMD_CREATE_TDB}, - {"open", CMD_OPEN_TDB}, - {"transaction_start", CMD_TRANSACTION_START}, - {"transaction_commit", CMD_TRANSACTION_COMMIT}, - {"transaction_cancel", CMD_TRANSACTION_CANCEL}, - {"erase", CMD_ERASE}, - {"dump", CMD_DUMP}, - {"insert", CMD_INSERT}, - {"move", CMD_MOVE}, - {"store", CMD_STORE}, - {"show", CMD_SHOW}, - {"keys", CMD_KEYS}, - {"hexkeys", CMD_HEXKEYS}, - {"delete", CMD_DELETE}, - {"list", CMD_LIST_HASH_FREE}, - {"free", CMD_LIST_FREE}, - {"info", CMD_INFO}, - {"speed", CMD_SPEED}, - {"mmap", CMD_MMAP}, - {"first", CMD_FIRST}, - {"1", CMD_FIRST}, - {"next", CMD_NEXT}, - {"n", CMD_NEXT}, - {"check", CMD_CHECK}, - {"quit", CMD_QUIT}, - {"q", CMD_QUIT}, - {"!", CMD_SYSTEM}, - {NULL, CMD_HELP} -}; - -struct timeval tp1,tp2; - -static void _start_timer(void) -{ - gettimeofday(&tp1,NULL); -} - -static double _end_timer(void) -{ - gettimeofday(&tp2,NULL); - return((tp2.tv_sec - tp1.tv_sec) + - (tp2.tv_usec - tp1.tv_usec)*1.0e-6); -} - -#ifdef PRINTF_ATTRIBUTE -static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); -#endif -static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); -} - -/* a tdb tool for manipulating a tdb database */ - -static TDB_CONTEXT *tdb; - -static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); -static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); -static int print_hexkey(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state); - -static void print_asc(const char *buf,int len) -{ - int i; - - /* We're probably printing ASCII strings so don't try to display - the trailing NULL character. */ - - if (buf[len - 1] == 0) - len--; - - for (i=0;i8) printf(" "); - while (n--) printf(" "); - - n = i%16; - if (n > 8) n = 8; - print_asc(&buf[i-(i%16)],n); printf(" "); - n = (i%16) - n; - if (n>0) print_asc(&buf[i-n],n); - printf("\n"); - } -} - -static void help(void) -{ - printf("\n" -"tdbtool: \n" -" create dbname : create a database\n" -" open dbname : open an existing database\n" -" transaction_start : start a transaction\n" -" transaction_commit : commit a transaction\n" -" transaction_cancel : cancel a transaction\n" -" erase : erase the database\n" -" dump : dump the database as strings\n" -" keys : dump the database keys as strings\n" -" hexkeys : dump the database keys as hex values\n" -" info : print summary info about the database\n" -" insert key data : insert a record\n" -" move key file : move a record to a destination tdb\n" -" store key data : store a record (replace)\n" -" show key : show a record by key\n" -" delete key : delete a record by key\n" -" list : print the database hash table and freelist\n" -" free : print the database freelist\n" -" check : check the integrity of an opened database\n" -" speed : perform speed tests on the database\n" -" ! command : execute system command\n" -" 1 | first : print the first record\n" -" n | next : print the next record\n" -" q | quit : terminate\n" -" \\n : repeat 'next' command\n" -"\n"); -} - -static void terror(const char *why) -{ - printf("%s\n", why); -} - -static void create_tdb(const char *tdbname) -{ - struct tdb_logging_context log_ctx; - log_ctx.log_fn = tdb_log; - - if (tdb) tdb_close(tdb); - tdb = tdb_open_ex(tdbname, 0, TDB_CLEAR_IF_FIRST | (disable_mmap?TDB_NOMMAP:0), - O_RDWR | O_CREAT | O_TRUNC, 0600, &log_ctx, NULL); - if (!tdb) { - printf("Could not create %s: %s\n", tdbname, strerror(errno)); - } -} - -static void open_tdb(const char *tdbname) -{ - struct tdb_logging_context log_ctx; - log_ctx.log_fn = tdb_log; - - if (tdb) tdb_close(tdb); - tdb = tdb_open_ex(tdbname, 0, disable_mmap?TDB_NOMMAP:0, O_RDWR, 0600, - &log_ctx, NULL); - if (!tdb) { - printf("Could not open %s: %s\n", tdbname, strerror(errno)); - } -} - -static void insert_tdb(char *keyname, size_t keylen, char* data, size_t datalen) -{ - TDB_DATA key, dbuf; - - if ((keyname == NULL) || (keylen == 0)) { - terror("need key"); - return; - } - - key.dptr = (unsigned char *)keyname; - key.dsize = keylen; - dbuf.dptr = (unsigned char *)data; - dbuf.dsize = datalen; - - if (tdb_store(tdb, key, dbuf, TDB_INSERT) == -1) { - terror("insert failed"); - } -} - -static void store_tdb(char *keyname, size_t keylen, char* data, size_t datalen) -{ - TDB_DATA key, dbuf; - - if ((keyname == NULL) || (keylen == 0)) { - terror("need key"); - return; - } - - if ((data == NULL) || (datalen == 0)) { - terror("need data"); - return; - } - - key.dptr = (unsigned char *)keyname; - key.dsize = keylen; - dbuf.dptr = (unsigned char *)data; - dbuf.dsize = datalen; - - printf("Storing key:\n"); - print_rec(tdb, key, dbuf, NULL); - - if (tdb_store(tdb, key, dbuf, TDB_REPLACE) == -1) { - terror("store failed"); - } -} - -static void show_tdb(char *keyname, size_t keylen) -{ - TDB_DATA key, dbuf; - - if ((keyname == NULL) || (keylen == 0)) { - terror("need key"); - return; - } - - key.dptr = (unsigned char *)keyname; - key.dsize = keylen; - - dbuf = tdb_fetch(tdb, key); - if (!dbuf.dptr) { - terror("fetch failed"); - return; - } - - print_rec(tdb, key, dbuf, NULL); - - free( dbuf.dptr ); - - return; -} - -static void delete_tdb(char *keyname, size_t keylen) -{ - TDB_DATA key; - - if ((keyname == NULL) || (keylen == 0)) { - terror("need key"); - return; - } - - key.dptr = (unsigned char *)keyname; - key.dsize = keylen; - - if (tdb_delete(tdb, key) != 0) { - terror("delete failed"); - } -} - -static void move_rec(char *keyname, size_t keylen, char* tdbname) -{ - TDB_DATA key, dbuf; - TDB_CONTEXT *dst_tdb; - - if ((keyname == NULL) || (keylen == 0)) { - terror("need key"); - return; - } - - if ( !tdbname ) { - terror("need destination tdb name"); - return; - } - - key.dptr = (unsigned char *)keyname; - key.dsize = keylen; - - dbuf = tdb_fetch(tdb, key); - if (!dbuf.dptr) { - terror("fetch failed"); - return; - } - - print_rec(tdb, key, dbuf, NULL); - - dst_tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600); - if ( !dst_tdb ) { - terror("unable to open destination tdb"); - return; - } - - if ( tdb_store( dst_tdb, key, dbuf, TDB_REPLACE ) == -1 ) { - terror("failed to move record"); - } - else - printf("record moved\n"); - - tdb_close( dst_tdb ); - - return; -} - -static int print_rec(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) -{ - printf("\nkey %d bytes\n", (int)key.dsize); - print_asc((const char *)key.dptr, key.dsize); - printf("\ndata %d bytes\n", (int)dbuf.dsize); - print_data((const char *)dbuf.dptr, dbuf.dsize); - return 0; -} - -static int print_key(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) -{ - printf("key %d bytes: ", (int)key.dsize); - print_asc((const char *)key.dptr, key.dsize); - printf("\n"); - return 0; -} - -static int print_hexkey(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) -{ - printf("key %d bytes\n", (int)key.dsize); - print_data((const char *)key.dptr, key.dsize); - printf("\n"); - return 0; -} - -static int total_bytes; - -static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, void *state) -{ - total_bytes += dbuf.dsize; - return 0; -} - -static void info_tdb(void) -{ - int count; - total_bytes = 0; - if ((count = tdb_traverse(tdb, traverse_fn, NULL)) == -1) - printf("Error = %s\n", tdb_errorstr(tdb)); - else - printf("%d records totalling %d bytes\n", count, total_bytes); -} - -static void speed_tdb(const char *tlimit) -{ - const char *str = "store test", *str2 = "transaction test"; - unsigned timelimit = tlimit?atoi(tlimit):0; - double t; - int ops; - if (timelimit == 0) timelimit = 5; - - ops = 0; - printf("Testing store speed for %u seconds\n", timelimit); - _start_timer(); - do { - long int r = random(); - TDB_DATA key, dbuf; - key.dptr = discard_const_p(uint8_t, str); - key.dsize = strlen((char *)key.dptr); - dbuf.dptr = (uint8_t *) &r; - dbuf.dsize = sizeof(r); - tdb_store(tdb, key, dbuf, TDB_REPLACE); - t = _end_timer(); - ops++; - } while (t < timelimit); - printf("%10.3f ops/sec\n", ops/t); - - ops = 0; - printf("Testing fetch speed for %u seconds\n", timelimit); - _start_timer(); - do { - long int r = random(); - TDB_DATA key, dbuf; - key.dptr = discard_const_p(uint8_t, str); - key.dsize = strlen((char *)key.dptr); - dbuf.dptr = (uint8_t *) &r; - dbuf.dsize = sizeof(r); - tdb_fetch(tdb, key); - t = _end_timer(); - ops++; - } while (t < timelimit); - printf("%10.3f ops/sec\n", ops/t); - - ops = 0; - printf("Testing transaction speed for %u seconds\n", timelimit); - _start_timer(); - do { - long int r = random(); - TDB_DATA key, dbuf; - key.dptr = discard_const_p(uint8_t, str2); - key.dsize = strlen((char *)key.dptr); - dbuf.dptr = (uint8_t *) &r; - dbuf.dsize = sizeof(r); - tdb_transaction_start(tdb); - tdb_store(tdb, key, dbuf, TDB_REPLACE); - tdb_transaction_commit(tdb); - t = _end_timer(); - ops++; - } while (t < timelimit); - printf("%10.3f ops/sec\n", ops/t); - - ops = 0; - printf("Testing traverse speed for %u seconds\n", timelimit); - _start_timer(); - do { - tdb_traverse(tdb, traverse_fn, NULL); - t = _end_timer(); - ops++; - } while (t < timelimit); - printf("%10.3f ops/sec\n", ops/t); -} - -static void toggle_mmap(void) -{ - disable_mmap = !disable_mmap; - if (disable_mmap) { - printf("mmap is disabled\n"); - } else { - printf("mmap is enabled\n"); - } -} - -static char *tdb_getline(const char *prompt) -{ - static char thisline[1024]; - char *p; - fputs(prompt, stdout); - thisline[0] = 0; - p = fgets(thisline, sizeof(thisline)-1, stdin); - if (p) p = strchr(p, '\n'); - if (p) *p = 0; - return p?thisline:NULL; -} - -static int do_delete_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, TDB_DATA dbuf, - void *state) -{ - return tdb_delete(the_tdb, key); -} - -static void first_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey) -{ - TDB_DATA dbuf; - *pkey = tdb_firstkey(the_tdb); - - dbuf = tdb_fetch(the_tdb, *pkey); - if (!dbuf.dptr) terror("fetch failed"); - else { - print_rec(the_tdb, *pkey, dbuf, NULL); - } -} - -static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey) -{ - TDB_DATA dbuf; - *pkey = tdb_nextkey(the_tdb, *pkey); - - dbuf = tdb_fetch(the_tdb, *pkey); - if (!dbuf.dptr) - terror("fetch failed"); - else - print_rec(the_tdb, *pkey, dbuf, NULL); -} - -static int count(TDB_DATA key, TDB_DATA data, void *private_data) -{ - (*(unsigned int *)private_data)++; - return 0; -} - -static void check_db(TDB_CONTEXT *the_tdb) -{ - int tdbcount = 0; - if (!the_tdb) - printf("Error: No database opened!\n"); - else if (tdb_check(the_tdb, count, &tdbcount) == -1) - printf("Integrity check for the opened database failed.\n"); - else - printf("Database integrity is OK and has %d records.\n", - tdbcount); -} - -static int do_command(void) -{ - COMMAND_TABLE *ctp = cmd_table; - enum commands mycmd = CMD_HELP; - int cmd_len; - - if (cmdname && strlen(cmdname) == 0) { - mycmd = CMD_NEXT; - } else { - while (ctp->name) { - cmd_len = strlen(ctp->name); - if (strncmp(ctp->name,cmdname,cmd_len) == 0) { - mycmd = ctp->cmd; - break; - } - ctp++; - } - } - - switch (mycmd) { - case CMD_CREATE_TDB: - bIterate = 0; - create_tdb(arg1); - return 0; - case CMD_OPEN_TDB: - bIterate = 0; - open_tdb(arg1); - return 0; - case CMD_SYSTEM: - /* Shell command */ - if (system(arg1) == -1) { - terror("system() call failed\n"); - } - return 0; - case CMD_QUIT: - return 1; - default: - /* all the rest require a open database */ - if (!tdb) { - bIterate = 0; - terror("database not open"); - help(); - return 0; - } - switch (mycmd) { - case CMD_TRANSACTION_START: - bIterate = 0; - tdb_transaction_start(tdb); - return 0; - case CMD_TRANSACTION_COMMIT: - bIterate = 0; - tdb_transaction_commit(tdb); - return 0; - case CMD_TRANSACTION_CANCEL: - bIterate = 0; - tdb_transaction_cancel(tdb); - return 0; - case CMD_ERASE: - bIterate = 0; - tdb_traverse(tdb, do_delete_fn, NULL); - return 0; - case CMD_DUMP: - bIterate = 0; - tdb_traverse(tdb, print_rec, NULL); - return 0; - case CMD_INSERT: - bIterate = 0; - insert_tdb(arg1, arg1len,arg2,arg2len); - return 0; - case CMD_MOVE: - bIterate = 0; - move_rec(arg1,arg1len,arg2); - return 0; - case CMD_STORE: - bIterate = 0; - store_tdb(arg1,arg1len,arg2,arg2len); - return 0; - case CMD_SHOW: - bIterate = 0; - show_tdb(arg1, arg1len); - return 0; - case CMD_KEYS: - tdb_traverse(tdb, print_key, NULL); - return 0; - case CMD_HEXKEYS: - tdb_traverse(tdb, print_hexkey, NULL); - return 0; - case CMD_DELETE: - bIterate = 0; - delete_tdb(arg1,arg1len); - return 0; - case CMD_LIST_HASH_FREE: - tdb_dump_all(tdb); - return 0; - case CMD_LIST_FREE: - tdb_printfreelist(tdb); - return 0; - case CMD_INFO: - info_tdb(); - return 0; - case CMD_SPEED: - speed_tdb(arg1); - return 0; - case CMD_MMAP: - toggle_mmap(); - return 0; - case CMD_FIRST: - bIterate = 1; - first_record(tdb, &iterate_kbuf); - return 0; - case CMD_NEXT: - if (bIterate) - next_record(tdb, &iterate_kbuf); - return 0; - case CMD_CHECK: - check_db(tdb); - return 0; - case CMD_HELP: - help(); - return 0; - case CMD_CREATE_TDB: - case CMD_OPEN_TDB: - case CMD_SYSTEM: - case CMD_QUIT: - /* - * unhandled commands. cases included here to avoid compiler - * warnings. - */ - return 0; - } - } - - return 0; -} - -static char *convert_string(char *instring, size_t *sizep) -{ - size_t length = 0; - char *outp, *inp; - char temp[3]; - - outp = inp = instring; - - while (*inp) { - if (*inp == '\\') { - inp++; - if (*inp && strchr("0123456789abcdefABCDEF",(int)*inp)) { - temp[0] = *inp++; - temp[1] = '\0'; - if (*inp && strchr("0123456789abcdefABCDEF",(int)*inp)) { - temp[1] = *inp++; - temp[2] = '\0'; - } - *outp++ = (char)strtol((const char *)temp,NULL,16); - } else { - *outp++ = *inp++; - } - } else { - *outp++ = *inp++; - } - length++; - } - *sizep = length; - return instring; -} - -int main(int argc, char *argv[]) -{ - cmdname = ""; - arg1 = NULL; - arg1len = 0; - arg2 = NULL; - arg2len = 0; - - if (argv[1]) { - cmdname = "open"; - arg1 = argv[1]; - do_command(); - cmdname = ""; - arg1 = NULL; - } - - switch (argc) { - case 1: - case 2: - /* Interactive mode */ - while ((cmdname = tdb_getline("tdb> "))) { - arg2 = arg1 = NULL; - if ((arg1 = strchr((const char *)cmdname,' ')) != NULL) { - arg1++; - arg2 = arg1; - while (*arg2) { - if (*arg2 == ' ') { - *arg2++ = '\0'; - break; - } - if ((*arg2++ == '\\') && (*arg2 == ' ')) { - arg2++; - } - } - } - if (arg1) arg1 = convert_string(arg1,&arg1len); - if (arg2) arg2 = convert_string(arg2,&arg2len); - if (do_command()) break; - } - break; - case 5: - arg2 = convert_string(argv[4],&arg2len); - case 4: - arg1 = convert_string(argv[3],&arg1len); - case 3: - cmdname = argv[2]; - default: - do_command(); - break; - } - - if (tdb) tdb_close(tdb); - - return 0; -} diff --git a/bundled/tdb/tools/tdbtorture.c b/bundled/tdb/tools/tdbtorture.c deleted file mode 100644 index 79fe3cd5..00000000 --- a/bundled/tdb/tools/tdbtorture.c +++ /dev/null @@ -1,431 +0,0 @@ -/* this tests tdb by doing lots of ops from several simultaneous - writers - that stresses the locking code. -*/ - -#include "replace.h" -#include "system/time.h" -#include "system/wait.h" -#include "system/filesys.h" -#include "tdb.h" - -#ifdef HAVE_GETOPT_H -#include -#endif - - -#define REOPEN_PROB 30 -#define DELETE_PROB 8 -#define STORE_PROB 4 -#define APPEND_PROB 6 -#define TRANSACTION_PROB 10 -#define TRANSACTION_PREPARE_PROB 2 -#define LOCKSTORE_PROB 5 -#define TRAVERSE_PROB 20 -#define TRAVERSE_READ_PROB 20 -#define CULL_PROB 100 -#define KEYLEN 3 -#define DATALEN 100 - -static struct tdb_context *db; -static int in_transaction; -static int error_count; -static int always_transaction = 0; -static int hash_size = 2; -static int loopnum; -static int count_pipe; -static struct tdb_logging_context log_ctx; - -#ifdef PRINTF_ATTRIBUTE -static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4); -#endif -static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) -{ - va_list ap; - - /* trace level messages do not indicate an error */ - if (level != TDB_DEBUG_TRACE) { - error_count++; - } - - va_start(ap, format); - vfprintf(stdout, format, ap); - va_end(ap); - fflush(stdout); -#if 0 - if (level != TDB_DEBUG_TRACE) { - char *ptr; - signal(SIGUSR1, SIG_IGN); - asprintf(&ptr,"xterm -e gdb /proc/%d/exe %d", getpid(), getpid()); - system(ptr); - free(ptr); - } -#endif -} - -static void fatal(const char *why) -{ - perror(why); - error_count++; -} - -static char *randbuf(int len) -{ - char *buf; - int i; - buf = (char *)malloc(len+1); - - for (i=0;i - - -ldb - - - -

tdb

- -TDB is a Trivial Database. In concept, it is very much like GDBM, and BSD's DB -except that it allows multiple simultaneous writers and uses locking -internally to keep writers from trampling on each other. TDB is also extremely -small. - -

Download

-You can download the latest releases of tdb from the tdb directory on the samba public -source archive. - - -

Discussion and bug reports

- -tdb does not currently have its own mailing list or bug tracking -system. For now, please use the samba-technical -mailing list, and the Samba -bugzilla bug tracking system. - -

Download

- -You can download the latest code either via git or rsync.
-
-To fetch via git see the following guide:
-Using Git for Samba Development
-Once you have cloned the tree switch to the master branch and cd into the source/lib/tdb directory.
-
-To fetch via rsync use these commands: - -
-  rsync -Pavz samba.org::ftp/unpacked/standalone_projects/lib/tdb .
-  rsync -Pavz samba.org::ftp/unpacked/standalone_projects/lib/replace .
-
- -and build in tdb. It will find the replace library in the directory -above automatically. - - - diff --git a/bundled/tdb/wscript b/bundled/tdb/wscript deleted file mode 100644 index 2fdd67f2..00000000 --- a/bundled/tdb/wscript +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env python - -APPNAME = 'tdb' -VERSION = '1.2.3' - -blddir = 'bin' - -import sys, os - -# find the buildtools directory -srcdir = '.' -while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5: - srcdir = '../' + srcdir -sys.path.insert(0, srcdir + '/buildtools/wafsamba') - -import wafsamba, samba_dist, Options, Logs - -samba_dist.DIST_DIRS('lib/tdb:. lib/replace:lib/replace buildtools:buildtools') - -def set_options(opt): - opt.BUILTIN_DEFAULT('replace') - opt.BUNDLED_EXTENSION_DEFAULT('tdb', noextension='tdb') - opt.RECURSE('lib/replace') - if opt.IN_LAUNCH_DIR(): - opt.add_option('--disable-python', - help=("disable the pytdb module"), - action="store_true", dest='disable_python', default=False) - - -def configure(conf): - conf.RECURSE('lib/replace') - - conf.env.standalone_tdb = conf.IN_LAUNCH_DIR() - - if not conf.env.standalone_tdb: - if conf.CHECK_BUNDLED_SYSTEM('tdb', minversion=VERSION, - implied_deps='replace'): - conf.define('USING_SYSTEM_TDB', 1) - - conf.env.disable_python = getattr(Options.options, 'disable_python', False) - - conf.CHECK_XSLTPROC_MANPAGES() - - if not conf.env.disable_python: - # also disable if we don't have the python libs installed - conf.check_tool('python') - conf.check_python_version((2,4,2)) - conf.check_python_headers(mandatory=False) - if not conf.env.HAVE_PYTHON_H: - Logs.warn('Disabling pytdb as python devel libs not found') - conf.env.disable_python = True - - conf.SAMBA_CONFIG_H() - -def build(bld): - bld.RECURSE('lib/replace') - - COMMON_SRC = bld.SUBDIR('common', - '''check.c error.c tdb.c traverse.c - freelistcheck.c lock.c dump.c freelist.c - io.c open.c transaction.c''') - - if not bld.CONFIG_SET('USING_SYSTEM_TDB'): - bld.SAMBA_LIBRARY('tdb', - COMMON_SRC, - deps='replace rt', - includes='include', - abi_file='ABI/tdb-%s.sigs' % VERSION, - abi_match='tdb_*', - hide_symbols=True, - vnum=VERSION, is_bundled=not bld.env.standalone_tdb) - - bld.SAMBA_BINARY('tdbtorture', - 'tools/tdbtorture.c', - 'tdb', - install=False) - - bld.SAMBA_BINARY('tdbdump', - 'tools/tdbdump.c', - 'tdb', manpages='manpages/tdbdump.8') - - bld.SAMBA_BINARY('tdbbackup', - 'tools/tdbbackup.c', - 'tdb', - manpages='manpages/tdbbackup.8') - - bld.SAMBA_BINARY('tdbtool', - 'tools/tdbtool.c', - 'tdb', manpages='manpages/tdbtool.8') - - s4_build = getattr(bld.env, '_SAMBA_BUILD_', 0) == 4 - - bld.SAMBA_PYTHON('pytdb', - 'pytdb.c', - deps='tdb', - enabled=not bld.env.disable_python, - realname='tdb.so') - - if bld.env.standalone_tdb: - bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig' - bld.PKG_CONFIG_FILES('tdb.pc', vnum=VERSION) - bld.INSTALL_FILES('${INCLUDEDIR}', 'include/tdb.h', flat=True) - - -def test(ctx): - '''run tdb testsuite''' - import Utils - cmd = os.path.join(Utils.g_module.blddir, 'tdbtorture') - os.system(cmd) - -def dist(): - '''makes a tarball for distribution''' - samba_dist.dist() diff --git a/configure.ac b/configure.ac index f8708440..dff3f9e5 100644 --- a/configure.ac +++ b/configure.ac @@ -388,7 +388,7 @@ if ! $PERL ./infrastructure/makebuildenv.pl \ fi cat parcels.txt | sed -e 's/#.*//' | while read cmd subdir configure_args; do - if test "$cmd" = "configure"; then + if test "$cmd" = "subdir"; then echo export CC CXX CXXFLAGS LDFLAGS LIBS args="$configure_args --target=$target_alias" diff --git a/infrastructure/makebuildenv.pl.in b/infrastructure/makebuildenv.pl.in index 56f7742e..f165accc 100755 --- a/infrastructure/makebuildenv.pl.in +++ b/infrastructure/makebuildenv.pl.in @@ -252,9 +252,6 @@ for(@modules_files) # check directory exists die "Module $mod can't be found\n" unless -d $mod; - - # skip bundled libraries with their own Makefile process - next if ($mod =~ m|^bundled/|); # and put in lists push @modules,$mod; @@ -513,20 +510,9 @@ __E } } - # make include path - my $include_paths = ""; - foreach my $mod (@all_deps_for_module) - { - if ($mod =~ m|^bundled/| and -d "$mod/include") - { - $include_paths .= "-I../../$mod/include "; - } - else - { - $include_paths .= "-I../../$mod "; - } - } + # make include path + my $include_paths = join(' ',map {'-I../../'.$_} @all_deps_for_module); # is target a library? my $target_is_library = ($type ne 'bin' && $type ne 'test'); @@ -788,18 +774,13 @@ __E { $dep_target = "\$(OUTBASE)/$dep/$1.a"; } - elsif ($dep =~ m|^bundled/(.*)|) - { - $dep_target = "lib$1.a"; - } - elsif ($dep =~ m|^bin/(.*)|) + elsif ($dep =~ m|^.*/(.*)|) { $dep_target = "\$(OUTBASE)/$dep/$1$platform_exe_ext"; } else { - die "Don't know how to add compile-time " . - "dependency on $dep"; + $dep_target = "lib$dep.a"; } $deps_makeinfo .= < + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/qdbm/ChangeLog b/qdbm/ChangeLog new file mode 100644 index 00000000..3fae65dd --- /dev/null +++ b/qdbm/ChangeLog @@ -0,0 +1,990 @@ +2007-10-18 Mikio Hirabayashi + + - A potential defect related to leaf division of B+ tree was cleared. + - Release: 1.8.77 + +2007-03-07 Mikio Hirabayashi + + - The hash function of on-memory map was optimized. + - A bug related to large object was fixed. + - Release: 1.8.76 + +2006-11-10 Mikio Hirabayashi + + - The utility API was enhanced. + - A bug related to B+ tree API for Ruby was fixed. + - Release: 1.8.75 + +2006-11-02 Mikio Hirabayashi + + - A bug related to optimization on Intel Mac series was escaped. + - Release: 1.8.74 + +2006-10-20 Mikio Hirabayashi + + - A bug related to BZIP2 encoding was fixed. + - Release: 1.8.73 + +2006-10-06 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.8.72 + +2006-08-24 Mikio Hirabayashi + + - Makefile was modified to assure portability. + - Silent flag was added to the C++ API, the Java API, and the Ruby API. + - Release: 1.8.71 + +2006-08-18 Mikio Hirabayashi + + - A bug of segmentation fault on BSD was fixed. + - A test command for checking multi thread safety was added. + - Release: 1.8.70 + +2006-08-15 Mikio Hirabayashi + + - Mutex controll in C++ API became refined. + - Release: 1.8.69 + +2006-08-08 Mikio Hirabayashi + + - A bug about memory alignment was fixed. + - A bug of handling meta data on big endian platforms was fixed. + - Release: 1.8.68 + +2006-08-05 Mikio Hirabayashi + + - A bug about memory alignment was fixed. + - A bug about parsing MIME was fixed. + - Release: 1.8.67 + +2006-08-05 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.8.66 + +2006-08-03 Mikio Hirabayashi + + - The extended API was enhanced. + - The extended advanced API was enhanced. + - Release: 1.8.65 + +2006-07-28 Mikio Hirabayashi + + - A bug of Makefile ralated to optimization was fixed. + - Release: 1.8.64 + +2006-07-24 Mikio Hirabayashi + + - A lot of functions were replaced by macros. + - The utility API was enhanced. + - Release: 1.8.63 + +2006-07-20 Mikio Hirabayashi + + - A lot of functions were replaced by macros. + - The URL resolver was to allow unescaped meta characters. + - The advanced API was enhanced. + - Release: 1.8.62 + +2006-07-14 Mikio Hirabayashi + + - A bug of the size checking function of the extended API was fixed. + - The advanced API was enhanced. + - Release: 1.8.61 + +2006-06-03 Mikio Hirabayashi + + - The basic API was enhanced. + - The extended API was enhanced. + - The advanced API was enhanced. + - Multiple cursor class is now supported on the java API. + - Release: 1.8.60 + +2006-05-30 Mikio Hirabayashi + + - The basic API was enhanced. + - The extended API was enhanced. + - The advanced API was enhanced. + - A bug of Makefile for Mac OS X support was fixed. + - Release: 1.8.59 + +2006-05-28 Mikio Hirabayashi + + - The basic API was enhanced. + - The advanced API was enhanced. + - Release: 1.8.58 + +2006-05-20 Mikio Hirabayashi + + - The basic API was enhanced. + - The utility API was enhanced. + - Release: 1.8.57 + +2006-05-17 Mikio Hirabayashi + + - A bug of URL decoder was fixed. + - Release: 1.8.56 + +2006-05-15 Mikio Hirabayashi + + - The extended API was enhanced. + - The utility API was enhanced. + - Release: 1.8.55 + +2006-05-15 Mikio Hirabayashi + + - The basic API was enhanced. + - Release: 1.8.54 + +2006-05-10 Mikio Hirabayashi + + - AIX is now supported. + - The utility API was enhanced. + - Release: 1.8.53 + +2006-05-04 Mikio Hirabayashi + + - A bug about evaluating RFC822 date format was fixed. + - Release: 1.8.52 + +2006-05-02 Mikio Hirabayashi + + - A bug about evaluating RFC822 date format was fixed. + - Warings from GCC 4.1.x were dealt with. + - Missing functions in qdbm.def were supplied. + - Release: 1.8.51 + +2006-04-28 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.8.50 + +2006-04-19 Mikio Hirabayashi + + - A parameter of dynamic linking library on Mac OS X was modified. + - The utility API was enhanced. + - Release: 1.8.49 + +2006-03-27 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.8.48 + +2006-03-10 Mikio Hirabayashi + + - LTmakefile was modified. + - The utility API was enhanced. + - Release: 1.8.47 + +2006-02-20 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.8.46 + +2006-01-28 Mikio Hirabayashi + + - Alignment algorithm was improved. + - A bug of mmap emulation on Windows was fixed. + - Release: 1.8.45 + +2006-01-24 Mikio Hirabayashi + + - A bug of handling meta data on big endian platforms was fixed. + - The advanced API was enhanced. + - Release: 1.8.44 + +2006-01-24 Mikio Hirabayashi + + - A bug of mmap emulation on Windows was fixed. + - Release: 1.8.43 + +2006-01-22 Mikio Hirabayashi + + - mmap emulation on Windows was enhanced. + - Release: 1.8.42 + +2006-01-13 Mikio Hirabayashi + + - Compression of pages of B+ tree with LZO and BZIP was added. + - Release: 1.8.41 + +2006-01-08 Mikio Hirabayashi + + - Configuration for VC++ was to build DLL. + - Release: 1.8.40 + +2006-01-04 Mikio Hirabayashi + + - The advanced API was enhanced. + - Release: 1.8.39 + +2006-01-01 Mikio Hirabayashi + + - The advanced API was enhanced. + - Release: 1.8.38 + +2005-12-26 Mikio Hirabayashi + + - Functions to set the size of the free block pool were added. + - Commands line tools were enhanced. + - Release: 1.8.37 + +2005-12-24 Mikio Hirabayashi + + - Free block pool was enhanced. + - Commands line tools were enhanced. + - Release: 1.8.36 + +2005-11-30 Mikio Hirabayashi + + - The utility API was enhanced. + - The extended advanced API was enhanced. + - All stat calls were replaced with lstat calls. + - Release: 1.8.35 + +2005-11-22 Mikio Hirabayashi + + - A bug of i-node duplication on MinGW was fixed. + - Release: 1.8.34 + +2005-09-09 Mikio Hirabayashi + + - Compressing options of ZLIB was changed. + - The utility API was enhanced. + - Release: 1.8.33 + +2005-08-30 Mikio Hirabayashi + + - A bug of backward string matching was fixed. + - The utility API was enhanced. + - Release: 1.8.32 + +2005-06-19 Mikio Hirabayashi + + - A bug of the MIME parser was fixed. + - A bug about database repair on Win32 was fixed. + - A bug of Makefile for Mac OS X support was fixed. + - The type of error codes of GDBM-compatibility API was changed. + - Release: 1.8.31 + +2005-06-09 Mikio Hirabayashi + + - A Bug of APIs for C++ related to namespace was fixed. + - The library of shared objects of C++ APIs was added. + - The utility API was enhanced. + - Release: 1.8.30 + +2005-06-01 Mikio Hirabayashi + + - A bug about file locking on Win32 was fixed. + - Manuals of command line tools were added. + - The utility API was enhanced. + - Release: 1.8.29 + +2005-05-27 Mikio Hirabayashi + + - A compilation problem on hppa-linux was fixed. + - A configuration file for pkg-config was added. + - Release: 1.8.28 + +2005-05-18 Mikio Hirabayashi + + - Non-blocking lock was featured. + - Release: 1.8.27 + +2005-05-12 Mikio Hirabayashi + + - The inverted API was enhanced. + - The utility API was enhanced. + - Release: 1.8.26 + +2005-05-10 Mikio Hirabayashi + + - The inverted API was enhanced. + - The utility API was enhanced. + - Release: 1.8.25 + +2005-04-25 Mikio Hirabayashi + + - The utility API was enhanced. + - A bug about database repair on Win32 was fixed. + - Release: 1.8.24 + +2005-04-01 Mikio Hirabayashi + + - The utility API was enhanced. + - The extended advanced API was enhanced. + - Release: 1.8.23 + +2005-03-24 Mikio Hirabayashi + + - The extended advanced API was enhanced. + - The utility API was enhanced. + - The inverted API was enhanced. + - Test commands were enhanced. + - Release: 1.8.22 + +2005-01-22 Mikio Hirabayashi + + - Functions to dump endian independent data was added. + - Release: 1.8.21 + +2005-01-05 Mikio Hirabayashi + + - Sparse file support was added. + - Release: 1.8.20 + +2005-01-02 Mikio Hirabayashi + + - The utility API was enhanced. + - Building configurations were enhanced. + - Release: 1.8.19 + +2004-11-10 Mikio Hirabayashi + + - The utility API was enhanced. + - The extended advanced API was enhanced. + - The inverted API was enhanced. + - Release: 1.8.18 + +2004-09-20 Mikio Hirabayashi + + - The utility API was enhanced. + - The CGI script for file upload was enhanced. + - The spec file for RPM packages was enhanced. + - Release: 1.8.17 + +2004-08-17 Mikio Hirabayashi + + - A bug in the extended API was fixed. + - A bug about seek on Windows 9x was fixed. + - The CGI script for file upload was enhanced. + - Release: 1.8.16 + +2004-08-04 Mikio Hirabayashi + + - The utility API was enhanced. + - A bug about mmap on Mac OS X was fixed. + - A CGI script for file upload was added. + - Building configurations were enhanced. + - Release: 1.8.15 + +2004-07-19 Mikio Hirabayashi + + - The basic API was enhanced. + - The extended API was enhanced. + - The advanced API was enhanced. + - The inverted API was enhanced. + - Building configurations were enhanced. + - Release: 1.8.14 + +2004-07-07 Mikio Hirabayashi + + - The utility API was enhanced. + - The inverted API was enhanced. + - Release: 1.8.13 + +2004-05-18 Mikio Hirabayashi + + - The utility API was enhanced. + - The inverted API was enhanced. + - Building configurations were enhanced. + - Release: 1.8.12 + +2004-05-12 Mikio Hirabayashi + + - The utility API was enhanced. + - Source codes were cleaned up for Visual C++. + - Test commands were enhanced. + - Building configurations were enhanced. + - Release: 1.8.11 + +2004-04-23 Mikio Hirabayashi + + - Utility for performance test was enhanced. + - It was escaped from a bug about mmap on FreeBSD and NetBSD. + - Release: 1.8.10 + +2004-04-20 Mikio Hirabayashi + + - Logger for debugging is now featured. + - It was escaped from a bug about mmap on OpenBSD. + - Release: 1.8.9 + +2004-04-11 Mikio Hirabayashi + + - Processing speed was improved. + - The basic API was enhanced. + - The extended API was enhanced. + - The configuration for VC++ was enhanced. + - Release: 1.8.8 + +2004-03-25 Mikio Hirabayashi + + - The configuration of C++ API escaped from a bug of pthread. + - Release: 1.8.7 + +2004-03-21 Mikio Hirabayashi + + - The extended API was enhanced. + - Bugs in the utility API about memory management were fixed. + - Release: 1.8.6 + +2004-03-12 Mikio Hirabayashi + + - A bug in the utility API for 64-bit platforms was fixed. + - The utility API was enhanced. + - Release: 1.8.5 + +2004-03-09 Mikio Hirabayashi + + - Runtime switching of whether to use ZLIB was featured. + - The binary package for Win32 now features ZLIB and ICONV. + - The utility API was enhanced. + - Release: 1.8.4 + +2004-03-06 Mikio Hirabayashi + + - The utility API was enhanced. + - A utility class of Java API was enhanced. + - Test commands were enhanced. + - Release: 1.8.3 + +2004-03-01 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.8.2 + +2004-02-22 Mikio Hirabayashi + + - Processing speed of multi-thread support was improved. + - Release: 1.8.1 + +2004-02-21 Mikio Hirabayashi + + - Switch to make API for C thread-safe was added. + - Release: 1.8.0 + +2004-02-18 Mikio Hirabayashi + + - The utility API was enhanced. + - Potential bugs in APIs for C++ were fixed. + - Release: 1.7.34 + +2004-01-28 Mikio Hirabayashi + + - The extended API was enhanced. + - The inverted API was enhanced. + - Release: 1.7.33 + +2004-01-17 Mikio Hirabayashi + + - The inverted API was enhanced. + - Release: 1.7.32 + +2004-01-16 Mikio Hirabayashi + + - The inverted API was enhanced. + - Release: 1.7.31 + +2004-01-12 Mikio Hirabayashi + + - The inverted API was enhanced. + - Release: 1.7.30 + +2004-01-11 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.7.29 + +2004-01-09 Mikio Hirabayashi + + - A bug in the utility API was fixed. + - Release: 1.7.28 + +2004-01-06 Mikio Hirabayashi + + - A bug in the advanced API was fixed. + - The utility API was enhanced. + - Release: 1.7.27 + +2004-01-04 Mikio Hirabayashi + + - The inverted API was enhanced. + - Release: 1.7.26 + +2004-01-01 Mikio Hirabayashi + + - The inverted API was enhanced. + - The utility API was enhanced. + - Release: 1.7.25 + +2003-12-26 Mikio Hirabayashi + + - C++ export was supported in header files. + - The utility API was enhanced. + - Release: 1.7.24 + +2003-12-21 Mikio Hirabayashi + + - Repairing utility was added to the advanced API. + - The basic API was enhanced. + - The utility API was enhanced. + - Release: 1.7.23 + +2003-12-16 Mikio Hirabayashi + + - Repairing utility was added to the extended API. + - The utility API was enhanced. + - Release: 1.7.22 + +2003-12-14 Mikio Hirabayashi + + - A utility to repair a broken database file was added. + - A ulitity command for full-text search was enhanced. + - Release: 1.7.21 + +2003-12-10 Mikio Hirabayashi + + - Character encoding converter was added. + - Release: 1.7.20 + +2003-12-10 Mikio Hirabayashi + + - Format converter for older versions than 1.7.13 was added. + - Tuning paramters of the inverted API were modified. + - A CGI script for full-text search was enhanced. + - Release: 1.7.19 + +2003-12-08 Mikio Hirabayashi + + - The utility API was enhanced. + - The GDBM-compatible API was enhanced. + - Release: 1.7.18 + +2003-12-05 Mikio Hirabayashi + + - The utility API was enhanced. + - A CGI script for full-text search was enhanced. + - Release: 1.7.17 + +2003-12-01 Mikio Hirabayashi + + - A CGI script for full-text search was enhanced. + - A ulitity command for full-text search was enhanced. + - Building configuration files were modified. + - Release: 1.7.16 + +2003-11-30 Mikio Hirabayashi + + - A CGI script for full-text search was enhanced. + - A ulitity command for full-text search was enhanced. + - Release: 1.7.15 + +2003-11-29 Mikio Hirabayashi + + - The inverted API was enhanced. + - A ulitity command for full-text search was enhanced. + - A CGI script for full-text search was enhanced. + - Release: 1.7.14 + +2003-11-27 Mikio Hirabayashi + + - Format of headers of database was modified. + - Supporting endian conversion was abolished. + - Import/export features were added to utility commands. + - A ulitity command for full-text search was enhanced. + - A CGI script for full-text search was enhanced. + - Release: 1.7.13 + +2003-11-25 Mikio Hirabayashi + + - The utility API was enhanced. + - The inverted API was enhanced. + - A ulitity command for full-text search was enhanced. + - A CGI script for full-text search was enhanced. + - Release: 1.7.12 + +2003-11-23 Mikio Hirabayashi + + - The inverted API was enhanced. + - A ulitity command for full-text search was enhanced. + - A CGI script for full-text search was enhanced. + - A utility class of Java API was enhanced. + - Release: 1.7.11 + +2003-11-20 Mikio Hirabayashi + + - A utility class of Java API was enhanced. + - Building configuration for CGI scripts was modified. + - Release: 1.7.10 + +2003-11-20 Mikio Hirabayashi + + - Tuning paramters of the inverted API were modified. + - A ulitity command for full-text search was enhanced. + - Release: 1.7.9 + +2003-11-16 Mikio Hirabayashi + + - Optional features of compressing with ZLIB were added. + - Release: 1.7.8 + +2003-11-05 Mikio Hirabayashi + + - The extended advanced API, Vista was added. + - Release: 1.7.7 + +2003-11-03 Mikio Hirabayashi + + - C API compilation using Visual C++ was supported. + - Odeum and its commands were enhanced. + - Release: 1.7.6 + +2003-10-25 Mikio Hirabayashi + + - A ulitity command for full-text search was enhanced. + - A CGI script for full-text search was enhanced. + - Release: 1.7.5 + +2003-10-23 Mikio Hirabayashi + + - A CGI script for full-text search was added. + - A bug of BSD support in Makefile was fixed. + - Release: 1.7.4 + +2003-10-19 Mikio Hirabayashi + + - Processing speed of the inverted API was improved. + - A ulitity command for full-text search was enhanced. + - Release: 1.7.3 + +2003-10-17 Mikio Hirabayashi + + - The license was changed to LGPL. + - An indexing command for the inverted API was added. + - Release: 1.7.2 + +2003-10-14 Mikio Hirabayashi + + - A test command for the inverted API was added. + - A bug about optimization in the inverted API was fixed. + - Tuning paramters of the inverted API were modified. + - Release: 1.7.1 + +2003-10-13 Mikio Hirabayashi + + - The inverted API, Odeum was added. + - Comments in source codes increased. + - Release: 1.7.0 + +2003-10-05 Mikio Hirabayashi + + - Executable commands were modified for RISC OS. + - Release: 1.6.22 + +2003-10-05 Mikio Hirabayashi + + - Executable commands were modified for RISC OS. + - Release: 1.6.21 + +2003-09-30 Mikio Hirabayashi + + - Naming file in RISC OS style was supported. + - Hash functions were enhanced. + - Release: 1.6.20 + +2003-09-26 Mikio Hirabayashi + + - The utility API was enhanced. + - Test commands were added. + - Release: 1.6.19 + +2003-09-22 Mikio Hirabayashi + + - Makefile for RISC OS was added. + - C++ API was enhanced. + - Release: 1.6.18 + +2003-09-14 Mikio Hirabayashi + + - Test commands were enhanced. + - Source codes and Makefile were modified for RISC OS. + - The CGI script was enhanced. + - Release: 1.6.17 + +2003-09-13 Mikio Hirabayashi + + - The CGI script for administration was added. + - C++ API was enhanced. + - Release: 1.6.16 + +2003-08-28 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.6.15 + +2003-08-16 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.6.14 + +2003-08-11 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.6.13 + +2003-08-05 Mikio Hirabayashi + + - A bug in the utility API was fixed. + - Test commands were enhanced. + - Release: 1.6.12 + +2003-07-31 Mikio Hirabayashi + + - C and Java APIs support compilation using MinGW. + - Release: 1.6.11 + +2003-07-27 Mikio Hirabayashi + + - Perl and Ruby APIs support transaction. + - Release: 1.6.10 + +2003-07-26 Mikio Hirabayashi + + - Speed of transaction was improved. + - Release: 1.6.9 + +2003-07-24 Mikio Hirabayashi + + - C++ and Java APIs of B+ tree support transaction. + - Release: 1.6.8 + +2003-07-21 Mikio Hirabayashi + + - C API of B+ tree supports transaction. + - Bugs about Mutex in C++ and Java APIs were fixed. + - Release: 1.6.7 + +2003-07-18 Mikio Hirabayashi + + - C++ and Java APIs of database abstraction were simplified. + - Ruby API of B+ tree was simplified. + - Release: 1.6.6 + +2003-07-16 Mikio Hirabayashi + + - Ruby API of B+ tree was added. + - C, C++, Java and Perl APIs of B+ tree were enhanced. + - Release: 1.6.5 + +2003-07-13 Mikio Hirabayashi + + - Perl API of B+ tree was added. + - C, C++ and Java APIs of B+ tree were enhanced. + - Release: 1.6.4 + +2003-07-08 Mikio Hirabayashi + + - Java API of B++ tree was added. + - C API of B+ tree was enhanced. + - C++ API of B+ tree was enhanced. + - Release: 1.6.3 + +2003-07-05 Mikio Hirabayashi + + - Debug routines were removed and speed was improved. + - No locking mode was added. + - Endian converter of Villa was added. + - C++ API of B++ tree was added. + - Release: 1.6.2 + +2003-07-03 Mikio Hirabayashi + + - The advanced API was enhanced to improve its speed. + - Makefiles were enhanced for HP-UX. + - Release: 1.6.1 + +2003-06-28 Mikio Hirabayashi + + - The advanced API for B+ tree database is added. + - Release: 1.6.0 + +2003-06-23 Mikio Hirabayashi + + - Makefiles were enhanced for Mac OS X. + - Release: 1.5.13 + +2003-06-18 Mikio Hirabayashi + + - Makefile was enhanced for Solaris and Mac OS X. + - Release: 1.5.12 + +2003-06-06 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.5.11 + +2003-05-31 Mikio Hirabayashi + + - The utility API was enhanced. + - Release: 1.5.10 + +2003-05-29 Mikio Hirabayashi + + - The utility API was changed. + - Release: 1.5.9 + +2003-05-25 Mikio Hirabayashi + + - Alignment mechanism was simplified. + - Release: 1.5.8 + +2003-05-17 Mikio Hirabayashi + + - Makefile was updated + - Release: 1.5.7 + +2003-05-16 Mikio Hirabayashi + + - Test tools were enhanced. + - Release: 1.5.6 + +2003-05-14 Mikio Hirabayashi + + - Makefile using libtool was added. + - Release: 1.5.5 + +2003-05-12 Mikio Hirabayashi + + - API for Ruby was enhanced. + - Release: 1.5.4 + +2003-05-08 Mikio Hirabayashi + + - API for Ruby was added. + - Release: 1.5.3 + +2003-05-04 Mikio Hirabayashi + + - API for Perl was enhanced. + - Release: 1.5.2 + +2003-04-30 Mikio Hirabayashi + + - API for Perl was enhanced. + - Release: 1.5.1 + +2003-04-29 Mikio Hirabayashi + + - API for Perl was added. + - Release: 1.5.0 + +2003-04-25 Mikio Hirabayashi + + - The package was reorganized to be a GNU package. + - Release: 1.4.11 + +2003-04-21 Mikio Hirabayashi + + - The utility API was added. + - Release: 1.4.10 + +2003-04-15 Mikio Hirabayashi + + - Endian converters were added. + - Release: 1.4.9 + +2003-04-12 Mikio Hirabayashi + + - The GDBM-compatible API was enhanced. + - Release: 1.4.8 + +2003-04-10 Mikio Hirabayashi + + - Some bugs were fixed and C++ API was enhanced. + - Release: 1.4.7 + +2003-04-09 Mikio Hirabayashi + + - Coalescence of dead regions and reuse of them were featured. + - Release: 1.4.6 + +2003-04-06 Mikio Hirabayashi + + - The GDBM-compatible API and the C++ API were enhanced. + - Release: 1.4.5 + +2003-04-04 Mikio Hirabayashi + + - The API for C++ and the API for Java were enhanced. + - Release: 1.4.4 + +2003-04-02 Mikio Hirabayashi + + - Documents for C++ was enhanced. + - Release: 1.4.3 + +2003-04-01 Mikio Hirabayashi + + - The API for Java was enhanced. + - Release: 1.4.2 + +2003-03-23 Mikio Hirabayashi + + - Makefiles were modified. + - Release: 1.4.1 + +2003-03-23 Mikio Hirabayashi + + - APIs for C++ and Java was enhanced. + - Release: 1.4.0 + +2003-03-15 Mikio Hirabayashi + + - The API for C++ was added. + - Release: 1.3.2 + +2003-03-11 Mikio Hirabayashi + + - The API for Java was supported on Solaris and Windows. + - Release: 1.3.1 + +2003-03-04 Mikio Hirabayashi + + - The API for Java was added. + - Release: 1.3.0 + +2003-02-23 Mikio Hirabayashi + + - The GDBM-compatible API was added. + - Release: 1.2.0 + +2003-02-21 Mikio Hirabayashi + + - Compatibility with NDBM was improved. + - Release: 1.1.3 + +2003-02-18 Mikio Hirabayashi + + - Optimizing suppoted on Windows. DLL is supported. + - Release: 1.1.2 + +2003-02-15 Mikio Hirabayashi + + - Windows is now supported. + - The compatible API was enhanced. + - Release: 1.1.1 + +2003-02-11 Mikio Hirabayashi + + - The NDBM-compatible API was added. + - Release: 1.1.0 + +2003-02-08 Mikio Hirabayashi + + - The initial version. + - Release: 1.0.0 + diff --git a/qdbm/LTmakefile.in b/qdbm/LTmakefile.in new file mode 100644 index 00000000..547abccf --- /dev/null +++ b/qdbm/LTmakefile.in @@ -0,0 +1,318 @@ +# Makefile to build QDBM using libtool + + + +#================================================================ +# Setting variables +#================================================================ + + +# Generic settings +SHELL = @SHELL@ + +# Packaging +PACKAGE = @PACKAGE_NAME@ +VERSION = @PACKAGE_VERSION@ +LIBVER = @LIBVER@ +LIBREV = @LIBREV@ + +# Targets +MYHEADS = depot.h curia.h relic.h hovel.h cabin.h villa.h vista.h odeum.h +MYLIBOBJS = depot.lo curia.lo relic.lo hovel.lo cabin.lo villa.lo vista.lo odeum.lo myconf.lo +MYLIBS = libqdbm.la +MYBINS = dpmgr dptest dptsv crmgr crtest crtsv rlmgr rltest hvmgr hvtest \ + cbtest cbcodec vlmgr vltest vltsv odmgr odtest odidx qmttest +MYMAN1S = dpmgr.1 dptest.1 dptsv.1 crmgr.1 crtest.1 crtsv.1 rlmgr.1 rltest.1 hvmgr.1 hvtest.1 \ + cbtest.1 cbcodec.1 vlmgr.1 vltest.1 vltsv.1 odmgr.1 odtest.1 odidx.1 qmttest.1 +MYMAN3S = qdbm.3 depot.3 dpopen.3 curia.3 cropen.3 relic.3 hovel.3 \ + cabin.3 villa.3 vlopen.3 vista.3 odeum.3 odopen.3 +MYDOCS = spex.html spex-ja.html COPYING ChangeLog NEWS THANKS +MYPCS = qdbm.pc + +# Install destinations +prefix = @prefix@ +exec_prefix = @exec_prefix@ +MYHEADDIR = @includedir@ +MYLIBDIR = @libdir@ +MYBINDIR = @bindir@ +MYMAN1DIR = @mandir@/man1 +MYMAN3DIR = @mandir@/man3 +MYSHAREDIR = $(prefix)/share/$(PACKAGE) +MYPCDIR = @libdir@/pkgconfig + +# Building binaries +LIBTOOL = libtool +CC = gcc +CFLAGS = -I. -I$(MYHEADDIR) -I$(HOME)/include -I/usr/local/include @MYDEFS@ \ + -D_XOPEN_SOURCE_EXTENDED=1 -D_GNU_SOURCE=1 -D__EXTENSIONS__=1 -D_HPUX_SOURCE=1 \ + -D_POSIX_MAPPED_FILES=1 -D_POSIX_SYNCHRONIZED_IO=1 \ + -DPIC=1 -D_THREAD_SAFE=1 -D_REENTRANT=1 -DNDEBUG -O3 +LD = gcc +LIBLDFLAGS = -rpath $(MYLIBDIR) -R $(MYLIBDIR) \ + -version-info $$(($(LIBVER)+$(LIBREV))):0:$(LIBREV) @LIBS@ +LDFLAGS = -rpath $(MYLIBDIR) -R $(MYLIBDIR) -L. -lqdbm @LIBS@ +INSTALL = install +MKDIR = mkdir -p +CP = cp -rf +RM = rm -rf + + + +#================================================================ +# Suffix rules +#================================================================ + + +.SUFFIXES : +.SUFFIXES : .c .lo + +.c.lo : + $(LIBTOOL) --mode=compile --tag=CC $(CC) -c $(CFLAGS) $< + + + +#================================================================ +# Actions +#================================================================ + + +all : $(MYLIBS) $(MYBINS) + @printf '\n' + @printf '#================================================================\n' + @printf '# Ready to install.\n' + @printf '#================================================================\n' + + +clean : + $(RM) $(MYLIBS) $(MYBINS) *.o *.a *.so *.lo *.la a.out .libs \ + *.exe *.dll.a *.dll TAGS srcdoc gmon.out leak.log casket casket.* *~ + + +install : + $(LIBTOOL) --mode=install $(INSTALL) $(MYHEADS) $(MYHEADDIR) + $(LIBTOOL) --mode=install $(INSTALL) $(MYLIBS) $(MYLIBDIR) + $(LIBTOOL) --mode=install $(INSTALL) $(MYBINS) $(MYBINDIR) + $(MKDIR) $(MYMAN1DIR) + cd man && $(CP) $(MYMAN1S) $(MYMAN1DIR) + $(MKDIR) $(MYMAN3DIR) + cd man && $(CP) $(MYMAN3S) $(MYMAN3DIR) + $(MKDIR) $(MYSHAREDIR) + $(CP) $(MYDOCS) $(MYSHAREDIR) + $(MKDIR) $(MYPCDIR) + $(CP) $(MYPCS) $(MYPCDIR) + @printf '\n' + @printf '#================================================================\n' + @printf '# Thanks for using QDBM.\n' + @printf '#================================================================\n' + + +uninstall : + cd $(MYHEADDIR) && $(LIBTOOL) --mode=uninstall $(RM) $(MYHEADS) + cd $(MYLIBDIR) && $(LIBTOOL) --mode=uninstall $(RM) $(MYLIBS) + cd $(MYBINDIR) && $(LIBTOOL) --mode=uninstall $(RM) $(MYBINS) + cd $(MYMAN1DIR) && $(RM) $(MYMAN1S) + cd $(MYMAN3DIR) && $(RM) $(MYMAN3S) + $(RM) $(MYSHAREDIR) + cd $(MYPCDIR) && $(RM) $(MYPCS) + + +distclean : clean + $(RM) Makefile LTmakefile rpmspec config.cache config.log config.status autom4te.cache + + +check : + $(RM) casket* + $(LIBTOOL) --mode=execute ./dptest write -s casket 500 500000 + $(LIBTOOL) --mode=execute ./dptest write casket 50000 5000 + $(LIBTOOL) --mode=execute ./dptest read casket + $(LIBTOOL) --mode=execute ./dptest read -wb casket + $(LIBTOOL) --mode=execute ./dptest rcat -c casket 50000 50 500 32 8 + $(LIBTOOL) --mode=execute ./dptest combo casket + $(LIBTOOL) --mode=execute ./dptest wicked -c casket 5000 + $(LIBTOOL) --mode=execute ./dptest wicked casket 500 + $(LIBTOOL) --mode=execute ./dpmgr repair casket + $(LIBTOOL) --mode=execute ./dpmgr optimize casket + $(LIBTOOL) --mode=execute ./dpmgr list casket + $(RM) casket* + $(LIBTOOL) --mode=execute ./crtest write -s casket 500 100000 5 + $(LIBTOOL) --mode=execute ./crtest write casket 50000 500 10 + $(LIBTOOL) --mode=execute ./crtest read casket + $(LIBTOOL) --mode=execute ./crtest read -wb casket + $(LIBTOOL) --mode=execute ./crtest rcat -c casket 50000 5 10 500 32 8 + $(LIBTOOL) --mode=execute ./crtest combo casket + $(LIBTOOL) --mode=execute ./crtest wicked -c casket 5000 + $(LIBTOOL) --mode=execute ./crtest wicked casket 500 + $(LIBTOOL) --mode=execute ./crmgr repair casket + $(LIBTOOL) --mode=execute ./crmgr optimize casket + $(LIBTOOL) --mode=execute ./crmgr list casket + $(RM) casket* + $(LIBTOOL) --mode=execute ./crtest write -lob casket 1000 50 10 + $(LIBTOOL) --mode=execute ./crtest read -lob casket + $(RM) casket* + $(LIBTOOL) --mode=execute ./rltest write casket 5000 + $(LIBTOOL) --mode=execute ./rltest read casket 5000 + $(LIBTOOL) --mode=execute ./rlmgr list casket + $(RM) casket* + $(LIBTOOL) --mode=execute ./hvtest write casket 5000 + $(LIBTOOL) --mode=execute ./hvtest read casket 5000 + $(LIBTOOL) --mode=execute ./hvmgr optimize casket + $(LIBTOOL) --mode=execute ./hvmgr list casket + $(RM) casket* + $(LIBTOOL) --mode=execute ./hvtest write -qdbm -s casket 500 + $(LIBTOOL) --mode=execute ./hvtest write -qdbm casket 5000 + $(LIBTOOL) --mode=execute ./hvtest read -qdbm casket 5000 + $(RM) casket* + $(LIBTOOL) --mode=execute ./cbtest sort 5000 + $(LIBTOOL) --mode=execute ./cbtest strstr 500 + $(LIBTOOL) --mode=execute ./cbtest list 50000 + $(LIBTOOL) --mode=execute ./cbtest list -d 500 + $(LIBTOOL) --mode=execute ./cbtest map 50000 500 + $(LIBTOOL) --mode=execute ./cbtest map -d 500 5 + $(LIBTOOL) --mode=execute ./cbtest heap 50000 500 + $(LIBTOOL) --mode=execute ./cbtest heap -d 500 50 + $(LIBTOOL) --mode=execute ./cbtest wicked 5000 + $(LIBTOOL) --mode=execute ./cbtest misc + $(RM) casket* + $(LIBTOOL) --mode=execute ./vltest write -tune 32 31 32 32 casket 50000 + $(LIBTOOL) --mode=execute ./vltest read casket + $(LIBTOOL) --mode=execute ./vltest rdup -tune 32 31 512 256 casket 50000 50000 + $(LIBTOOL) --mode=execute ./vltest combo casket + $(LIBTOOL) --mode=execute ./vltest wicked -c casket 5000 + $(LIBTOOL) --mode=execute ./vltest wicked casket 500 + $(LIBTOOL) --mode=execute ./vlmgr repair casket + $(LIBTOOL) --mode=execute ./vlmgr optimize casket + $(LIBTOOL) --mode=execute ./vlmgr list casket + $(RM) casket* + $(LIBTOOL) --mode=execute ./vltest write -int -cz -tune 32 31 32 32 casket 50000 + $(LIBTOOL) --mode=execute ./vltest read -int -vc casket + $(LIBTOOL) --mode=execute ./vltest rdup -int -cz -cc -tune 32 31 512 256 casket 50000 50000 + $(LIBTOOL) --mode=execute ./vltest combo -cz casket + $(LIBTOOL) --mode=execute ./vltest wicked -cz -c casket 5000 + $(LIBTOOL) --mode=execute ./vltest combo -cy casket + $(LIBTOOL) --mode=execute ./vltest wicked -cy -c casket 5000 + $(LIBTOOL) --mode=execute ./vltest combo -cx casket + $(LIBTOOL) --mode=execute ./vltest wicked -cx -c casket 5000 + $(RM) casket* + $(LIBTOOL) --mode=execute ./odtest write casket 500 50 5000 + $(LIBTOOL) --mode=execute ./odtest read casket + $(LIBTOOL) --mode=execute ./odtest combo casket + $(LIBTOOL) --mode=execute ./odtest wicked casket 500 + $(RM) casket* + $(LIBTOOL) --mode=execute ./qmttest casket 50000 10 + $(RM) casket* + @printf '\n' + @printf '#================================================================\n' + @printf '# Checking completed.\n' + @printf '#================================================================\n' + + +.PHONY : all clean install check + + + +#================================================================ +# Building binaries +#================================================================ + + +libqdbm.la : $(MYLIBOBJS) + $(LIBTOOL) --mode=link --tag=CC $(LD) $(MYLIBOBJS) -o $@ $(LIBLDFLAGS) + + +dpmgr : dpmgr.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ dpmgr.lo $(LDFLAGS) + + +dptest : dptest.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ dptest.lo $(LDFLAGS) + + +dptsv : dptsv.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ dptsv.lo $(LDFLAGS) + + +crmgr : crmgr.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ crmgr.lo $(LDFLAGS) + + +crtest : crtest.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ crtest.lo $(LDFLAGS) + + +crtsv : crtsv.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ crtsv.lo $(LDFLAGS) + + +rlmgr : rlmgr.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ rlmgr.lo $(LDFLAGS) + + +rltest : rltest.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ rltest.lo $(LDFLAGS) + + +hvmgr : hvmgr.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ hvmgr.lo $(LDFLAGS) + + +hvtest : hvtest.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ hvtest.lo $(LDFLAGS) + + +cbtest : cbtest.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ cbtest.lo $(LDFLAGS) + + +cbcodec : cbcodec.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ cbcodec.lo $(LDFLAGS) + + +vlmgr : vlmgr.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ vlmgr.lo $(LDFLAGS) + + +vltest : vltest.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ vltest.lo $(LDFLAGS) + + +vltsv : vltsv.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ vltsv.lo $(LDFLAGS) + + +odmgr : odmgr.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ odmgr.lo $(LDFLAGS) + + +odtest : odtest.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ odtest.lo $(LDFLAGS) + + +odidx : odidx.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ odidx.lo $(LDFLAGS) + + +qmttest : qmttest.lo $(MYLIBS) + $(LIBTOOL) --mode=link --tag=CC $(LD) -o $@ qmttest.lo $(LDFLAGS) + + +depot.lo dpmgr.lo dptest.lo dptsv.lo : depot.h myconf.h + +curia.lo crmgr.lo crtest.lo crtsv.lo : curia.h depot.h myconf.h + +relic.lo rlmgr.lo rltest.lo : relic.h depot.h myconf.h + +hovel.lo hvmgr.lo hvtest.lo : hovel.h depot.h curia.h myconf.h + +cabin.lo cbtest.lo : cabin.h myconf.h + +villa.lo vlmgr.lo vltest.lo vltsv.lo : villa.h depot.h cabin.h myconf.h + +vista.lo : vista.h villa.h depot.h curia.h cabin.h myconf.h villa.c + +odeum.lo odmgr.lo odtest.lo odidx.lo : odeum.h depot.h curia.h cabin.h villa.h myconf.h + +myconf.lo : myconf.h + + + +# END OF FILE diff --git a/qdbm/Makefile.in b/qdbm/Makefile.in new file mode 100644 index 00000000..f87d7e46 --- /dev/null +++ b/qdbm/Makefile.in @@ -0,0 +1,646 @@ +# Makefile for QDBM + + + +#================================================================ +# Setting variables +#================================================================ + + +# Generic settings +SHELL = @SHELL@ +srcdir = @srcdir@ +VPATH = @srcdir@ +SUBDIRS = + +# Packaging +PACKAGE = @PACKAGE_NAME@ +VERSION = @PACKAGE_VERSION@ +PACKAGEDIR = $(PACKAGE)-$(VERSION) +PACKAGETGZ = $(PACKAGE)-$(VERSION).tar.gz +LIBVER = @LIBVER@ +LIBREV = @LIBREV@ + +# Targets +MYHEADS = depot.h curia.h relic.h hovel.h cabin.h villa.h vista.h odeum.h +MYLIBOBJS = depot.o curia.o relic.o hovel.o cabin.o villa.o vista.o odeum.o myconf.o +MYLIBS = libqdbm.a libqdbm.so.$(LIBVER).$(LIBREV).0 libqdbm.so.$(LIBVER) libqdbm.so +MYBINS = dpmgr dptest dptsv crmgr crtest crtsv rlmgr rltest hvmgr hvtest \ + cbtest cbcodec vlmgr vltest vltsv odmgr odtest odidx qmttest +MYMAN1S = dpmgr.1 dptest.1 dptsv.1 crmgr.1 crtest.1 crtsv.1 rlmgr.1 rltest.1 hvmgr.1 hvtest.1 \ + cbtest.1 cbcodec.1 vlmgr.1 vltest.1 vltsv.1 odmgr.1 odtest.1 odidx.1 qmttest.1 +MYMAN3S = qdbm.3 depot.3 dpopen.3 curia.3 cropen.3 relic.3 hovel.3 \ + cabin.3 villa.3 vlopen.3 vista.3 odeum.3 odopen.3 +MYDOCS = spex.html spex-ja.html COPYING ChangeLog NEWS THANKS +MYPCS = qdbm.pc +MYWINLIBS = libqdbm.a libqdbm.dll.a +MYMACLIBS = libqdbm.a libqdbm.$(LIBVER).$(LIBREV).0.dylib libqdbm.$(LIBVER).dylib libqdbm.dylib +MYHPUXLIBS = libqdbm.a libqdbm.sl + +# Install destinations +prefix = @prefix@ +exec_prefix = @exec_prefix@ +MYHEADDIR = @includedir@ +MYLIBDIR = @libdir@ +MYBINDIR = @bindir@ +MYMAN1DIR = @mandir@/man1 +MYMAN3DIR = @mandir@/man3 +MYDATADIR = @datadir@/$(PACKAGE) +MYPCDIR = @libdir@/pkgconfig +DESTDIR = + +# Building binaries +CC = @CC@ +CPPFLAGS = @CPPFLAGS@ -I$(srcdir) -I$(MYHEADDIR) \ + -I$(HOME)/include -I/usr/local/include @MYDEFS@ \ + -D_XOPEN_SOURCE_EXTENDED=1 -D_GNU_SOURCE=1 -D__EXTENSIONS__=1 -D_HPUX_SOURCE=1 \ + -D_POSIX_MAPPED_FILES=1 -D_POSIX_SYNCHRONIZED_IO=1 \ + -DPIC=1 -D_THREAD_SAFE=1 -D_REENTRANT=1 -DNDEBUG +CFLAGS = @CFLAGS@ -Wall -pedantic -fPIC -fsigned-char -O0 -fforce-addr @MYOPTS@ +LD = @LD@ +LIBS = -lqdbm @LIBS@ +LIBLDFLAGS = @LDFLAGS@ -L. -L$(MYLIBDIR) -L$(HOME)/lib -L/usr/local/lib @LIBS@ +LDFLAGS = @LDFLAGS@ -L. -L$(MYLIBDIR) -L$(HOME)/lib -L/usr/local/lib $(LIBS) +LDENV = LD_RUN_PATH=/lib:/usr/lib:$(MYLIBDIR):$(HOME)/lib:/usr/local/lib +AR = @AR@ +ARFLAGS = rcsv +RUNENV = LD_LIBRARY_PATH=.:/lib:/usr/lib:$(MYLIBDIR):$(HOME)/lib:/usr/local/lib + + + +#================================================================ +# Suffix rules +#================================================================ + + +.SUFFIXES : +.SUFFIXES : .c .o + +.c.o : + $(CC) -c $(CPPFLAGS) $(CFLAGS) $< + + + +#================================================================ +# Actions +#================================================================ + + +targets : @TARGETS@ + + +all : $(MYLIBS) $(MYBINS) + @printf '\n' + @printf '#================================================================\n' + @printf '# Ready to install.\n' + @printf '#================================================================\n' + + +static : + make MYLIBS="$(MYLIBS)" LDFLAGS="-static $(LDFLAGS)" all + + +debug : + make MYLIBS="$(MYLIBS)" CPPFLAGS="$(CPPFLAGS) -UNDEBUG" \ + CFLAGS="-Wall -ansi -pedantic -fPIC -fsigned-char -O2 -g" \ + LDFLAGS="-static $(LDFLAGS)" all + + +devel : + make MYLIBS="$(MYLIBS)" CPPFLAGS="$(CPPFLAGS) -UNDEBUG" \ + CFLAGS="-Wall -ansi -pedantic -fPIC -fsigned-char -O2 -g -pipe" all + sync ; sync + + +stable : + make MYLIBS="$(MYLIBS)" CFLAGS="-Wall -ansi -pedantic -fPIC -fsigned-char -O2" all + + +profile : + make MYLIBS="$(MYLIBS)" \ + CFLAGS="-Wall -pedantic -fPIC -fsigned-char -O3 -pg -g -Werror" \ + LDFLAGS="-static $(LDFLAGS)" all + + +unsigned : + make MYLIBS="$(MYLIBS)" CPPFLAGS="$(CPPFLAGS) -UNDEBUG" \ + CFLAGS="-Wall -ansi -pedantic -fPIC -funsigned-char -g -O2" all + + +m64 : + make MYLIBS="$(MYLIBS)" CPPFLAGS="$(CPPFLAGS) -UNDEBUG" \ + CFLAGS="-Wall -ansi -pedantic -fPIC -fsigned-char -O2 -m64 -g" all + + +pen4 : + stdopt="-O3 -fomit-frame-pointer -minline-all-stringops" ; \ + exopt="-march=pentium4 -minline-all-stringops -fprefetch-loop-arrays" ; \ + make MYLIBS="$(MYLIBS)" \ + CFLAGS="-Wall -pedantic -fPIC -fsigned-char $$stdopt $$exopt" all + + +k8 : + stdopt="-O3 -fomit-frame-pointer -minline-all-stringops" ; \ + exopt="-march=k8 -minline-all-stringops -fprefetch-loop-arrays" ; \ + make MYLIBS="$(MYLIBS)" \ + CFLAGS="-Wall -pedantic -fPIC -fsigned-char $$stdopt $$exopt" all + + +clean : + rm -rf $(MYLIBS) $(MYBINS) *.o *.a *.so *.lo *.la a.out .libs \ + *.exe *.dll.a *.dll *.dylib *.sl TAGS srcdoc gmon.out leak.log \ + casket casket.* casket-* *~ + + +version : + vernum=`expr $(LIBVER)00 + $(LIBREV)` ; \ + sed -e 's/_QDBM_VERSION.*/_QDBM_VERSION "$(VERSION)"/' \ + -e "s/_QDBM_LIBVER.*/_QDBM_LIBVER $$vernum/" depot.h > depot.h~ + [ -f depot.h~ ] && mv -f depot.h~ depot.h + + +install : + mkdir -p $(DESTDIR)$(MYHEADDIR) + cd $(srcdir) && cp -Rf $(MYHEADS) $(DESTDIR)$(MYHEADDIR) + mkdir -p $(DESTDIR)$(MYLIBDIR) + cp -Rf $(MYLIBS) $(DESTDIR)$(MYLIBDIR) + mkdir -p $(DESTDIR)$(MYBINDIR) + cp -Rf $(MYBINS) $(DESTDIR)$(MYBINDIR) + mkdir -p $(DESTDIR)$(MYMAN1DIR) + cd $(srcdir)/man && cp -Rf $(MYMAN1S) $(DESTDIR)$(MYMAN1DIR) + mkdir -p $(DESTDIR)$(MYMAN3DIR) + cd $(srcdir)/man && cp -Rf $(MYMAN3S) $(DESTDIR)$(MYMAN3DIR) + mkdir -p $(DESTDIR)$(MYDATADIR) + cd $(srcdir) && cp -Rf $(MYDOCS) $(DESTDIR)$(MYDATADIR) + mkdir -p $(DESTDIR)$(MYPCDIR) + cd $(srcdir) && cp -Rf $(MYPCS) $(DESTDIR)$(MYPCDIR) + @printf '\n' + @printf '#================================================================\n' + @printf '# Thanks for using QDBM.\n' + @printf '#================================================================\n' + + +install-strip : + make DESTDIR=$(DESTDIR) install + cd $(DESTDIR)$(MYBINDIR) && strip $(MYBINS) + + +uninstall : + cd $(DESTDIR)$(MYHEADDIR) && rm -f $(MYHEADS) + cd $(DESTDIR)$(MYLIBDIR) && rm -f $(MYLIBS) + cd $(DESTDIR)$(MYBINDIR) && rm -f $(MYBINS) + cd $(DESTDIR)$(MYMAN1DIR) && rm -f $(MYMAN1S) + cd $(DESTDIR)$(MYMAN3DIR) && rm -f $(MYMAN3S) + rm -rf $(DESTDIR)$(MYDATADIR) + cd $(DESTDIR)$(MYPCDIR) && rm -f $(MYPCS) + + +dist : + sync ; sync + for dir in $(SUBDIRS) ; \ + do \ + if [ -d $$dir ] ; \ + then \ + echo Making $@ in $$dir ; \ + ( cd $$dir && if [ -f configure.in ] ; then autoconf ; ./configure ; \ + make dist ; fi ) ; \ + fi ; \ + done + make version + make distclean + cd .. && tar cvf - $(PACKAGEDIR) | gzip -c > $(PACKAGETGZ) + sync ; sync + + +distclean : clean + for dir in $(SUBDIRS) ; \ + do \ + if [ -d $$dir ] ; \ + then \ + echo Making $@ in $$dir ; \ + ( cd $$dir && if [ -f Makefile ] ; then make distclean ; fi ) ; \ + fi ; \ + done + rm -rf Makefile LTmakefile qdbm.spec qdbm.pc config.cache config.log config.status \ + autom4te.cache rpm-tmp *-win32 + + +TAGS : + etags -o $@ *.c *.h + + +sdoc : + rm -rf srcdoc + ./lab/ccdoc -d srcdoc -t "Source Documents of QDBM" *.h *.c + + +check : + sync ; sync + rm -rf casket* + $(RUNENV) $(RUNCMD) ./dptest write -s casket 500 500000 + $(RUNENV) $(RUNCMD) ./dptest write casket 50000 5000 + $(RUNENV) $(RUNCMD) ./dptest read casket + $(RUNENV) $(RUNCMD) ./dptest read -wb casket + $(RUNENV) $(RUNCMD) ./dptest rcat -c casket 50000 50 500 32 8 + $(RUNENV) $(RUNCMD) ./dptest combo casket + $(RUNENV) $(RUNCMD) ./dptest wicked -c casket 5000 + $(RUNENV) $(RUNCMD) ./dptest wicked casket 500 + $(RUNENV) $(RUNCMD) ./dpmgr repair casket + $(RUNENV) $(RUNCMD) ./dpmgr optimize casket + $(RUNENV) $(RUNCMD) ./dpmgr list casket + rm -rf casket* + $(RUNENV) $(RUNCMD) ./crtest write -s casket 500 100000 5 + $(RUNENV) $(RUNCMD) ./crtest write casket 50000 500 10 + $(RUNENV) $(RUNCMD) ./crtest read casket + $(RUNENV) $(RUNCMD) ./crtest read -wb casket + $(RUNENV) $(RUNCMD) ./crtest rcat -c casket 50000 5 10 500 32 8 + $(RUNENV) $(RUNCMD) ./crtest combo casket + $(RUNENV) $(RUNCMD) ./crtest wicked -c casket 5000 + $(RUNENV) $(RUNCMD) ./crtest wicked casket 500 + $(RUNENV) $(RUNCMD) ./crmgr repair casket + $(RUNENV) $(RUNCMD) ./crmgr optimize casket + $(RUNENV) $(RUNCMD) ./crmgr list casket + rm -rf casket* + $(RUNENV) $(RUNCMD) ./crtest write -lob casket 1000 50 10 + $(RUNENV) $(RUNCMD) ./crtest read -lob casket + rm -rf casket* + $(RUNENV) $(RUNCMD) ./rltest write casket 5000 + $(RUNENV) $(RUNCMD) ./rltest read casket 5000 + $(RUNENV) $(RUNCMD) ./rlmgr list casket + rm -rf casket* + $(RUNENV) $(RUNCMD) ./hvtest write casket 5000 + $(RUNENV) $(RUNCMD) ./hvtest read casket 5000 + $(RUNENV) $(RUNCMD) ./hvmgr optimize casket + $(RUNENV) $(RUNCMD) ./hvmgr list casket + rm -rf casket* + $(RUNENV) $(RUNCMD) ./hvtest write -qdbm -s casket 500 + $(RUNENV) $(RUNCMD) ./hvtest write -qdbm casket 5000 + $(RUNENV) $(RUNCMD) ./hvtest read -qdbm casket 5000 + rm -rf casket* + $(RUNENV) $(RUNCMD) ./cbtest sort 5000 + $(RUNENV) $(RUNCMD) ./cbtest strstr 500 + $(RUNENV) $(RUNCMD) ./cbtest list 50000 + $(RUNENV) $(RUNCMD) ./cbtest list -d 500 + $(RUNENV) $(RUNCMD) ./cbtest map 50000 500 + $(RUNENV) $(RUNCMD) ./cbtest map -d 500 5 + $(RUNENV) $(RUNCMD) ./cbtest heap 50000 500 + $(RUNENV) $(RUNCMD) ./cbtest heap -d 500 50 + $(RUNENV) $(RUNCMD) ./cbtest wicked 5000 + $(RUNENV) $(RUNCMD) ./cbtest misc + rm -rf casket* + $(RUNENV) $(RUNCMD) ./vltest write -tune 32 31 32 32 casket 50000 + $(RUNENV) $(RUNCMD) ./vltest read casket + $(RUNENV) $(RUNCMD) ./vltest rdup -tune 32 31 512 256 casket 50000 50000 + $(RUNENV) $(RUNCMD) ./vltest combo casket + $(RUNENV) $(RUNCMD) ./vltest wicked -c casket 5000 + $(RUNENV) $(RUNCMD) ./vltest wicked casket 500 + $(RUNENV) $(RUNCMD) ./vlmgr repair casket + $(RUNENV) $(RUNCMD) ./vlmgr optimize casket + $(RUNENV) $(RUNCMD) ./vlmgr list casket + rm -rf casket* + $(RUNENV) $(RUNCMD) ./vltest write -int -cz -tune 32 31 32 32 casket 50000 + $(RUNENV) $(RUNCMD) ./vltest read -int -vc casket + $(RUNENV) $(RUNCMD) ./vltest rdup -int -cz -cc -tune 32 31 512 256 casket 50000 50000 + $(RUNENV) $(RUNCMD) ./vltest combo -cz casket + $(RUNENV) $(RUNCMD) ./vltest wicked -cz -c casket 5000 + $(RUNENV) $(RUNCMD) ./vltest combo -cy casket + $(RUNENV) $(RUNCMD) ./vltest wicked -cy -c casket 5000 + $(RUNENV) $(RUNCMD) ./vltest combo -cx casket + $(RUNENV) $(RUNCMD) ./vltest wicked -cx -c casket 5000 + rm -rf casket* + $(RUNENV) $(RUNCMD) ./odtest write casket 500 50 5000 + $(RUNENV) $(RUNCMD) ./odtest read casket + $(RUNENV) $(RUNCMD) ./odtest combo casket + $(RUNENV) $(RUNCMD) ./odtest wicked casket 500 + rm -rf casket* + $(RUNENV) $(RUNCMD) ./qmttest casket 50000 10 + rm -rf casket* + @printf '\n' + @printf '#================================================================\n' + @printf '# Checking completed.\n' + @printf '#================================================================\n' + + +check-valgrind : + make RUNCMD="valgrind --tool=memcheck --log-fd=1" check | tee leak.log + grep ERROR leak.log + grep 'at exit' leak.log + + +world : + make clean ; make + cd plus ; [ -f Makefile ] || ./configure ; make clean ; make + cd java ; [ -f Makefile ] || ./configure ; make clean ; make + cd perl ; [ -f Makefile ] || ./configure ; make clean ; make + cd ruby ; [ -f Makefile ] || ./configure ; make clean ; make + cd cgi ; [ -f Makefile ] || ./configure ; make clean ; make + + +install-world : + make install + cd plus ; [ -f Makefile ] || ./configure ; make install + cd java ; [ -f Makefile ] || ./configure ; make install + cd perl ; [ -f Makefile ] || ./configure ; make install + cd ruby ; [ -f Makefile ] || ./configure ; make install + cd cgi ; [ -f Makefile ] || ./configure ; make install + + +uninstall-world : + make uninstall + cd plus ; [ -f Makefile ] || ./configure ; make uninstall + cd java ; [ -f Makefile ] || ./configure ; make uninstall + cd perl ; [ -f Makefile ] || ./configure ; make uninstall + cd ruby ; [ -f Makefile ] || ./configure ; make uninstall + cd cgi ; [ -f Makefile ] || ./configure ; make uninstall + + +check-world : + make check + cd plus ; [ -f Makefile ] || ./configure ; make check + cd java ; [ -f Makefile ] || ./configure ; make check + cd perl ; [ -f Makefile ] || ./configure ; make check + cd ruby ; [ -f Makefile ] || ./configure ; make check + + +rpm : ../$(PACKAGETGZ) qdbm.spec + mkdir -p rpm-tmp/{BUILD,RPMS,SOURCES,SPECS,SRPMS} + mkdir -p rpm-tmp/RPMS/i386 + cp ../$(PACKAGETGZ) rpm-tmp/SOURCES + rpmbuild -bb --target i386 --define "_topdir `pwd`/rpm-tmp" qdbm.spec + mv -f rpm-tmp/RPMS/i386/$(PACKAGE)-*$(VERSION)*.rpm .. + rm -rf rpm-tmp + + +win32pkg : + test -f /bin/mgwz.dll + test -f /bin/libiconv-2.dll + make uninstall && make uninstall-win && make clean + make mingw && strip *.exe && make install-win + cd java && ./configure + cd java && make uninstall && make uninstall-win && make clean + cd java && make mingw + cd cgi && ./configure + cd cgi && make clean + cd cgi && make mingw && strip *.cgi + mkdir -p $(PACKAGE)-$(VERSION)-win32 + cp -Rf $(MYHEADS) libqdbm.dll.a qdbm.dll *.exe *.html \ + misc/README-win32.txt misc/COPYING.txt misc/win32check.bat \ + /bin/mgwz.dll /bin/libiconv-2.dll \ + $(PACKAGE)-$(VERSION)-win32 + cp -Rf java/jqdbm.dll java/qdbm.jar java/*.html java/japidoc $(PACKAGE)-$(VERSION)-win32 + mkdir -p $(PACKAGE)-$(VERSION)-win32/cgi + cp -Rf cgi/*.cgi cgi/*.conf cgi/*.html $(PACKAGE)-$(VERSION)-win32/cgi + zip -r $(PACKAGE)-$(VERSION)-win32.zip $(PACKAGE)-$(VERSION)-win32 + mv -f $(PACKAGE)-$(VERSION)-win32.zip .. + rm -rf $(PACKAGE)-$(VERSION)-win32 + make uninstall && make uninstall-win && make clean + cd java ; make uninstall && make uninstall-win && make clean + + +win : + make MYLIBS="$(MYWINLIBS)" CFLAGS="-Wall -ansi -pedantic -fsigned-char -O2" + + +mingw : + make CC="gcc -mno-cygwin" MYLIBS="$(MYWINLIBS)" \ + CFLAGS="-Wall -fsigned-char -O2" LIBLDFLAGS="@MGWLIBS@" LDFLAGS="-L. -lqdbm @MGWLIBS@" + + +check-win : + make check + + +install-win : + make MYBINS="`for file in $(MYBINS) ; do echo $$file.exe ; done | tr '\n' ' '`" \ + MYLIBS="$(MYWINLIBS)" install + cp -Rf qdbm.dll $(DESTDIR)$(MYBINDIR) + + +uninstall-win : + make MYBINS="`for file in $(MYBINS) ; do echo $$file.exe ; done | tr '\n' ' '`" \ + MYLIBS="$(MYWINLIBS)" uninstall + rm -f $(DESTDIR)$(MYBINDIR)/qdbm.dll + + +def : libqdbm.a + ./misc/makevcdef libqdbm.a > qdbm.def + + +mac : + make MYLIBS="$(MYMACLIBS)" CFLAGS="-Wall -fsigned-char -fno-common -O2" + + +check-mac : + make RUNENV="DYLD_LIBRARY_PATH=." check + + +install-mac : + make MYLIBS="$(MYMACLIBS)" install + + +uninstall-mac : + make MYLIBS="$(MYMACLIBS)" uninstall + + +hpux : + make MYLIBS="$(MYHPUXLIBS)" + + +check-hpux : + make RUNENV="SHLIB_PATH=." check + + +install-hpux : + make MYLIBS="$(MYHPUXLIBS)" install + + +uninstall-hpux : + make MYLIBS="$(MYHPUXLIBS)" uninstall + + +no-so : + make MYLIBS="libqdbm.a" all + + +install-no-so : + make MYLIBS="libqdbm.a" install + + +uninstall-no-so : + make MYLIBS="libqdbm.a" uninstall + + +.PHONY : all clean install check + + + +#================================================================ +# Building binaries +#================================================================ + + +libqdbm.a : $(MYLIBOBJS) + $(AR) $(ARFLAGS) $@ $(MYLIBOBJS) + + +libqdbm.so.$(LIBVER).$(LIBREV).0 : $(MYLIBOBJS) + if uname -a | egrep -i 'SunOS' > /dev/null ; \ + then \ + $(CC) -shared -Wl,-G,-h,libqdbm.so.$(LIBVER) -o $@ $(MYLIBOBJS) $(LIBLDFLAGS) ; \ + else \ + $(CC) -shared -Wl,-soname,libqdbm.so.$(LIBVER) -o $@ $(MYLIBOBJS) $(LIBLDFLAGS) ; \ + fi + + +libqdbm.so.$(LIBVER) : libqdbm.so.$(LIBVER).$(LIBREV).0 + ln -f -s libqdbm.so.$(LIBVER).$(LIBREV).0 $@ + + +libqdbm.so : libqdbm.so.$(LIBVER).$(LIBREV).0 + ln -f -s libqdbm.so.$(LIBVER).$(LIBREV).0 $@ + + +libqdbm.dll.a : qdbm.dll + + +qdbm.dll : $(MYLIBOBJS) + $(CC) -shared -o $@ \ + -Wl,--out-implib=lib$@.a \ + -Wl,--export-all-symbols \ + -Wl,--enable-auto-import \ + -Wl,--add-stdcall-alias \ + -Wl,--whole-archive \ + -Wl,--no-whole-archive $(MYLIBOBJS) $(LIBLDFLAGS) + + +libqdbm.$(LIBVER).$(LIBREV).0.dylib : $(MYLIBOBJS) + $(CC) -dynamiclib -o $@ \ + -install_name $(MYLIBDIR)/libqdbm.$(LIBVER).dylib \ + -current_version $(LIBVER).$(LIBREV).0 \ + -compatibility_version $(LIBVER) \ + $(MYLIBOBJS) $(LIBLDFLAGS) + + +libqdbm.$(LIBVER).dylib : libqdbm.$(LIBVER).$(LIBREV).0.dylib + ln -f -s libqdbm.$(LIBVER).$(LIBREV).0.dylib $@ + + +libqdbm.dylib : libqdbm.$(LIBVER).$(LIBREV).0.dylib + ln -f -s libqdbm.$(LIBVER).$(LIBREV).0.dylib $@ + + +libqdbm.sl : $(MYLIBOBJS) + $(CC) -shared -Wl,-b -o $@ $(MYLIBOBJS) $(LIBLDFLAGS) + + +dpmgr : dpmgr.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ dpmgr.o $(LDFLAGS) + + +dptest : dptest.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ dptest.o $(LDFLAGS) + + +dptsv : dptsv.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ dptsv.o $(LDFLAGS) + + +crmgr : crmgr.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ crmgr.o $(LDFLAGS) + + +crtest : crtest.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ crtest.o $(LDFLAGS) + + +crtsv : crtsv.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ crtsv.o $(LDFLAGS) + + +rlmgr : rlmgr.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ rlmgr.o $(LDFLAGS) + + +rltest : rltest.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ rltest.o $(LDFLAGS) + + +hvmgr : hvmgr.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ hvmgr.o $(LDFLAGS) + + +hvtest : hvtest.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ hvtest.o $(LDFLAGS) + + +cbtest : cbtest.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ cbtest.o $(LDFLAGS) + + +cbcodec : cbcodec.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ cbcodec.o $(LDFLAGS) + + +vlmgr : vlmgr.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ vlmgr.o $(LDFLAGS) + + +vltest : vltest.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ vltest.o $(LDFLAGS) + + +vltsv : vltsv.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ vltsv.o $(LDFLAGS) + + +odmgr : odmgr.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ odmgr.o $(LDFLAGS) + + +odtest : odtest.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ odtest.o $(LDFLAGS) + + +odidx : odidx.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ odidx.o $(LDFLAGS) + + +qmttest : qmttest.o $(MYLIBS) + $(LDENV) $(CC) $(CFLAGS) -o $@ qmttest.o $(LDFLAGS) + + +depot.o : depot.h myconf.h + +curia.o : depot.h curia.h myconf.h + +relic.o : depot.h relic.h myconf.h + +hovel.o : depot.h curia.h hovel.h myconf.h + +cabin.o : cabin.h myconf.h + +villa.o : depot.h cabin.h villa.h myconf.h + +vista.o : depot.h curia.h cabin.h villa.h vista.h myconf.h villa.c + +odeum.o : depot.h curia.h cabin.h villa.h myconf.h + +myconf.o : myconf.h + +dpmgr.o dptest.o dptsv.o : depot.h cabin.h + +crmgr.o crtest.o crtsv.o : depot.h curia.h cabin.h + +rlmgr.o rltest.o : depot.h relic.h cabin.h + +hvmgr.o hvtest.o : depot.h curia.h hovel.h cabin.h + +cbtest.o cbcodec.o : cabin.h + +vlmgr.o vltest.o vltsv.o : depot.h cabin.h villa.h + +odmgr.o odtest.o odidx.o : depot.h curia.h cabin.h villa.h odeum.h + + + +# END OF FILE diff --git a/qdbm/NEWS b/qdbm/NEWS new file mode 100644 index 00000000..52a27359 --- /dev/null +++ b/qdbm/NEWS @@ -0,0 +1,43 @@ +== Thu, 08 Sep 2005 13:13:58 +0900 == + +Compressing options of ZLIB was changed. If you use villa with the option +`VL_OZCOMP', databases of the earlier versions are not compatible with the +current version of QDBM. To convert the old database to new format, +export endian independent data by "vlmgr exportdb" with the old version, +and then import it by "vlmgr importdb" with the latest version. + + + +== Wed, 10 Mar 2004 23:24:24 +0900 == + +API of B+ tree was changed a bit. Even if you build QDBM with ZLIB +enabled, records are not compressed. Instead of it, the function `vlopen' +has the option `VL_OZCOMP'. If it is specified, records are compressed. +So, you can switch whether to compress records or not, on runtime. + +Users who have used ZLIB feature should modify their source codes to +specify that option. + + + +== Wed, 10 Dec 2003 09:24:12 +0900 == + +The database format was changed with QDBM 1.7.13. Newer versions do not +have backward compatibility to old format. You can convert old databases +with the command `fmtcnv031127' in the sub directory `lab'. To build it, +perform the following steps. + + cd lab + make fmtcnv031127 + +About usage of it, see the file `README' in `lab'. Typically, to convert +a Depot database named as `old' and create a database named as `new', +perform the following step. + + ./fmtcnv031127 < old > new + +I'm sorry for bothering you. + + + +== END OF FILE == diff --git a/qdbm/README b/qdbm/README new file mode 100644 index 00000000..d7adad4b --- /dev/null +++ b/qdbm/README @@ -0,0 +1,50 @@ +================================================================ + QDBM: Quick Database Manager + Copyright (C) 2000-2007 Mikio Hirabayashi +================================================================ + + +Please read the following documents with a WWW browser. +How to install QDBM is explained in the specification. + + README - this file + COPYING - license + ChangeLog - history of enhancement + NEWS - news for users + THANKS - list of contributors + spex.html - specification + spex-ja.html - specification in Japanese + + +Contents of the directory tree is below. + + ./ - sources of QDBM + ./plus/ - API for C++ (read `./plus/xspex.html') + ./java/ - API for Java (read `./java/jspex.html') + ./perl/ - API for Perl (read `./perl/plspex.html') + ./ruby/ - API for Ruby (read `./ruby/rbspex.html') + ./cgi/ - CGI scripts (read `./cgi/cgispex.html') + ./man1/ - manual pages for commands + ./man3/ - manual pages for C API + ./lab/ - for test and experiment + ./bros/ - for comparison with other database managers + ./misc/ - miscellaneous files + + +QDBM is released under the terms of the GNU Lesser General Public +License. See the file `COPYING' for details. + +QDBM was written by Mikio Hirabayashi. You can contact the author +by e-mail to `mikio@users.sourceforge.net'. However, as for +topics which can be shared among other users, pleae send it to +the mailing list. To join the mailing list, refer to the following +URL. + + http://lists.sourceforge.net/lists/listinfo/qdbm-users + + +Thanks. + + + +== END OF FILE == diff --git a/qdbm/RISCmakefile b/qdbm/RISCmakefile new file mode 100644 index 00000000..2cebbb3f --- /dev/null +++ b/qdbm/RISCmakefile @@ -0,0 +1,140 @@ +# Makefile for the RISC OS version of QDBM + + +# Define which compiler to use: + +CC = cc +#CC = gcc + + +######################################### +# DO NOT EDIT ANYTHING BELOW THIS LINE! # +######################################### + +ifeq (${CC},cc) +CC = cc +LD = link +AR = libfile +DEPEND = -depend !Depend +CC_FLAGS = -Wdp -throwback -Otime -I@,Unix: -JUnix +UNIXLIB = Unix:o.UnixLib +else +ifeq (${CC},gcc) +CC = gcc +LD = gcc +AR = ar +CC_FLAGS = -mthrowback -O3 -I. +else +# No other compiler supported! +endif +endif + +QDBM_OBJS = o.depot o.curia o.relic o.hovel o.cabin o.villa o.vista o.odeum o.myconf + +.INIT : + @cdir o + +## Rule Patterns ## + +.SUFFIXES : .c .o + +.c.o : + $(CC) $(CC_FLAGS) $(DEPEND) -c -o $@ $< + +# Static dependencies: + +all : libqdbm testcases managers converters + +libqdbm : $(QDBM_OBJS) + $(AR) $(AR_FLAGS) -c -o libqdbm $(QDBM_OBJS) + +testcases : dptest crtest rltest hvtest cbtest vltest odtest + create testcases + +managers : dpmgr crmgr rlmgr hvmgr vlmgr odmgr + create managers + +converters : dptsv crtsv cbcodec vltsv odidx + create converters + +dptest : o.dptest libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +crtest : o.crtest libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +rltest : o.rltest libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +hvtest : o.hvtest libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +cbtest : o.cbtest libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +vltest : o.vltest libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +odtest : o.odtest libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +dpmgr : o.dpmgr libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +crmgr : o.crmgr libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +rlmgr : o.rlmgr libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +hvmgr : o.hvmgr libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +vlmgr : o.vlmgr libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +odmgr : o.odmgr libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +dptsv : o.dptsv libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +crtsv : o.crtsv libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +cbcodec : o.cbcodec libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +vltsv : o.vltsv libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +odidx : o.odidx libqdbm + $(LD) $(LD_FLAGS) -o $@ o.$* libqdbm $(UNIXLIB) + +clean: + -ifthere libqdbm then wipe libqdbm ~CFR~V + -ifthere dptest then wipe dptest ~CFR~V + -ifthere crtest then wipe crtest ~CFR~V + -ifthere rltest then wipe rltest ~CFR~V + -ifthere hvtest then wipe hvtest ~CFR~V + -ifthere cbtest then wipe cbtest ~CFR~V + -ifthere vltest then wipe vltest ~CFR~V + -ifthere odtest then wipe odtest ~CFR~V + -ifthere dpmgr then wipe dpmgr ~CFR~V + -ifthere crmgr then wipe crmgr ~CFR~V + -ifthere rlmgr then wipe rlmgr ~CFR~V + -ifthere hvmgr then wipe hvmgr ~CFR~V + -ifthere cbmgr then wipe cbmgr ~CFR~V + -ifthere vlmgr then wipe vlmgr ~CFR~V + -ifthere odmgr then wipe odmgr ~CFR~V + -ifthere dptsv then wipe dptsv ~CFR~V + -ifthere crtsv then wipe crtsv ~CFR~V + -ifthere cbcodec then wipe cbcodec ~CFR~V + -ifthere vltsv then wipe vltsv ~CFR~V + -ifthere odidx then wipe odidx ~CFR~V + -ifthere testcases then wipe testcases ~CFR~V + -ifthere managers then wipe managers ~CFR~V + -ifthere converters then wipe converters ~CFR~V + -ifthere o.* then wipe o.* ~CFR~V + +# Dynamic dependencies: diff --git a/qdbm/THANKS b/qdbm/THANKS new file mode 100644 index 00000000..dc7a0dc6 --- /dev/null +++ b/qdbm/THANKS @@ -0,0 +1,45 @@ +================================================================ + Thanks to all of the following for their valuable suggestions + or contributions. +================================================================ + + +Kang-Jin Lee + - suggestions about the GDBM-compatible API + - contributions about Makefile + +Pat Podenski + - suggestions about porting to Mac OS X, Solaris, and HP-UX + +BERO + - contributions about supporting MinGW + +Stefan Bellon + - contributions about porting to RISC OS + +Donald Gobin + - contributions about supporting Visual C++ + +Emanuel Dejanu + - contributions about supporting Visual C++ + +Keith Bostic + - suggestions about the performance test suite + +William Lachance + - contributions about RPM spec file + +Zed A. Shaw + - contributions about a text analyzer in Odeum + - contributions about a query language in Odeum + +Chris Bilderback + - contributions about cursor functions in Villa. + +Fumitoshi Ukai + - contributions of troff manuals + - making Debian packages + + + +== END OF FILE == diff --git a/qdbm/VCmakefile b/qdbm/VCmakefile new file mode 100644 index 00000000..210a98ff --- /dev/null +++ b/qdbm/VCmakefile @@ -0,0 +1,248 @@ +# Makefile to build QDBM using Microsoft Visual C++ + + + +#================================================================ +# Setting variables +#================================================================ + + +# VC++ directory +VCPATH = C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 + +# User options +YOUR_CLFLAGS = +YOUR_LIBFLAGS = +YOUR_LINKFLAGS= + +# Configurations +!IF "$(CFG)" == "ld" +!MESSAGE Build using static debug configuration +BASE_FLAGS = /MLd /W3 /ZI /Od /FD /GZ /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" +BASE_DEFS = /D_DEBUG /D__DEBUG__ +OUTDIR = .\tmp_ld +LIB_APPEND = _ld +EXE_APPEND = _ld +!ELSEIF "$(CFG)" == "l" +!MESSAGE Build using static release configuration +BASE_DEFS = /DNDEBUG +BASE_FLAGS = /ML /W3 /O2 /FD /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" +OUTDIR = .\tmp_l +LIB_APPEND = _l +EXE_APPEND = _l +!ELSEIF "$(CFG)" == "td" +!MESSAGE Build using static threaded debug configuration +BASE_FLAGS = /MTd /W3 /ZI /Od /FD /GZ /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" +BASE_DEFS = /D_DEBUG /D__DEBUG__ +OUTDIR = .\tmp_td +LIB_APPEND = _td +EXE_APPEND = _td +!ELSEIF "$(CFG)" == "t" +!MESSAGE Build using static threaded release configuration +BASE_DEFS = /DNDEBUG +BASE_FLAGS = /MT /W3 /O2 /FD /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" +OUTDIR = .\tmp_t +LIB_APPEND = _t +EXE_APPEND = _t +!ELSEIF "$(CFG)" == "dd" +!MESSAGE Build using dynamic threaded debug configuration +BASE_FLAGS = /MDd /W3 /ZI /Od /FD /GZ /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" +BASE_DEFS = /D_DEBUG /D__DEBUG__ +OUTDIR = .\tmp_dd +LIB_APPEND = _dd +EXE_APPEND = _dd +!ELSE +!MESSAGE Build using dynamic threaded release configuration +BASE_DEFS = /DNDEBUG +BASE_FLAGS = /MD /W3 /O2 /FD /Fo"$(OUTDIR)\\" /Fd"$(OUTDIR)\\" +OUTDIR = .\tmp +LIB_APPEND = +EXE_APPEND = +!ENDIF + +# Building binaries +CLFLAGS = /I "$(VCPATH)\Include" /I "$(VCPATH)\PlatformSDK\Include" /I "." \ + /nologo $(YOUR_CLFLAGS) $(BASE_FLAGS) $(BASE_DEFS) /D_CRT_SECURE_NO_DEPRECATE=1 +LIBFLAGS = /libpath:"$(VCPATH)\lib" /libpath:"$(VCPATH)\PlatformSDK\Lib" /libpath:"." \ + /nologo $(YOUR_LIBFLAGS) +LINKFLAGS = /libpath:"$(VCPATH)\lib" /libpath:"$(VCPATH)\PlatformSDK\Lib" /libpath:"." \ + /nologo $(YOUR_LINKFLAGS) + +# Targets +MYLIBS = qdbm$(LIB_APPEND).dll qdbm$(LIB_APPEND).lib qdbm$(LIB_APPEND)_static.lib +LIBOBJS = $(OUTDIR)\depot.obj $(OUTDIR)\curia.obj $(OUTDIR)\relic.obj \ + $(OUTDIR)\hovel.obj $(OUTDIR)\cabin.obj $(OUTDIR)\villa.obj \ + $(OUTDIR)\vista.obj $(OUTDIR)\odeum.obj $(OUTDIR)\myconf.obj +MYBINS = dpmgr$(EXE_APPEND).exe dptest$(EXE_APPEND).exe dptsv$(EXE_APPEND).exe \ + crmgr$(EXE_APPEND).exe crtest$(EXE_APPEND).exe crtsv$(EXE_APPEND).exe \ + rlmgr$(EXE_APPEND).exe rltest$(EXE_APPEND).exe hvmgr$(EXE_APPEND).exe \ + hvtest$(EXE_APPEND).exe cbtest$(EXE_APPEND).exe cbcodec$(EXE_APPEND).exe \ + vlmgr$(EXE_APPEND).exe vltest$(EXE_APPEND).exe vltsv$(EXE_APPEND).exe \ + odmgr$(EXE_APPEND).exe odtest$(EXE_APPEND).exe odidx$(EXE_APPEND).exe + + + +#================================================================ +# Suffix rules +#================================================================ + + +.SUFFIXES : +.SUFFIXES : .c .obj + +.c{$(OUTDIR)}.obj : + cl /c $(CLFLAGS) $< + +.c.obj: + cl /c $(CLFLAGS) $< + + + +#================================================================ +# Actions +#================================================================ + + +all : $(OUTDIR) $(MYLIBS) $(MYBINS) + + +allcfg: + nmake /NOLOGO /f VCmakefile CFG=ld + nmake /NOLOGO /f VCmakefile CFG=l + nmake /NOLOGO /f VCmakefile CFG=td + nmake /NOLOGO /f VCmakefile CFG=t + nmake /NOLOGO /f VCmakefile CFG=dd + nmake /NOLOGO /f VCmakefile + + +clean : + -rd tmp_ld /S /Q > NUL: 2>&1 + -rd tmp_l /S /Q > NUL: 2>&1 + -rd tmp_td /S /Q > NUL: 2>&1 + -rd tmp_t /S /Q > NUL: 2>&1 + -rd tmp_dd /S /Q > NUL: 2>&1 + -rd tmp /S /Q > NUL: 2>&1 + -del *.obj *.lib *.dll *.exp *.exe casket /F /Q > NUL: 2>&1 + + +"$(OUTDIR)" : + if not exist "$(OUTDIR)/" mkdir "$(OUTDIR)" + + + +#================================================================ +# Building binaries +#================================================================ + + +qdbm$(LIB_APPEND).dll : $(LIBOBJS) qdbm.def + link /DLL /DEF:qdbm.def $(LINKFLAGS) /OUT:$@ /IMPLIB:qdbm$(LIB_APPEND).lib $(LIBOBJS) + + +qdbm$(LIB_APPEND).lib : qdbm$(LIB_APPEND).dll + + +qdbm$(LIB_APPEND)_static.lib : $(LIBOBJS) + lib $(LIBFLAGS) /OUT:$@ $(LIBOBJS) + + +dpmgr$(EXE_APPEND).exe : $(OUTDIR)\dpmgr.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\dpmgr.obj qdbm$(LIB_APPEND).lib + + +dptest$(EXE_APPEND).exe : $(OUTDIR)\dptest.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\dptest.obj qdbm$(LIB_APPEND).lib + + +dptsv$(EXE_APPEND).exe : $(OUTDIR)\dptsv.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\dptsv.obj qdbm$(LIB_APPEND).lib + + +crmgr$(EXE_APPEND).exe : $(OUTDIR)\crmgr.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\crmgr.obj qdbm$(LIB_APPEND).lib + + +crtest$(EXE_APPEND).exe : $(OUTDIR)\crtest.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\crtest.obj qdbm$(LIB_APPEND).lib + + +crtsv$(EXE_APPEND).exe : $(OUTDIR)\crtsv.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\crtsv.obj qdbm$(LIB_APPEND).lib + + +rlmgr$(EXE_APPEND).exe : $(OUTDIR)\rlmgr.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\rlmgr.obj qdbm$(LIB_APPEND).lib + + +rltest$(EXE_APPEND).exe : $(OUTDIR)\rltest.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\rltest.obj qdbm$(LIB_APPEND).lib + + +hvmgr$(EXE_APPEND).exe : $(OUTDIR)\hvmgr.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\hvmgr.obj qdbm$(LIB_APPEND).lib + + +hvtest$(EXE_APPEND).exe : $(OUTDIR)\hvtest.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\hvtest.obj qdbm$(LIB_APPEND).lib + + +cbtest$(EXE_APPEND).exe : $(OUTDIR)\cbtest.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\cbtest.obj qdbm$(LIB_APPEND).lib + + +cbcodec$(EXE_APPEND).exe : $(OUTDIR)\cbcodec.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\cbcodec.obj qdbm$(LIB_APPEND).lib + + +vlmgr$(EXE_APPEND).exe : $(OUTDIR)\vlmgr.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\vlmgr.obj qdbm$(LIB_APPEND).lib + + +vltest$(EXE_APPEND).exe : $(OUTDIR)\vltest.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\vltest.obj qdbm$(LIB_APPEND).lib + + +vltsv$(EXE_APPEND).exe : $(OUTDIR)\vltsv.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\vltsv.obj qdbm$(LIB_APPEND).lib + + +odmgr$(EXE_APPEND).exe : $(OUTDIR)\odmgr.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\odmgr.obj qdbm$(LIB_APPEND).lib + + +odtest$(EXE_APPEND).exe : $(OUTDIR)\odtest.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\odtest.obj qdbm$(LIB_APPEND).lib + + +odidx$(EXE_APPEND).exe : $(OUTDIR)\odidx.obj qdbm$(LIB_APPEND).lib + link $(LINKFLAGS) /OUT:$@ $(OUTDIR)\odidx.obj qdbm$(LIB_APPEND).lib + + +$(OUTDIR)\depot.obj $(OUTDIR)\dpmgr.obj $(OUTDIR)\dptest.obj $(OUTDIR)\dptsv.obj : \ + depot.h myconf.h + +$(OUTDIR)\curia.obj $(OUTDIR)\crmgr.obj $(OUTDIR)\crtest.obj $(OUTDIR)\crtsv.obj : \ + curia.h depot.h myconf.h + +$(OUTDIR)\relic.obj $(OUTDIR)\rlmgr.obj $(OUTDIR)\rltest.obj : \ + relic.h depot.h myconf.h + +$(OUTDIR)\hovel.obj $(OUTDIR)\hvmgr.obj $(OUTDIR)\hvtest.obj : \ + hovel.h depot.h curia.h myconf.h + +$(OUTDIR)\cabin.obj $(OUTDIR)\cbtest.obj $(OUTDIR)\cbcodec.obj : \ + cabin.h myconf.h + +$(OUTDIR)\villa.obj $(OUTDIR)\vlmgr.obj $(OUTDIR)\vltest.obj $(OUTDIR)\vltsv.obj : \ + villa.h depot.h cabin.h myconf.h + +$(OUTDIR)\vista.obj : vista.h villa.h depot.h curia.h cabin.h myconf.h + +$(OUTDIR)\odeum.obj $(OUTDIR)\odmgr.obj $(OUTDIR)\odtest.obj $(OUTDIR)\odidx.obj : \ + odeum.h depot.h curia.h cabin.h villa.h myconf.h + +$(OUTDIR)\myconf.obj : myconf.h + + + +# END OF FILE diff --git a/qdbm/cabin.c b/qdbm/cabin.c new file mode 100644 index 00000000..262cb3eb --- /dev/null +++ b/qdbm/cabin.c @@ -0,0 +1,3529 @@ +/************************************************************************************************* + * Implementation of Cabin + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#define QDBM_INTERNAL 1 + +#include "cabin.h" +#include "myconf.h" + +#define CB_GCUNIT 64 /* allocation unit size of a buffer in gc */ +#define CB_SPBUFSIZ 32 /* size of a buffer for sprintf */ +#define CB_SPMAXWIDTH 128 /* max width of a column for sprintf */ +#define CB_MAPPBNUM 251 /* bucket size of a petit map handle */ +#define CB_MAPCSUNIT 52 /* small allocation unit size of map concatenation */ +#define CB_MAPCBUNIT 252 /* big allocation unit size of map concatenation */ +#define CB_MSGBUFSIZ 256 /* size of a buffer for log message */ +#define CB_IOBUFSIZ 8192 /* size of an I/O buffer */ +#define CB_FILEMODE 00644 /* permission of a creating file */ +#define CB_NUMBUFSIZ 32 /* size of a buffer for a number */ +#define CB_ENCBUFSIZ 32 /* size of a buffer for encoding name */ +#define CB_DATEBUFSIZ 64 /* size of a buffer for date expression */ +#define CB_VNUMBUFSIZ 8 /* size of a buffer for variable length number */ + +/* set a buffer for a variable length number */ +#define CB_SETVNUMBUF(CB_len, CB_buf, CB_num) \ + do { \ + int _CB_num; \ + _CB_num = (CB_num); \ + if(_CB_num == 0){ \ + ((signed char *)(CB_buf))[0] = 0; \ + (CB_len) = 1; \ + } else { \ + (CB_len) = 0; \ + while(_CB_num > 0){ \ + int _CB_rem = _CB_num & 0x7f; \ + _CB_num >>= 7; \ + if(_CB_num > 0){ \ + ((signed char *)(CB_buf))[(CB_len)] = -_CB_rem - 1; \ + } else { \ + ((signed char *)(CB_buf))[(CB_len)] = _CB_rem; \ + } \ + (CB_len)++; \ + } \ + } \ + } while(FALSE) + +/* read a variable length buffer */ +#define CB_READVNUMBUF(CB_buf, CB_size, CB_num, CB_step) \ + do { \ + int _CB_i, _CB_base; \ + CB_num = 0; \ + _CB_base = 1; \ + if((size) < 2){ \ + CB_num = ((signed char *)(CB_buf))[0]; \ + (CB_step) = 1; \ + } else { \ + for(_CB_i = 0; _CB_i < (size); _CB_i++){ \ + if(((signed char *)(CB_buf))[_CB_i] >= 0){ \ + CB_num += ((signed char *)(CB_buf))[_CB_i] * _CB_base; \ + break; \ + } \ + CB_num += _CB_base * (((signed char *)(CB_buf))[_CB_i] + 1) * -1; \ + _CB_base *= 128; \ + } \ + (CB_step) = _CB_i + 1; \ + } \ + } while(FALSE) + +/* get the first hash value */ +#define CB_FIRSTHASH(CB_res, CB_kbuf, CB_ksiz) \ + do { \ + const unsigned char *_CB_p; \ + int _CB_ksiz; \ + _CB_p = (const unsigned char *)(CB_kbuf); \ + _CB_ksiz = CB_ksiz; \ + for((CB_res) = 19780211; _CB_ksiz--;){ \ + (CB_res) = (CB_res) * 37 + *(_CB_p)++; \ + } \ + (CB_res) &= INT_MAX; \ + } while(FALSE) + +/* get the second hash value */ +#define CB_SECONDHASH(CB_res, CB_kbuf, CB_ksiz) \ + do { \ + const unsigned char *_CB_p; \ + int _CB_ksiz; \ + _CB_p = (const unsigned char *)(CB_kbuf) + CB_ksiz - 1; \ + _CB_ksiz = CB_ksiz; \ + for((CB_res) = 0x13579bdf; _CB_ksiz--;){ \ + (CB_res) = (CB_res) * 31 + *(_CB_p)--; \ + } \ + (CB_res) &= INT_MAX; \ + } while(FALSE) + + +/* private function prototypes */ +static void cbggchandler(void); +static void cbggckeeper(void *ptr, void (*func)(void *)); +static void cbqsortsub(char *bp, int nmemb, int size, char *pswap, char *vswap, + int(*compar)(const void *, const void *)); +static int cblistelemcmp(const void *a, const void *b); +static int cbkeycmp(const char *abuf, int asiz, const char *bbuf, int bsiz); + + + +/************************************************************************************************* + * public objects + *************************************************************************************************/ + + +/* Call back function for handling a fatal error. */ +void (*cbfatalfunc)(const char *message) = NULL; + + +/* Allocate a region on memory. */ +void *cbmalloc(size_t size){ + char *p; + assert(size > 0 && size < INT_MAX); + if(!(p = malloc(size))) cbmyfatal("out of memory"); + return p; +} + + +/* Re-allocate a region on memory. */ +void *cbrealloc(void *ptr, size_t size){ + char *p; + assert(size > 0); + if(!(p = realloc(ptr, size))) cbmyfatal("out of memory"); + return p; +} + + +/* Duplicate a region on memory. */ +char *cbmemdup(const char *ptr, int size){ + char *p; + assert(ptr); + if(size < 0) size = strlen(ptr); + CB_MALLOC(p, size + 1); + memcpy(p, ptr, size); + p[size] = '\0'; + return p; +} + + +/* Free a region on memory. */ +void cbfree(void *ptr){ + free(ptr); +} + + +/* Register the pointer or handle of an object to the global garbage collector. */ +void cbglobalgc(void *ptr, void (*func)(void *)){ + assert(ptr && func); + cbggckeeper(ptr, func); +} + + +/* Exercise the global garbage collector explicitly. */ +void cbggcsweep(void){ + cbggckeeper(NULL, NULL); +} + + +/* Check availability of allocation of the virtual memory. */ +int cbvmemavail(size_t size){ + assert(size >= 0); + return _qdbm_vmemavail(size); +} + + +/* Sort an array using insert sort. */ +void cbisort(void *base, int nmemb, int size, int(*compar)(const void *, const void *)){ + char *bp, *swap; + int i, j; + assert(base && nmemb >= 0 && size > 0 && compar); + bp = (char *)base; + CB_MALLOC(swap, size); + for(i = 1; i < nmemb; i++){ + if(compar(bp + (i - 1) * size, bp + i * size) > 0){ + memcpy(swap, bp + i * size, size); + for(j = i; j > 0; j--){ + if(compar(bp + (j - 1) * size, swap) < 0) break; + memcpy(bp + j * size, bp + (j - 1) * size, size); + } + memcpy(bp + j * size, swap, size); + } + } + free(swap); +} + + +/* Sort an array using shell sort. */ +void cbssort(void *base, int nmemb, int size, int(*compar)(const void *, const void *)){ + char *bp, *swap; + int step, bottom, i, j; + assert(base && nmemb >= 0 && size > 0 && compar); + bp = (char *)base; + CB_MALLOC(swap, size); + for(step = (nmemb - 1) / 3; step >= 0; step = (step - 1) / 3){ + if(step < 5) step = 1; + for(bottom = 0; bottom < step; bottom++){ + for(i = bottom + step; i < nmemb; i += step){ + if(compar(bp + (i - step) * size, bp + i * size) > 0){ + memcpy(swap, bp + i * size, size); + for(j = i; j > step - 1; j -= step){ + if(compar(bp + (j - step) * size, swap) < 0) break; + memcpy(bp + j * size, bp + (j - step) * size, size); + } + memcpy(bp + j * size, swap, size); + } + } + } + if(step < 2) break; + } + free(swap); +} + + +/* Sort an array using heap sort. */ +void cbhsort(void *base, int nmemb, int size, int(*compar)(const void *, const void *)){ + char *bp, *swap; + int top, bottom, mybot, i; + assert(base && nmemb >= 0 && size > 0 && compar); + bp = (char *)base; + nmemb--; + bottom = nmemb / 2 + 1; + top = nmemb; + CB_MALLOC(swap, size); + while(bottom > 0){ + bottom--; + mybot = bottom; + i = 2 * mybot; + while(i <= top) { + if(i < top && compar(bp + (i + 1) * size, bp + i * size) > 0) i++; + if(compar(bp + mybot * size, bp + i * size) >= 0) break; + memcpy(swap, bp + mybot * size, size); + memcpy(bp + mybot * size, bp + i * size, size); + memcpy(bp + i * size, swap, size); + mybot = i; + i = 2 * mybot; + } + } + while(top > 0){ + memcpy(swap, bp, size); + memcpy(bp, bp + top * size, size); + memcpy(bp + top * size, swap, size); + top--; + mybot = bottom; + i = 2 * mybot; + while(i <= top){ + if(i < top && compar(bp + (i + 1) * size, bp + i * size) > 0) i++; + if(compar(bp + mybot * size, bp + i * size) >= 0) break; + memcpy(swap, bp + mybot * size, size); + memcpy(bp + mybot * size, bp + i * size, size); + memcpy(bp + i * size, swap, size); + mybot = i; + i = 2 * mybot; + } + } + free(swap); +} + + +/* Sort an array using quick sort. */ +void cbqsort(void *base, int nmemb, int size, int(*compar)(const void *, const void *)){ + char *pswap, *vswap; + assert(base && nmemb >= 0 && size > 0 && compar); + CB_MALLOC(pswap, size); + CB_MALLOC(vswap, size); + cbqsortsub(base, nmemb, size, pswap, vswap, compar); + free(vswap); + free(pswap); +} + + +/* Compare two strings with case insensitive evaluation. */ +int cbstricmp(const char *astr, const char *bstr){ + int ac, bc; + assert(astr && bstr); + while(*astr != '\0'){ + if(*bstr == '\0') return 1; + ac = (*astr >= 'A' && *astr <= 'Z') ? *astr + ('a' - 'A') : *(unsigned char *)astr; + bc = (*bstr >= 'A' && *bstr <= 'Z') ? *bstr + ('a' - 'A') : *(unsigned char *)bstr; + if(ac != bc) return ac - bc; + astr++; + bstr++; + } + return *bstr == '\0' ? 0 : -1; +} + + +/* Check whether a string begins with a key. */ +int cbstrfwmatch(const char *str, const char *key){ + assert(str && key); + while(*key != '\0'){ + if(*str != *key || *str == '\0') return FALSE; + key++; + str++; + } + return TRUE; +} + + +/* Check whether a string begins with a key, with case insensitive evaluation. */ +int cbstrfwimatch(const char *str, const char *key){ + int sc, kc; + assert(str && key); + while(*key != '\0'){ + if(*str == '\0') return FALSE; + sc = *str; + if(sc >= 'A' && sc <= 'Z') sc += 'a' - 'A'; + kc = *key; + if(kc >= 'A' && kc <= 'Z') kc += 'a' - 'A'; + if(sc != kc) return FALSE; + key++; + str++; + } + return TRUE; +} + + +/* Check whether a string ends with a key. */ +int cbstrbwmatch(const char *str, const char *key){ + int slen, klen, i; + assert(str && key); + slen = strlen(str); + klen = strlen(key); + for(i = 1; i <= klen; i++){ + if(i > slen || str[slen-i] != key[klen-i]) return FALSE; + } + return TRUE; +} + + +/* Check whether a string ends with a key, with case insensitive evaluation. */ +int cbstrbwimatch(const char *str, const char *key){ + int slen, klen, i, sc, kc; + assert(str && key); + slen = strlen(str); + klen = strlen(key); + for(i = 1; i <= klen; i++){ + if(i > slen) return FALSE; + sc = str[slen-i]; + if(sc >= 'A' && sc <= 'Z') sc += 'a' - 'A'; + kc = key[klen-i]; + if(kc >= 'A' && kc <= 'Z') kc += 'a' - 'A'; + if(sc != kc) return FALSE; + } + return TRUE; +} + + +/* Locate a substring in a string using KMP method. */ +char *cbstrstrkmp(const char *haystack, const char *needle){ + int i, j, hlen, nlen; + signed char tbl[0x100]; + assert(haystack && needle); + nlen = strlen(needle); + if(nlen >= 0x100) return strstr(haystack, needle); + tbl[0] = -1; + i = 0; + j = -1; + while(i < nlen){ + while((j >= 0) && (needle[i] != needle[j])){ + j = tbl[j]; + } + i++; + j++; + tbl[i] = j; + } + hlen = strlen(haystack); + i = 0; + j = 0; + while(i < hlen && j < nlen){ + while((j >= 0) && (haystack[i] != needle[j])){ + j = tbl[j]; + } + i++; + j++; + } + if(j == nlen) return (char *)(haystack + i - nlen); + return NULL; +} + + +/* Locate a substring in a string using BM method. */ +char *cbstrstrbm(const char *haystack, const char *needle){ + const unsigned char *rp; + const char *ep; + unsigned char tbl[0x100]; + int i, j, nlen, len, idx; + assert(haystack && needle); + nlen = strlen(needle); + if(nlen < 3 || nlen >= 0x100) return strstr(haystack, needle); + for(i = 0; i < 0x100; i++){ + tbl[i] = nlen; + } + len = nlen; + rp = (const unsigned char *)needle; + while(len > 0){ + tbl[*rp++] = --len; + } + nlen--; + ep = haystack + strlen(haystack) - nlen; + while(haystack < ep){ + for(i = nlen; haystack[i] == needle[i]; i--){ + if(i == 0) return (char *)haystack; + } + idx = ((unsigned char *)haystack)[i]; + j = tbl[idx] - nlen + i; + haystack += j > 0 ? j : 2; + } + return NULL; +} + + +/* Convert the letters of a string to upper case. */ +char *cbstrtoupper(char *str){ + int i; + assert(str); + for(i = 0; str[i] != '\0'; i++){ + if(str[i] >= 'a' && str[i] <= 'z') str[i] -= 'a' - 'A'; + } + return str; +} + + +/* Convert the letters of a string to lower case. */ +char *cbstrtolower(char *str){ + int i; + assert(str); + for(i = 0; str[i] != '\0'; i++){ + if(str[i] >= 'A' && str[i] <= 'Z') str[i] += 'a' - 'A'; + } + return str; +} + + +/* Cut space characters at head or tail of a string. */ +char *cbstrtrim(char *str){ + char *wp; + int i, head; + assert(str); + wp = str; + head = TRUE; + for(i = 0; str[i] != '\0'; i++){ + if((str[i] >= 0x07 && str[i] <= 0x0d) || str[i] == 0x20){ + if(!head) *(wp++) = str[i]; + } else { + *(wp++) = str[i]; + head = FALSE; + } + } + *wp = '\0'; + while(wp > str && ((wp[-1] >= 0x07 && wp[-1] <= 0x0d) || wp[-1] == 0x20)){ + *(--wp) = '\0'; + } + return str; +} + + +/* Squeeze space characters in a string and trim it. */ +char *cbstrsqzspc(char *str){ + char *wp; + int i, spc; + assert(str); + wp = str; + spc = TRUE; + for(i = 0; str[i] != '\0'; i++){ + if(str[i] > 0 && str[i] <= ' '){ + if(!spc) *(wp++) = str[i]; + spc = TRUE; + } else { + *(wp++) = str[i]; + spc = FALSE; + } + } + *wp = '\0'; + for(wp--; wp >= str; wp--){ + if(*wp > 0 && *wp <= ' '){ + *wp = '\0'; + } else { + break; + } + } + return str; +} + + +/* Count the number of characters in a string of UTF-8. */ +int cbstrcountutf(const char *str){ + const unsigned char *rp; + int cnt; + assert(str); + rp = (unsigned char *)str; + cnt = 0; + while(*rp != '\0'){ + if((*rp & 0x80) == 0x00 || (*rp & 0xe0) == 0xc0 || + (*rp & 0xf0) == 0xe0 || (*rp & 0xf8) == 0xf0) cnt++; + rp++; + } + return cnt; +} + + +/* Cut a string of UTF-8 at the specified number of characters. */ +char *cbstrcututf(char *str, int num){ + unsigned char *wp; + int cnt; + assert(str && num >= 0); + wp = (unsigned char *)str; + cnt = 0; + while(*wp != '\0'){ + if((*wp & 0x80) == 0x00 || (*wp & 0xe0) == 0xc0 || + (*wp & 0xf0) == 0xe0 || (*wp & 0xf8) == 0xf0){ + cnt++; + if(cnt > num){ + *wp = '\0'; + break; + } + } + wp++; + } + return str; +} + + +/* Get a datum handle. */ +CBDATUM *cbdatumopen(const char *ptr, int size){ + CBDATUM *datum; + CB_MALLOC(datum, sizeof(*datum)); + CB_MALLOC(datum->dptr, CB_DATUMUNIT); + datum->dptr[0] = '\0'; + datum->dsize = 0; + datum->asize = CB_DATUMUNIT; + if(ptr) CB_DATUMCAT(datum, ptr, (size >= 0 ? size : strlen(ptr))); + return datum; +} + + +/* Copy a datum. */ +CBDATUM *cbdatumdup(const CBDATUM *datum){ + assert(datum); + return cbdatumopen(datum->dptr, datum->dsize); +} + + +/* Free a datum handle. */ +void cbdatumclose(CBDATUM *datum){ + assert(datum); + free(datum->dptr); + free(datum); +} + + +/* Concatenate a datum and a region. */ +void cbdatumcat(CBDATUM *datum, const char *ptr, int size){ + assert(datum && ptr); + if(size < 0) size = strlen(ptr); + if(datum->dsize + size >= datum->asize){ + datum->asize = datum->asize * 2 + size + 1; + CB_REALLOC(datum->dptr, datum->asize); + } + memcpy(datum->dptr + datum->dsize, ptr, size); + datum->dsize += size; + datum->dptr[datum->dsize] = '\0'; +} + + +/* Get the pointer of the region of a datum. */ +const char *cbdatumptr(const CBDATUM *datum){ + assert(datum); + return datum->dptr; +} + + +/* Get the size of the region of a datum. */ +int cbdatumsize(const CBDATUM *datum){ + assert(datum); + return datum->dsize; +} + + +/* Set the size of the region of a datum. */ +void cbdatumsetsize(CBDATUM *datum, int size){ + assert(datum && size >= 0); + if(size <= datum->dsize){ + datum->dsize = size; + datum->dptr[size] = '\0'; + } else { + if(size >= datum->asize){ + datum->asize = datum->asize * 2 + size + 1; + CB_REALLOC(datum->dptr, datum->asize); + } + memset(datum->dptr + datum->dsize, 0, (size - datum->dsize) + 1); + datum->dsize = size; + } +} + + +/* Perform formatted output into a datum. */ +void cbdatumprintf(CBDATUM *datum, const char *format, ...){ + va_list ap; + char *tmp, cbuf[CB_NUMBUFSIZ], tbuf[CB_NUMBUFSIZ*2]; + unsigned char c; + int cblen, tlen; + assert(datum && format); + va_start(ap, format); + while(*format != '\0'){ + if(*format == '%'){ + cbuf[0] = '%'; + cblen = 1; + format++; + while(strchr("0123456789 .+-", *format) && *format != '\0' && cblen < CB_NUMBUFSIZ - 1){ + cbuf[cblen++] = *format; + format++; + } + cbuf[cblen++] = *format; + cbuf[cblen] = '\0'; + switch(*format){ + case 's': + tmp = va_arg(ap, char *); + if(!tmp) tmp = "(null)"; + cbdatumcat(datum, tmp, -1); + break; + case 'd': + tlen = sprintf(tbuf, cbuf, va_arg(ap, int)); + cbdatumcat(datum, tbuf, tlen); + break; + case 'o': case 'u': case 'x': case 'X': case 'c': + tlen = sprintf(tbuf, cbuf, va_arg(ap, unsigned int)); + cbdatumcat(datum, tbuf, tlen); + break; + case 'e': case 'E': case 'f': case 'g': case 'G': + tlen = sprintf(tbuf, cbuf, va_arg(ap, double)); + cbdatumcat(datum, tbuf, tlen); + break; + case '@': + tmp = va_arg(ap, char *); + if(!tmp) tmp = "(null)"; + while(*tmp){ + switch(*tmp){ + case '&': cbdatumcat(datum, "&", 5); break; + case '<': cbdatumcat(datum, "<", 4); break; + case '>': cbdatumcat(datum, ">", 4); break; + case '"': cbdatumcat(datum, """, 6); break; + default: + if(!((*tmp >= 0 && *tmp <= 0x8) || (*tmp >= 0x0e && *tmp <= 0x1f))) + cbdatumcat(datum, tmp, 1); + break; + } + tmp++; + } + break; + case '?': + tmp = va_arg(ap, char *); + if(!tmp) tmp = "(null)"; + while(*tmp){ + c = *(unsigned char *)tmp; + if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || + (c >= '0' && c <= '9') || (c != '\0' && strchr("_-.", c))){ + cbdatumcat(datum, tmp, 1); + } else { + tlen = sprintf(tbuf, "%%%02X", c); + cbdatumcat(datum, tbuf, tlen); + } + tmp++; + } + break; + case ':': + tmp = va_arg(ap, char *); + if(!tmp) tmp = ""; + tmp = cbmimeencode(tmp, "UTF-8", TRUE); + cbdatumcat(datum, tmp, -1); + free(tmp); + break; + case '%': + cbdatumcat(datum, "%", 1); + break; + } + } else { + cbdatumcat(datum, format, 1); + } + format++; + } + va_end(ap); +} + + +/* Convert a datum to an allocated region. */ +char *cbdatumtomalloc(CBDATUM *datum, int *sp){ + char *ptr; + assert(datum); + ptr = datum->dptr; + if(sp) *sp = datum->dsize; + free(datum); + return ptr; +} + + +/* Get a list handle. */ +CBLIST *cblistopen(void){ + CBLIST *list; + CB_MALLOC(list, sizeof(*list)); + list->anum = CB_LISTUNIT; + CB_MALLOC(list->array, sizeof(list->array[0]) * list->anum); + list->start = 0; + list->num = 0; + return list; +} + + +/* Copy a list. */ +CBLIST *cblistdup(const CBLIST *list){ + CBLIST *newlist; + int i, size; + const char *val; + assert(list); + CB_LISTOPEN2(newlist, CB_LISTNUM(list)); + for(i = 0; i < CB_LISTNUM(list); i++){ + val = CB_LISTVAL2(list, i, size); + CB_LISTPUSH(newlist, val, size); + } + return newlist; +} + + +/* Close a list handle. */ +void cblistclose(CBLIST *list){ + int i, end; + assert(list); + end = list->start + list->num; + for(i = list->start; i < end; i++){ + free(list->array[i].dptr); + } + free(list->array); + free(list); +} + + +/* Get the number of elements of a list. */ +int cblistnum(const CBLIST *list){ + assert(list); + return list->num; +} + + +/* Get the pointer to the region of an element. */ +const char *cblistval(const CBLIST *list, int index, int *sp){ + assert(list && index >= 0); + if(index >= list->num) return NULL; + index += list->start; + if(sp) *sp = list->array[index].dsize; + return list->array[index].dptr; +} + + +/* Add an element at the end of a list. */ +void cblistpush(CBLIST *list, const char *ptr, int size){ + int index; + assert(list && ptr); + if(size < 0) size = strlen(ptr); + index = list->start + list->num; + if(index >= list->anum){ + list->anum *= 2; + CB_REALLOC(list->array, list->anum * sizeof(list->array[0])); + } + CB_MALLOC(list->array[index].dptr, (size < CB_DATUMUNIT ? CB_DATUMUNIT : size) + 1); + memcpy(list->array[index].dptr, ptr, size); + list->array[index].dptr[size] = '\0'; + list->array[index].dsize = size; + list->num++; +} + + +/* Remove an element of the end of a list. */ +char *cblistpop(CBLIST *list, int *sp){ + int index; + assert(list); + if(list->num < 1) return NULL; + index = list->start + list->num - 1; + list->num--; + if(sp) *sp = list->array[index].dsize; + return list->array[index].dptr; +} + + +/* Add an element at the top of a list. */ +void cblistunshift(CBLIST *list, const char *ptr, int size){ + int index; + assert(list && ptr); + if(size < 0) size = strlen(ptr); + if(list->start < 1){ + if(list->start + list->num >= list->anum){ + list->anum *= 2; + CB_REALLOC(list->array, list->anum * sizeof(list->array[0])); + } + list->start = list->anum - list->num; + memmove(list->array + list->start, list->array, list->num * sizeof(list->array[0])); + } + index = list->start - 1; + CB_MALLOC(list->array[index].dptr, (size < CB_DATUMUNIT ? CB_DATUMUNIT : size) + 1); + memcpy(list->array[index].dptr, ptr, size); + list->array[index].dptr[size] = '\0'; + list->array[index].dsize = size; + list->start--; + list->num++; +} + + +/* Remove an element of the top of a list. */ +char *cblistshift(CBLIST *list, int *sp){ + int index; + assert(list); + if(list->num < 1) return NULL; + index = list->start; + list->start++; + list->num--; + if(sp) *sp = list->array[index].dsize; + return list->array[index].dptr; +} + + +/* Add an element at the specified location of a list. */ +void cblistinsert(CBLIST *list, int index, const char *ptr, int size){ + assert(list && index >= 0); + if(index > list->num) return; + if(size < 0) size = strlen(ptr); + index += list->start; + if(list->start + list->num >= list->anum){ + list->anum *= 2; + CB_REALLOC(list->array, list->anum * sizeof(list->array[0])); + } + memmove(list->array + index + 1, list->array + index, + sizeof(list->array[0]) * (list->start + list->num - index)); + CB_MEMDUP(list->array[index].dptr, ptr, size); + list->array[index].dsize = size; + list->num++; +} + + +/* Remove an element at the specified location of a list. */ +char *cblistremove(CBLIST *list, int index, int *sp){ + char *dptr; + assert(list && index >= 0); + if(index >= list->num) return NULL; + index += list->start; + dptr = list->array[index].dptr; + if(sp) *sp = list->array[index].dsize; + list->num--; + memmove(list->array + index, list->array + index + 1, + sizeof(list->array[0]) * (list->start + list->num - index)); + return dptr; +} + + +/* Overwrite an element at the specified location of a list. */ +void cblistover(CBLIST *list, int index, const char *ptr, int size){ + assert(list && index >= 0); + if(index >= list->num) return; + if(size < 0) size = strlen(ptr); + index += list->start; + if(size > list->array[index].dsize) + CB_REALLOC(list->array[index].dptr, size + 1); + memcpy(list->array[index].dptr, ptr, size); + list->array[index].dsize = size; + list->array[index].dptr[size] = '\0'; +} + + +/* Sort elements of a list in lexical order. */ +void cblistsort(CBLIST *list){ + assert(list); + qsort(list->array + list->start, list->num, sizeof(list->array[0]), cblistelemcmp); +} + + +/* Search a list for an element using liner search. */ +int cblistlsearch(const CBLIST *list, const char *ptr, int size){ + int i, end; + assert(list && ptr); + if(size < 0) size = strlen(ptr); + end = list->start + list->num; + for(i = list->start; i < end; i++){ + if(list->array[i].dsize == size && !memcmp(list->array[i].dptr, ptr, size)) + return i - list->start; + } + return -1; +} + + +/* Search a list for an element using binary search. */ +int cblistbsearch(const CBLIST *list, const char *ptr, int size){ + CBLISTDATUM key, *res; + assert(list && ptr); + if(size < 0) size = strlen(ptr); + CB_MEMDUP(key.dptr, ptr, size); + key.dsize = size; + res = bsearch(&key, list->array + list->start, list->num, sizeof(list->array[0]), cblistelemcmp); + free(key.dptr); + return res ? (res - list->array - list->start) : -1; +} + + +/* Serialize a list into a byte array. */ +char *cblistdump(const CBLIST *list, int *sp){ + char *buf, vnumbuf[CB_VNUMBUFSIZ]; + const char *vbuf; + int i, bsiz, vnumsiz, ln, vsiz; + assert(list && sp); + ln = CB_LISTNUM(list); + CB_SETVNUMBUF(vnumsiz, vnumbuf, ln); + CB_MALLOC(buf, vnumsiz + 1); + memcpy(buf, vnumbuf, vnumsiz); + bsiz = vnumsiz; + for(i = 0; i < ln; i++){ + vbuf = CB_LISTVAL2(list, i, vsiz); + CB_SETVNUMBUF(vnumsiz, vnumbuf, vsiz); + CB_REALLOC(buf, bsiz + vnumsiz + vsiz + 1); + memcpy(buf + bsiz, vnumbuf, vnumsiz); + bsiz += vnumsiz; + memcpy(buf + bsiz, vbuf, vsiz); + bsiz += vsiz; + } + *sp = bsiz; + return buf; +} + + +/* Redintegrate a serialized list. */ +CBLIST *cblistload(const char *ptr, int size){ + CBLIST *list; + const char *rp; + int i, anum, step, ln, vsiz; + assert(ptr && size >= 0); + anum = size / (sizeof(CBLISTDATUM) + 1); + CB_LISTOPEN2(list, anum); + rp = ptr; + CB_READVNUMBUF(rp, size, ln, step); + rp += step; + size -= step; + if(ln > size) return list; + for(i = 0; i < ln; i++){ + if(size < 1) break; + CB_READVNUMBUF(rp, size, vsiz, step); + rp += step; + size -= step; + if(vsiz > size) break; + CB_LISTPUSH(list, rp, vsiz); + rp += vsiz; + } + return list; +} + + +/* Get a map handle. */ +CBMAP *cbmapopen(void){ + return cbmapopenex(CB_MAPBNUM); +} + + +/* Copy a map. */ +CBMAP *cbmapdup(CBMAP *map){ + CBMAP *newmap; + const char *kbuf, *vbuf; + int ksiz, vsiz; + assert(map); + cbmapiterinit(map); + newmap = map->rnum > CB_MAPPBNUM ? cbmapopen() : cbmapopenex(CB_MAPPBNUM); + while((kbuf = cbmapiternext(map, &ksiz)) != NULL){ + CB_MAPITERVAL(vbuf, kbuf, vsiz); + cbmapput(newmap, kbuf, ksiz, vbuf, vsiz, FALSE); + } + cbmapiterinit(map); + return newmap; +} + + +/* Close a map handle. */ +void cbmapclose(CBMAP *map){ + CBMAPDATUM *datum, *next; + datum = map->first; + while(datum){ + next = datum->next; + free(datum); + datum = next; + } + free(map->buckets); + free(map); +} + + +/* Store a record. */ +int cbmapput(CBMAP *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int over){ + CBMAPDATUM *datum, **entp, *old; + char *dbuf; + int bidx, hash, kcmp, psiz; + assert(map && kbuf && vbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if(vsiz < 0) vsiz = strlen(vbuf); + CB_FIRSTHASH(hash, kbuf, ksiz); + bidx = hash % map->bnum; + datum = map->buckets[bidx]; + entp = map->buckets + bidx; + CB_SECONDHASH(hash, kbuf, ksiz); + while(datum){ + if(hash > datum->hash){ + entp = &(datum->left); + datum = datum->left; + } else if(hash < datum->hash){ + entp = &(datum->right); + datum = datum->right; + } else { + dbuf = (char *)datum + sizeof(*datum); + kcmp = cbkeycmp(kbuf, ksiz, dbuf, datum->ksiz); + if(kcmp < 0){ + entp = &(datum->left); + datum = datum->left; + } else if(kcmp > 0){ + entp = &(datum->right); + datum = datum->right; + } else { + if(!over) return FALSE; + psiz = CB_ALIGNPAD(ksiz); + if(vsiz > datum->vsiz){ + old = datum; + CB_REALLOC(datum, sizeof(*datum) + ksiz + psiz + vsiz + 1); + if(datum != old){ + if(map->first == old) map->first = datum; + if(map->last == old) map->last = datum; + if(*entp == old) *entp = datum; + if(datum->prev) datum->prev->next = datum; + if(datum->next) datum->next->prev = datum; + dbuf = (char *)datum + sizeof(*datum); + } + } + memcpy(dbuf + ksiz + psiz, vbuf, vsiz); + dbuf[ksiz+psiz+vsiz] = '\0'; + datum->vsiz = vsiz; + return TRUE; + } + } + } + psiz = CB_ALIGNPAD(ksiz); + CB_MALLOC(datum, sizeof(*datum) + ksiz + psiz + vsiz + 1); + dbuf = (char *)datum + sizeof(*datum); + memcpy(dbuf, kbuf, ksiz); + dbuf[ksiz] = '\0'; + datum->ksiz = ksiz; + memcpy(dbuf + ksiz + psiz, vbuf, vsiz); + dbuf[ksiz+psiz+vsiz] = '\0'; + datum->vsiz = vsiz; + datum->hash = hash; + datum->left = NULL; + datum->right = NULL; + datum->prev = map->last; + datum->next = NULL; + *entp = datum; + if(!map->first) map->first = datum; + if(map->last) map->last->next = datum; + map->last = datum; + map->rnum++; + return TRUE; +} + + +/* Concatenate a value at the end of the value of the existing record. */ +void cbmapputcat(CBMAP *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz){ + CBMAPDATUM *datum, **entp, *old; + char *dbuf; + int bidx, hash, kcmp, psiz, asiz, unit; + assert(map && kbuf && vbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if(vsiz < 0) vsiz = strlen(vbuf); + CB_FIRSTHASH(hash, kbuf, ksiz); + bidx = hash % map->bnum; + datum = map->buckets[bidx]; + entp = map->buckets + bidx; + CB_SECONDHASH(hash, kbuf, ksiz); + while(datum){ + if(hash > datum->hash){ + entp = &(datum->left); + datum = datum->left; + } else if(hash < datum->hash){ + entp = &(datum->right); + datum = datum->right; + } else { + dbuf = (char *)datum + sizeof(*datum); + kcmp = cbkeycmp(kbuf, ksiz, dbuf, datum->ksiz); + if(kcmp < 0){ + entp = &(datum->left); + datum = datum->left; + } else if(kcmp > 0){ + entp = &(datum->right); + datum = datum->right; + } else { + psiz = CB_ALIGNPAD(ksiz); + asiz = sizeof(*datum) + ksiz + psiz + datum->vsiz + vsiz + 1; + unit = asiz <= CB_MAPCSUNIT ? CB_MAPCSUNIT : CB_MAPCBUNIT; + asiz = (asiz - 1) + unit - (asiz - 1) % unit; + old = datum; + CB_REALLOC(datum, asiz); + if(datum != old){ + if(map->first == old) map->first = datum; + if(map->last == old) map->last = datum; + if(*entp == old) *entp = datum; + if(datum->prev) datum->prev->next = datum; + if(datum->next) datum->next->prev = datum; + dbuf = (char *)datum + sizeof(*datum); + } + memcpy(dbuf + ksiz + psiz + datum->vsiz, vbuf, vsiz); + dbuf[ksiz+psiz+datum->vsiz+vsiz] = '\0'; + datum->vsiz += vsiz; + return; + } + } + } + psiz = CB_ALIGNPAD(ksiz); + asiz = sizeof(*datum) + ksiz + psiz + vsiz + 1; + unit = asiz <= CB_MAPCSUNIT ? CB_MAPCSUNIT : CB_MAPCBUNIT; + asiz = (asiz - 1) + unit - (asiz - 1) % unit; + CB_MALLOC(datum, asiz); + dbuf = (char *)datum + sizeof(*datum); + memcpy(dbuf, kbuf, ksiz); + dbuf[ksiz] = '\0'; + datum->ksiz = ksiz; + memcpy(dbuf + ksiz + psiz, vbuf, vsiz); + dbuf[ksiz+psiz+vsiz] = '\0'; + datum->vsiz = vsiz; + datum->hash = hash; + datum->left = NULL; + datum->right = NULL; + datum->prev = map->last; + datum->next = NULL; + *entp = datum; + if(!map->first) map->first = datum; + if(map->last) map->last->next = datum; + map->last = datum; + map->rnum++; +} + + +/* Delete a record. */ +int cbmapout(CBMAP *map, const char *kbuf, int ksiz){ + CBMAPDATUM *datum, **entp, *tmp; + char *dbuf; + int bidx, hash, kcmp; + assert(map && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + CB_FIRSTHASH(hash, kbuf, ksiz); + bidx = hash % map->bnum; + datum = map->buckets[bidx]; + entp = map->buckets + bidx; + CB_SECONDHASH(hash, kbuf, ksiz); + while(datum){ + if(hash > datum->hash){ + entp = &(datum->left); + datum = datum->left; + } else if(hash < datum->hash){ + entp = &(datum->right); + datum = datum->right; + } else { + dbuf = (char *)datum + sizeof(*datum); + kcmp = cbkeycmp(kbuf, ksiz, dbuf, datum->ksiz); + if(kcmp < 0){ + entp = &(datum->left); + datum = datum->left; + } else if(kcmp > 0){ + entp = &(datum->right); + datum = datum->right; + } else { + if(datum->prev) datum->prev->next = datum->next; + if(datum->next) datum->next->prev = datum->prev; + if(datum == map->first) map->first = datum->next; + if(datum == map->last) map->last = datum->prev; + if(datum->left && !datum->right){ + *entp = datum->left; + } else if(!datum->left && datum->right){ + *entp = datum->right; + } else if(!datum->left && !datum->left){ + *entp = NULL; + } else { + *entp = datum->left; + tmp = *entp; + while(TRUE){ + if(hash > tmp->hash){ + if(tmp->left){ + tmp = tmp->left; + } else { + tmp->left = datum->right; + break; + } + } else if(hash < tmp->hash){ + if(tmp->right){ + tmp = tmp->right; + } else { + tmp->right = datum->right; + break; + } + } else { + kcmp = cbkeycmp(kbuf, ksiz, dbuf, datum->ksiz); + if(kcmp < 0){ + if(tmp->left){ + tmp = tmp->left; + } else { + tmp->left = datum->right; + break; + } + } else { + if(tmp->right){ + tmp = tmp->right; + } else { + tmp->right = datum->right; + break; + } + } + } + } + } + free(datum); + map->rnum--; + return TRUE; + } + } + } + return FALSE; +} + + +/* Retrieve a record. */ +const char *cbmapget(const CBMAP *map, const char *kbuf, int ksiz, int *sp){ + CBMAPDATUM *datum; + char *dbuf; + int hash, kcmp; + assert(map && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + CB_FIRSTHASH(hash, kbuf, ksiz); + datum = map->buckets[hash%map->bnum]; + CB_SECONDHASH(hash, kbuf, ksiz); + while(datum){ + if(hash > datum->hash){ + datum = datum->left; + } else if(hash < datum->hash){ + datum = datum->right; + } else { + dbuf = (char *)datum + sizeof(*datum); + kcmp = cbkeycmp(kbuf, ksiz, dbuf, datum->ksiz); + if(kcmp < 0){ + datum = datum->left; + } else if(kcmp > 0){ + datum = datum->right; + } else { + if(sp) *sp = datum->vsiz; + return dbuf + datum->ksiz + CB_ALIGNPAD(datum->ksiz); + } + } + } + return NULL; +} + + +/* Move a record to the edge. */ +int cbmapmove(CBMAP *map, const char *kbuf, int ksiz, int head){ + CBMAPDATUM *datum; + char *dbuf; + int hash, kcmp; + assert(map && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + CB_FIRSTHASH(hash, kbuf, ksiz); + datum = map->buckets[hash%map->bnum]; + CB_SECONDHASH(hash, kbuf, ksiz); + while(datum){ + if(hash > datum->hash){ + datum = datum->left; + } else if(hash < datum->hash){ + datum = datum->right; + } else { + dbuf = (char *)datum + sizeof(*datum); + kcmp = cbkeycmp(kbuf, ksiz, dbuf, datum->ksiz); + if(kcmp < 0){ + datum = datum->left; + } else if(kcmp > 0){ + datum = datum->right; + } else { + if(head){ + if(map->first == datum) return TRUE; + if(map->last == datum) map->last = datum->prev; + if(datum->prev) datum->prev->next = datum->next; + if(datum->next) datum->next->prev = datum->prev; + datum->prev = NULL; + datum->next = map->first; + map->first->prev = datum; + map->first = datum; + } else { + if(map->last == datum) return TRUE; + if(map->first == datum) map->first = datum->next; + if(datum->prev) datum->prev->next = datum->next; + if(datum->next) datum->next->prev = datum->prev; + datum->prev = map->last; + datum->next = NULL; + map->last->next = datum; + map->last = datum; + } + return TRUE; + } + } + } + return FALSE; +} + + +/* Initialize the iterator of a map handle. */ +void cbmapiterinit(CBMAP *map){ + assert(map); + map->cur = map->first; +} + + +/* Get the next key of the iterator. */ +const char *cbmapiternext(CBMAP *map, int *sp){ + CBMAPDATUM *datum; + assert(map); + if(!map->cur) return NULL; + datum = map->cur; + map->cur = datum->next; + if(sp) *sp = datum->ksiz; + return (char *)datum + sizeof(*datum); +} + + +/* Get the value binded to the key fetched from the iterator. */ +const char *cbmapiterval(const char *kbuf, int *sp){ + CBMAPDATUM *datum; + assert(kbuf); + datum = (CBMAPDATUM *)(kbuf - sizeof(*datum)); + if(sp) *sp = datum->vsiz; + return (char *)datum + sizeof(*datum) + datum->ksiz + CB_ALIGNPAD(datum->ksiz); +} + + +/* Get the number of the records stored in a map. */ +int cbmaprnum(const CBMAP *map){ + assert(map); + return map->rnum; +} + + +/* Get the list handle contains all keys in a map. */ +CBLIST *cbmapkeys(CBMAP *map){ + CBLIST *list; + const char *kbuf; + int anum, ksiz; + assert(map); + anum = cbmaprnum(map); + CB_LISTOPEN2(list, anum); + cbmapiterinit(map); + while((kbuf = cbmapiternext(map, &ksiz)) != NULL){ + CB_LISTPUSH(list, kbuf, ksiz); + } + return list; +} + + +/* Get the list handle contains all values in a map. */ +CBLIST *cbmapvals(CBMAP *map){ + CBLIST *list; + const char *kbuf, *vbuf; + int anum, ksiz, vsiz; + assert(map); + anum = cbmaprnum(map); + CB_LISTOPEN2(list, anum); + cbmapiterinit(map); + while((kbuf = cbmapiternext(map, &ksiz)) != NULL){ + CB_MAPITERVAL(vbuf, kbuf, vsiz); + CB_LISTPUSH(list, vbuf, vsiz); + } + return list; +} + + +/* Serialize a map into a byte array. */ +char *cbmapdump(CBMAP *map, int *sp){ + char *buf, vnumbuf[CB_VNUMBUFSIZ]; + const char *kbuf, *vbuf; + int bsiz, vnumsiz, rn, ksiz, vsiz; + assert(map && sp); + rn = cbmaprnum(map); + CB_SETVNUMBUF(vnumsiz, vnumbuf, rn); + CB_MALLOC(buf, vnumsiz + 1); + memcpy(buf, vnumbuf, vnumsiz); + bsiz = vnumsiz; + cbmapiterinit(map); + while((kbuf = cbmapiternext(map, &ksiz)) != NULL){ + CB_MAPITERVAL(vbuf, kbuf, vsiz); + CB_SETVNUMBUF(vnumsiz, vnumbuf, ksiz); + CB_REALLOC(buf, bsiz + vnumsiz + ksiz + 1); + memcpy(buf + bsiz, vnumbuf, vnumsiz); + bsiz += vnumsiz; + memcpy(buf + bsiz, kbuf, ksiz); + bsiz += ksiz; + CB_SETVNUMBUF(vnumsiz, vnumbuf, vsiz); + CB_REALLOC(buf, bsiz + vnumsiz + vsiz + 1); + memcpy(buf + bsiz, vnumbuf, vnumsiz); + bsiz += vnumsiz; + memcpy(buf + bsiz, vbuf, vsiz); + bsiz += vsiz; + } + *sp = bsiz; + return buf; +} + + +/* Redintegrate a serialized map. */ +CBMAP *cbmapload(const char *ptr, int size){ + CBMAP *map; + const char *rp, *kbuf, *vbuf; + int i, step, rn, ksiz, vsiz; + assert(ptr && size >= 0); + map = cbmapopenex(CB_MAPPBNUM); + rp = ptr; + CB_READVNUMBUF(rp, size, rn, step); + rp += step; + size -= step; + if(rn > size) return map; + for(i = 0; i < rn; i++){ + if(size < 1) break; + CB_READVNUMBUF(rp, size, ksiz, step); + rp += step; + size -= step; + if(ksiz > size) break; + kbuf = rp; + rp += ksiz; + if(size < 1) break; + CB_READVNUMBUF(rp, size, vsiz, step); + rp += step; + size -= step; + if(vsiz > size) break; + vbuf = rp; + rp += vsiz; + cbmapput(map, kbuf, ksiz, vbuf, vsiz, TRUE); + } + return map; +} + + +/* Redintegrate a serialized map and get one of the records. */ +char *cbmaploadone(const char *ptr, int size, const char *kbuf, int ksiz, int *sp){ + const char *rp, *tkbuf, *vbuf; + char *rv; + int i, step, rn, tksiz, vsiz; + assert(ptr && size >= 0 && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + rp = ptr; + CB_READVNUMBUF(rp, size, rn, step); + rp += step; + size -= step; + if(rn > size) return NULL; + for(i = 0; i < rn; i++){ + if(size < 1) break; + CB_READVNUMBUF(rp, size, tksiz, step); + rp += step; + size -= step; + if(tksiz > size) break; + tkbuf = rp; + rp += tksiz; + if(size < 1) break; + CB_READVNUMBUF(rp, size, vsiz, step); + rp += step; + size -= step; + if(vsiz > size) break; + vbuf = rp; + rp += vsiz; + if(tksiz == ksiz && !memcmp(tkbuf, kbuf, ksiz)){ + if(sp) *sp = vsiz; + CB_MEMDUP(rv, vbuf, vsiz); + return rv; + } + } + return NULL; +} + + +/* Get a heap handle. */ +CBHEAP *cbheapopen(int size, int max, int(*compar)(const void *, const void *)){ + CBHEAP *heap; + assert(size > 0 && max >= 0 && compar); + CB_MALLOC(heap, sizeof(*heap)); + CB_MALLOC(heap->base, size * max + 1); + CB_MALLOC(heap->swap, size); + heap->size = size; + heap->num = 0; + heap->max = max; + heap->compar = compar; + return heap; +} + + +/* Copy a heap. */ +CBHEAP *cbheapdup(CBHEAP *heap){ + CBHEAP *newheap; + assert(heap); + CB_MALLOC(newheap, sizeof(*newheap)); + CB_MEMDUP(newheap->base, heap->base, heap->size * heap->max); + CB_MALLOC(newheap->swap, heap->size); + newheap->size = heap->size; + newheap->num = heap->num; + newheap->max = heap->max; + newheap->compar = heap->compar; + return newheap; +} + + +/* Close a heap handle. */ +void cbheapclose(CBHEAP *heap){ + assert(heap); + free(heap->swap); + free(heap->base); + free(heap); +} + + +/* Get the number of the records stored in a heap. */ +int cbheapnum(CBHEAP *heap){ + assert(heap); + return heap->num; +} + + +/* Insert a record into a heap. */ +int cbheapinsert(CBHEAP *heap, const void *ptr){ + char *base; + int size, pidx, cidx, bot; + assert(heap && ptr); + if(heap->max < 1) return FALSE; + base = heap->base; + size = heap->size; + if(heap->num >= heap->max){ + if(heap->compar(ptr, base) > 0) return FALSE; + memcpy(base, ptr, size); + pidx = 0; + bot = heap->num / 2; + while(pidx < bot){ + cidx = pidx * 2 + 1; + if(cidx < heap->num - 1 && heap->compar(base + cidx * size, base + (cidx + 1) * size) < 0) + cidx++; + if(heap->compar(base + pidx * size, base + cidx * size) > 0) break; + memcpy(heap->swap, base + pidx * size, size); + memcpy(base + pidx * size, base + cidx * size, size); + memcpy(base + cidx * size, heap->swap, size); + pidx = cidx; + } + } else { + memcpy(base + size * heap->num, ptr, size); + cidx = heap->num; + while(cidx > 0){ + pidx = (cidx - 1) / 2; + if(heap->compar(base + cidx * size, base + pidx * size) <= 0) break; + memcpy(heap->swap, base + cidx * size, size); + memcpy(base + cidx * size, base + pidx * size, size); + memcpy(base + pidx * size, heap->swap, size); + cidx = pidx; + } + heap->num++; + } + return TRUE; +} + + +/* Get the pointer to the region of a record in a heap. */ +const void *cbheapval(CBHEAP *heap, int index){ + assert(heap && index >= 0); + if(index >= heap->num) return NULL; + return heap->base + index * heap->size; +} + + +/* Convert a heap to an allocated region. */ +void *cbheaptomalloc(CBHEAP *heap, int *np){ + char *ptr; + assert(heap); + qsort(heap->base, heap->num, heap->size, heap->compar); + ptr = heap->base; + if(np) *np = heap->num; + free(heap->swap); + free(heap); + return ptr; +} + + +/* Allocate a formatted string on memory. */ +char *cbsprintf(const char *format, ...){ + va_list ap; + char *buf, cbuf[CB_SPBUFSIZ], *str; + int len, cblen, num, slen; + unsigned int unum; + double dnum; + va_start(ap, format); + assert(format); + CB_MALLOC(buf, 1); + len = 0; + while(*format != '\0'){ + if(*format == '%'){ + cbuf[0] = '%'; + cblen = 1; + format++; + while(strchr("0123456789 .+-", *format) && *format != '\0' && cblen < CB_SPBUFSIZ - 1){ + cbuf[cblen++] = *format; + format++; + } + cbuf[cblen] = '\0'; + if(atoi(cbuf + 1) > CB_SPMAXWIDTH - 16){ + sprintf(cbuf, "(err)"); + } else { + cbuf[cblen++] = *format; + cbuf[cblen] = '\0'; + } + switch(*format){ + case 'd': + num = va_arg(ap, int); + CB_REALLOC(buf, len + CB_SPMAXWIDTH + 2); + len += sprintf(buf + len, cbuf, num); + break; + case 'o': case 'u': case 'x': case 'X': case 'c': + unum = va_arg(ap, unsigned int); + CB_REALLOC(buf, len + CB_SPMAXWIDTH + 2); + len += sprintf(buf + len, cbuf, unum); + break; + case 'e': case 'E': case 'f': case 'g': case 'G': + dnum = va_arg(ap, double); + CB_REALLOC(buf, len + CB_SPMAXWIDTH + 2); + len += sprintf(buf + len, cbuf, dnum); + break; + case 's': + str = va_arg(ap, char *); + slen = strlen(str); + CB_REALLOC(buf, len + slen + 2); + memcpy(buf + len, str, slen); + len += slen; + break; + case '%': + CB_REALLOC(buf, len + 2); + buf[len++] = '%'; + break; + default: + break; + } + } else { + CB_REALLOC(buf, len + 2); + buf[len++] = *format; + } + format++; + } + buf[len] = '\0'; + va_end(ap); + return buf; +} + + +/* Replace some patterns in a string. */ +char *cbreplace(const char *str, CBMAP *pairs){ + int i, bsiz, wi, rep, ksiz, vsiz; + char *buf; + const char *key, *val; + assert(str && pairs); + bsiz = CB_DATUMUNIT; + CB_MALLOC(buf, bsiz); + wi = 0; + while(*str != '\0'){ + rep = FALSE; + cbmapiterinit(pairs); + while((key = cbmapiternext(pairs, &ksiz)) != NULL){ + for(i = 0; i < ksiz; i++){ + if(str[i] == '\0' || str[i] != key[i]) break; + } + if(i == ksiz){ + CB_MAPITERVAL(val, key, vsiz); + if(wi + vsiz >= bsiz){ + bsiz = bsiz * 2 + vsiz; + CB_REALLOC(buf, bsiz); + } + memcpy(buf + wi, val, vsiz); + wi += vsiz; + str += ksiz; + rep = TRUE; + break; + } + } + if(!rep){ + if(wi + 1 >= bsiz){ + bsiz = bsiz * 2 + 1; + CB_REALLOC(buf, bsiz); + } + buf[wi++] = *str; + str++; + } + } + CB_REALLOC(buf, wi + 1); + buf[wi] = '\0'; + return buf; +} + + +/* Make a list by split a serial datum. */ +CBLIST *cbsplit(const char *ptr, int size, const char *delim){ + CBLIST *list; + int bi, step; + assert(ptr); + CB_LISTOPEN(list); + if(size < 0) size = strlen(ptr); + if(delim){ + for(bi = 0; bi < size; bi += step){ + step = 0; + while(bi + step < size && !strchr(delim, ptr[bi+step])){ + step++; + } + cblistpush(list, ptr + bi, step); + step++; + } + if(size > 0 && strchr(delim, ptr[size-1])) cblistpush(list, "", 0); + } else { + for(bi = 0; bi < size; bi += step){ + step = 0; + while(bi + step < size && ptr[bi+step]){ + step++; + } + cblistpush(list, ptr + bi, step); + step++; + } + if(size > 0 && ptr[size-1] == 0) cblistpush(list, "", 0); + } + return list; +} + + +/* Read whole data of a file. */ +char *cbreadfile(const char *name, int *sp){ + struct stat sbuf; + char iobuf[CB_IOBUFSIZ], *buf; + int fd, size, asiz, rv; + asiz = CB_IOBUFSIZ * 2; + if(name){ + if((fd = open(name, O_RDONLY, 0)) == -1) return NULL; + if(fstat(fd, &sbuf) != -1) asiz = sbuf.st_size + 1; + } else { + fd = 0; + } + CB_MALLOC(buf, asiz + 1); + size = 0; + while((rv = read(fd, iobuf, CB_IOBUFSIZ)) > 0){ + if(size + rv >= asiz){ + asiz = asiz * 2 + size; + CB_REALLOC(buf, asiz + 1); + } + memcpy(buf + size, iobuf, rv); + size += rv; + } + buf[size] = '\0'; + if(close(fd) == -1 || rv == -1){ + free(buf); + return NULL; + } + if(sp) *sp = size; + return buf; +} + + +/* Write data of a region into a file. */ +int cbwritefile(const char *name, const char *ptr, int size){ + int fd, err, wb; + assert(ptr); + if(size < 0) size = strlen(ptr); + if(name){ + if((fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, CB_FILEMODE)) == -1) return FALSE; + } else { + fd = 1; + } + err = FALSE; + wb = 0; + do { + wb = write(fd, ptr, size); + switch(wb){ + case -1: err = errno != EINTR ? TRUE : FALSE; break; + case 0: break; + default: + ptr += wb; + size -= wb; + break; + } + } while(size > 0); + if(close(fd) == -1) err = TRUE; + return err ? FALSE : TRUE; +} + + +/* Read every line of a file. */ +CBLIST *cbreadlines(const char *name){ + char *buf, *tmp; + int vsiz; + CBMAP *pairs; + CBLIST *list; + if(!(buf = cbreadfile(name, NULL))) return NULL; + pairs = cbmapopenex(3); + cbmapput(pairs, "\r\n", 2, "\n", 1, TRUE); + cbmapput(pairs, "\r", 1, "\n", 1, TRUE); + tmp = cbreplace(buf, pairs); + list = cbsplit(tmp, strlen(tmp), "\n"); + free(tmp); + cbmapclose(pairs); + free(buf); + if(CB_LISTNUM(list) > 0){ + cblistval(list, CB_LISTNUM(list) - 1, &vsiz); + if(vsiz < 1) CB_LISTDROP(list); + } + return list; +} + + +/* Read names of files in a directory. */ +CBLIST *cbdirlist(const char *name){ + DIR *DD; + struct dirent *dp; + CBLIST *list; + assert(name); + if(!(DD = opendir(name))) return NULL; + CB_LISTOPEN(list); + while((dp = readdir(DD)) != NULL){ + CB_LISTPUSH(list, dp->d_name, strlen(dp->d_name)); + } + if(closedir(DD) == -1){ + CB_LISTCLOSE(list); + return NULL; + } + return list; +} + + +/* Get the status of a file or a directory. */ +int cbfilestat(const char *name, int *isdirp, int *sizep, time_t *mtimep){ + struct stat sbuf; + assert(name); + if(lstat(name, &sbuf) == -1) return FALSE; + if(isdirp) *isdirp = S_ISDIR(sbuf.st_mode); + if(sizep) *sizep = (int)sbuf.st_size; + if(mtimep) *mtimep = sbuf.st_mtime; + return TRUE; +} + + +/* Remove a file or a directory and its sub ones recursively. */ +int cbremove(const char *name){ + CBLIST *list; + const char *elem; + char *path; + int i, err, tail; + struct stat sbuf; + assert(name); + if(lstat(name, &sbuf) == -1) return FALSE; + if(unlink(name) == 0) return TRUE; + if(!S_ISDIR(sbuf.st_mode) || !(list = cbdirlist(name))) return FALSE; + err = FALSE; + tail = name[0] != '\0' && name[strlen(name)-1] == MYPATHCHR; + for(i = 0; i < CB_LISTNUM(list); i++){ + elem = CB_LISTVAL(list, i); + if(!strcmp(MYCDIRSTR, elem) || !strcmp(MYPDIRSTR, elem)) continue; + if(tail){ + path = cbsprintf("%s%s", name, elem); + } else { + path = cbsprintf("%s%c%s", name, MYPATHCHR, elem); + } + if(!cbremove(path)) err = TRUE; + free(path); + } + CB_LISTCLOSE(list); + return rmdir(name) == 0 ? TRUE : FALSE; +} + + +/* Break up a URL into elements. */ +CBMAP *cburlbreak(const char *str){ + CBMAP *map; + char *tmp, *ep; + const char *rp; + int serv; + assert(str); + map = cbmapopenex(CB_MAPPBNUM); + CB_MEMDUP(tmp, str, strlen(str)); + rp = cbstrtrim(tmp); + cbmapput(map, "self", -1, rp, -1, TRUE); + serv = FALSE; + if(cbstrfwimatch(rp, "http://")){ + cbmapput(map, "scheme", -1, "http", -1, TRUE); + rp += 7; + serv = TRUE; + } else if(cbstrfwimatch(rp, "https://")){ + cbmapput(map, "scheme", -1, "https", -1, TRUE); + rp += 8; + serv = TRUE; + } else if(cbstrfwimatch(rp, "ftp://")){ + cbmapput(map, "scheme", -1, "ftp", -1, TRUE); + rp += 6; + serv = TRUE; + } else if(cbstrfwimatch(rp, "sftp://")){ + cbmapput(map, "scheme", -1, "sftp", -1, TRUE); + rp += 7; + serv = TRUE; + } else if(cbstrfwimatch(rp, "ftps://")){ + cbmapput(map, "scheme", -1, "ftps", -1, TRUE); + rp += 7; + serv = TRUE; + } else if(cbstrfwimatch(rp, "tftp://")){ + cbmapput(map, "scheme", -1, "tftp", -1, TRUE); + rp += 7; + serv = TRUE; + } else if(cbstrfwimatch(rp, "ldap://")){ + cbmapput(map, "scheme", -1, "ldap", -1, TRUE); + rp += 7; + serv = TRUE; + } else if(cbstrfwimatch(rp, "ldaps://")){ + cbmapput(map, "scheme", -1, "ldaps", -1, TRUE); + rp += 8; + serv = TRUE; + } else if(cbstrfwimatch(rp, "file://")){ + cbmapput(map, "scheme", -1, "file", -1, TRUE); + rp += 7; + serv = TRUE; + } + if((ep = strchr(rp, '#')) != NULL){ + cbmapput(map, "fragment", -1, ep + 1, -1, TRUE); + *ep = '\0'; + } + if((ep = strchr(rp, '?')) != NULL){ + cbmapput(map, "query", -1, ep + 1, -1, TRUE); + *ep = '\0'; + } + if(serv){ + if((ep = strchr(rp, '/')) != NULL){ + cbmapput(map, "path", -1, ep, -1, TRUE); + *ep = '\0'; + } else { + cbmapput(map, "path", -1, "/", -1, TRUE); + } + if((ep = strchr(rp, '@')) != NULL){ + *ep = '\0'; + if(rp[0] != '\0') cbmapput(map, "authority", -1, rp, -1, TRUE); + rp = ep + 1; + } + if((ep = strchr(rp, ':')) != NULL){ + if(ep[1] != '\0') cbmapput(map, "port", -1, ep + 1, -1, TRUE); + *ep = '\0'; + } + if(rp[0] != '\0') cbmapput(map, "host", -1, rp, -1, TRUE); + } else { + cbmapput(map, "path", -1, rp, -1, TRUE); + } + free(tmp); + if((rp = cbmapget(map, "path", -1, NULL)) != NULL){ + if((ep = strrchr(rp, '/')) != NULL){ + if(ep[1] != '\0') cbmapput(map, "file", -1, ep + 1, -1, TRUE); + } else { + cbmapput(map, "file", -1, rp, -1, TRUE); + } + } + if((rp = cbmapget(map, "file", -1, NULL)) != NULL && (!strcmp(rp, ".") || !strcmp(rp, ".."))) + cbmapout(map, "file", -1); + return map; +} + + +/* Resolve a relative URL with another absolute URL. */ +char *cburlresolve(const char *base, const char *target){ + CBMAP *telems, *belems; + CBLIST *bpaths, *opaths, *qelems; + CBDATUM *rbuf; + const char *vbuf, *path; + char *tmp, *wp, *enc, numbuf[CB_NUMBUFSIZ]; + int i, vsiz, port, num; + assert(base && target); + while(*base > '\0' && *base <= ' '){ + base++; + } + while(*target > '\0' && *target <= ' '){ + target++; + } + if(*target == '\0') target = base; + CB_DATUMOPEN(rbuf); + telems = cburlbreak(target); + port = 80; + belems = cburlbreak(cbmapget(telems, "scheme", -1, &vsiz) ? target : base); + if((vbuf = cbmapget(belems, "scheme", -1, &vsiz)) != NULL){ + CB_DATUMCAT(rbuf, vbuf, vsiz); + CB_DATUMCAT(rbuf, "://", 3); + if(!cbstricmp(vbuf, "https")){ + port = 443; + } else if(!cbstricmp(vbuf, "ftp")){ + port = 21; + } else if(!cbstricmp(vbuf, "sftp")){ + port = 115; + } else if(!cbstricmp(vbuf, "ftps")){ + port = 22; + } else if(!cbstricmp(vbuf, "tftp")){ + port = 69; + } else if(!cbstricmp(vbuf, "ldap")){ + port = 389; + } else if(!cbstricmp(vbuf, "ldaps")){ + port = 636; + } + } else { + CB_DATUMCAT(rbuf, "http://", 7); + } + if((vbuf = cbmapget(belems, "authority", -1, &vsiz)) != NULL){ + if((wp = strchr(vbuf, ':')) != NULL){ + *wp = '\0'; + tmp = cburldecode(vbuf, NULL); + enc = cburlencode(tmp, -1); + CB_DATUMCAT(rbuf, enc, strlen(enc)); + free(enc); + free(tmp); + CB_DATUMCAT(rbuf, ":", 1); + wp++; + tmp = cburldecode(wp, NULL); + enc = cburlencode(tmp, -1); + CB_DATUMCAT(rbuf, enc, strlen(enc)); + free(enc); + free(tmp); + } else { + tmp = cburldecode(vbuf, NULL); + enc = cburlencode(tmp, -1); + CB_DATUMCAT(rbuf, enc, strlen(enc)); + free(enc); + free(tmp); + } + CB_DATUMCAT(rbuf, "@", 1); + } + if((vbuf = cbmapget(belems, "host", -1, &vsiz)) != NULL){ + tmp = cburldecode(vbuf, NULL); + cbstrtolower(tmp); + enc = cburlencode(tmp, -1); + CB_DATUMCAT(rbuf, enc, strlen(enc)); + free(enc); + free(tmp); + } else { + CB_DATUMCAT(rbuf, "localhost", 9); + } + if((vbuf = cbmapget(belems, "port", -1, &vsiz)) != NULL && + (num = atoi(vbuf)) != port && num > 1){ + sprintf(numbuf, ":%d", num); + CB_DATUMCAT(rbuf, numbuf, strlen(numbuf)); + } + if(!(path = cbmapget(telems, "path", -1, NULL))) path = "/"; + if(path[0] == '\0' && (vbuf = cbmapget(belems, "path", -1, NULL)) != NULL) path = vbuf; + if(path[0] == '\0') path = "/"; + CB_LISTOPEN(bpaths); + if(path[0] != '/' && (vbuf = cbmapget(belems, "path", -1, &vsiz)) != NULL){ + opaths = cbsplit(vbuf, vsiz, "/"); + } else { + opaths = cbsplit("/", 1, "/"); + } + CB_LISTDROP(opaths); + for(i = 0; i < CB_LISTNUM(opaths); i++){ + vbuf = CB_LISTVAL2(opaths, i, vsiz); + if(vsiz < 1 || !strcmp(vbuf, ".")) continue; + if(!strcmp(vbuf, "..")){ + CB_LISTDROP(bpaths); + } else { + CB_LISTPUSH(bpaths, vbuf, vsiz); + } + } + CB_LISTCLOSE(opaths); + opaths = cbsplit(path, -1, "/"); + for(i = 0; i < CB_LISTNUM(opaths); i++){ + vbuf = CB_LISTVAL2(opaths, i, vsiz); + if(vsiz < 1 || !strcmp(vbuf, ".")) continue; + if(!strcmp(vbuf, "..")){ + CB_LISTDROP(bpaths); + } else { + CB_LISTPUSH(bpaths, vbuf, vsiz); + } + } + CB_LISTCLOSE(opaths); + for(i = 0; i < CB_LISTNUM(bpaths); i++){ + vbuf = CB_LISTVAL(bpaths, i); + if(strchr(vbuf, '%')){ + tmp = cburldecode(vbuf, NULL); + } else { + CB_MEMDUP(tmp, vbuf, strlen(vbuf)); + } + enc = cburlencode(tmp, -1); + CB_DATUMCAT(rbuf, "/", 1); + CB_DATUMCAT(rbuf, enc, strlen(enc)); + free(enc); + free(tmp); + } + if(cbstrbwmatch(path, "/")) CB_DATUMCAT(rbuf, "/", 1); + CB_LISTCLOSE(bpaths); + if((vbuf = cbmapget(telems, "query", -1, &vsiz)) != NULL){ + CB_DATUMCAT(rbuf, "?", 1); + qelems = cbsplit(vbuf, vsiz, "&;"); + for(i = 0; i < CB_LISTNUM(qelems); i++){ + vbuf = CB_LISTVAL(qelems, i); + if(i > 0) CB_DATUMCAT(rbuf, "&", 1); + if((wp = strchr(vbuf, '=')) != NULL){ + *wp = '\0'; + tmp = cburldecode(vbuf, NULL); + enc = cburlencode(tmp, -1); + CB_DATUMCAT(rbuf, enc, strlen(enc)); + free(enc); + free(tmp); + CB_DATUMCAT(rbuf, "=", 1); + wp++; + tmp = cburldecode(wp, NULL); + enc = cburlencode(tmp, -1); + CB_DATUMCAT(rbuf, enc, strlen(enc)); + free(enc); + free(tmp); + } else { + tmp = cburldecode(vbuf, NULL); + enc = cburlencode(tmp, -1); + CB_DATUMCAT(rbuf, enc, strlen(enc)); + free(enc); + free(tmp); + } + } + CB_LISTCLOSE(qelems); + } + if((vbuf = cbmapget(telems, "fragment", -1, &vsiz)) != NULL){ + tmp = cburldecode(vbuf, NULL); + enc = cburlencode(tmp, -1); + CB_DATUMCAT(rbuf, "#", 1); + CB_DATUMCAT(rbuf, enc, strlen(enc)); + free(enc); + free(tmp); + } + cbmapclose(belems); + cbmapclose(telems); + return cbdatumtomalloc(rbuf, NULL); +} + + +/* Encode a serial object with URL encoding. */ +char *cburlencode(const char *ptr, int size){ + char *buf, *wp; + int i, c; + assert(ptr); + if(size < 0) size = strlen(ptr); + CB_MALLOC(buf, size * 3 + 1); + wp = buf; + for(i = 0; i < size; i++){ + c = ((unsigned char *)ptr)[i]; + if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || + (c >= '0' && c <= '9') || (c != '\0' && strchr("_-.!~*'()", c))){ + *(wp++) = c; + } else { + wp += sprintf(wp, "%%%02X", c); + } + } + *wp = '\0'; + return buf; +} + + +/* Decode a string encoded with URL encoding. */ +char *cburldecode(const char *str, int *sp){ + char *buf, *wp; + unsigned char c; + CB_MEMDUP(buf, str, strlen(str)); + wp = buf; + while(*str != '\0'){ + if(*str == '%'){ + str++; + if(((str[0] >= '0' && str[0] <= '9') || (str[0] >= 'A' && str[0] <= 'F') || + (str[0] >= 'a' && str[0] <= 'f')) && + ((str[1] >= '0' && str[1] <= '9') || (str[1] >= 'A' && str[1] <= 'F') || + (str[1] >= 'a' && str[1] <= 'f'))){ + c = *str; + if(c >= 'A' && c <= 'Z') c += 'a' - 'A'; + if(c >= 'a' && c <= 'z'){ + *wp = c - 'a' + 10; + } else { + *wp = c - '0'; + } + *wp *= 0x10; + str++; + c = *str; + if(c >= 'A' && c <= 'Z') c += 'a' - 'A'; + if(c >= 'a' && c <= 'z'){ + *wp += c - 'a' + 10; + } else { + *wp += c - '0'; + } + str++; + wp++; + } else { + break; + } + } else if(*str == '+'){ + *wp = ' '; + str++; + wp++; + } else { + *wp = *str; + str++; + wp++; + } + } + *wp = '\0'; + if(sp) *sp = wp - buf; + return buf; +} + + +/* Encode a serial object with Base64 encoding. */ +char *cbbaseencode(const char *ptr, int size){ + char *tbl = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + char *buf, *wp; + const unsigned char *obj; + int i; + assert(ptr); + if(size < 0) size = strlen(ptr); + CB_MALLOC(buf, 4 * (size + 2) / 3 + 1); + obj = (const unsigned char *)ptr; + wp = buf; + for(i = 0; i < size; i += 3){ + switch(size - i){ + case 1: + *wp++ = tbl[obj[0] >> 2]; + *wp++ = tbl[(obj[0] & 3) << 4]; + *wp++ = '='; + *wp++ = '='; + break; + case 2: + *wp++ = tbl[obj[0] >> 2]; + *wp++ = tbl[((obj[0] & 3) << 4) + (obj[1] >> 4)]; + *wp++ = tbl[(obj[1] & 0xf) << 2]; + *wp++ = '='; + break; + default: + *wp++ = tbl[obj[0] >> 2]; + *wp++ = tbl[((obj[0] & 3) << 4) + (obj[1] >> 4)]; + *wp++ = tbl[((obj[1] & 0xf) << 2) + (obj[2] >> 6)]; + *wp++ = tbl[obj[2] & 0x3f]; + break; + } + obj += 3; + } + *wp = '\0'; + return buf; +} + + +/* Decode a string encoded with Base64 encoding. */ +char *cbbasedecode(const char *str, int *sp){ + unsigned char *obj, *wp; + int len, cnt, bpos, i, bits, eqcnt; + assert(str); + cnt = 0; + bpos = 0; + eqcnt = 0; + len = strlen(str); + CB_MALLOC(obj, len + 4); + wp = obj; + while(bpos < len && eqcnt == 0){ + bits = 0; + for(i = 0; bpos < len && i < 4; bpos++){ + if(str[bpos] >= 'A' && str[bpos] <= 'Z'){ + bits = (bits << 6) | (str[bpos] - 'A'); + i++; + } else if(str[bpos] >= 'a' && str[bpos] <= 'z'){ + bits = (bits << 6) | (str[bpos] - 'a' + 26); + i++; + } else if(str[bpos] >= '0' && str[bpos] <= '9'){ + bits = (bits << 6) | (str[bpos] - '0' + 52); + i++; + } else if(str[bpos] == '+'){ + bits = (bits << 6) | 62; + i++; + } else if(str[bpos] == '/'){ + bits = (bits << 6) | 63; + i++; + } else if(str[bpos] == '='){ + bits <<= 6; + i++; + eqcnt++; + } + } + if(i == 0 && bpos >= len) continue; + switch(eqcnt){ + case 0: + *wp++ = (bits >> 16) & 0xff; + *wp++ = (bits >> 8) & 0xff; + *wp++ = bits & 0xff; + cnt += 3; + break; + case 1: + *wp++ = (bits >> 16) & 0xff; + *wp++ = (bits >> 8) & 0xff; + cnt += 2; + break; + case 2: + *wp++ = (bits >> 16) & 0xff; + cnt += 1; + break; + } + } + obj[cnt] = '\0'; + if(sp) *sp = cnt; + return (char *)obj; +} + + +/* Encode a serial object with quoted-printable encoding. */ +char *cbquoteencode(const char *ptr, int size){ + const unsigned char *rp; + char *buf, *wp; + int i, cols; + assert(ptr); + if(size < 0) size = strlen(ptr); + rp = (const unsigned char *)ptr; + CB_MALLOC(buf, size * 3 + 1); + wp = buf; + cols = 0; + for(i = 0; i < size; i++){ + if(rp[i] == '=' || (rp[i] < 0x20 && rp[i] != '\r' && rp[i] != '\n' && rp[i] != '\t') || + rp[i] > 0x7e){ + wp += sprintf(wp, "=%02X", rp[i]); + cols += 3; + } else { + *(wp++) = rp[i]; + cols++; + } + } + *wp = '\0'; + return buf; +} + + +/* Decode a string encoded with quoted-printable encoding. */ +char *cbquotedecode(const char *str, int *sp){ + char *buf, *wp; + assert(str); + CB_MALLOC(buf, strlen(str) + 1); + wp = buf; + for(; *str != '\0'; str++){ + if(*str == '='){ + str++; + if(*str == '\0'){ + break; + } else if(str[0] == '\r' && str[1] == '\n'){ + str++; + } else if(str[0] != '\n' && str[0] != '\r'){ + if(*str >= 'A' && *str <= 'Z'){ + *wp = (*str - 'A' + 10) * 16; + } else if(*str >= 'a' && *str <= 'z'){ + *wp = (*str - 'a' + 10) * 16; + } else { + *wp = (*str - '0') * 16; + } + str++; + if(*str == '\0') break; + if(*str >= 'A' && *str <= 'Z'){ + *wp += *str - 'A' + 10; + } else if(*str >= 'a' && *str <= 'z'){ + *wp += *str - 'a' + 10; + } else { + *wp += *str - '0'; + } + wp++; + } + } else { + *wp = *str; + wp++; + } + } + *wp = '\0'; + if(sp) *sp = wp - buf; + return buf; +} + + +/* Split a string of MIME into headers and the body. */ +char *cbmimebreak(const char *ptr, int size, CBMAP *attrs, int *sp){ + CBLIST *list; + const char *head, *line, *pv, *ep; + char *hbuf, *name, *rv; + int i, j, wi, hlen; + assert(ptr); + if(size < 0) size = strlen(ptr); + head = NULL; + hlen = 0; + for(i = 0; i < size; i++){ + if(i < size - 4 && ptr[i] == '\r' && ptr[i+1] == '\n' && + ptr[i+2] == '\r' && ptr[i+3] == '\n'){ + head = ptr; + hlen = i; + ptr += i + 4; + size -= i + 4; + break; + } else if(i < size - 2 && ptr[i] == '\n' && ptr[i+1] == '\n'){ + head = ptr; + hlen = i; + ptr += i + 2; + size -= i + 2; + break; + } + } + if(head && attrs){ + CB_MALLOC(hbuf, hlen + 1); + wi = 0; + for(i = 0; i < hlen; i++){ + if(head[i] == '\r') continue; + if(i < hlen - 1 && head[i] == '\n' && (head[i+1] == ' ' || head[i+1] == '\t')){ + hbuf[wi++] = ' '; + i++; + } else { + hbuf[wi++] = head[i]; + } + } + list = cbsplit(hbuf, wi, "\n"); + for(i = 0; i < CB_LISTNUM(list); i++){ + line = CB_LISTVAL(list, i); + if((pv = strchr(line, ':')) != NULL){ + CB_MEMDUP(name, line, pv - line); + for(j = 0; name[j] != '\0'; j++){ + if(name[j] >= 'A' && name[j] <= 'Z') name[j] -= 'A' - 'a'; + } + pv++; + while(*pv == ' ' || *pv == '\t'){ + pv++; + } + cbmapput(attrs, name, -1, pv, -1, TRUE); + free(name); + } + + } + CB_LISTCLOSE(list); + free(hbuf); + if((pv = cbmapget(attrs, "content-type", -1, NULL)) != NULL){ + if((ep = strchr(pv, ';')) != NULL){ + cbmapput(attrs, "TYPE", -1, pv, ep - pv, TRUE); + do { + ep++; + while(ep[0] == ' '){ + ep++; + } + if(cbstrfwimatch(ep, "charset=")){ + ep += 8; + while(*ep > '\0' && *ep <= ' '){ + ep++; + } + if(ep[0] == '"') ep++; + pv = ep; + while(ep[0] != '\0' && ep[0] != ' ' && ep[0] != '"' && ep[0] != ';'){ + ep++; + } + cbmapput(attrs, "CHARSET", -1, pv, ep - pv, TRUE); + } else if(cbstrfwimatch(ep, "boundary=")){ + ep += 9; + while(*ep > '\0' && *ep <= ' '){ + ep++; + } + if(ep[0] == '"'){ + ep++; + pv = ep; + while(ep[0] != '\0' && ep[0] != '"'){ + ep++; + } + } else { + pv = ep; + while(ep[0] != '\0' && ep[0] != ' ' && ep[0] != '"' && ep[0] != ';'){ + ep++; + } + } + cbmapput(attrs, "BOUNDARY", -1, pv, ep - pv, TRUE); + } + } while((ep = strchr(ep, ';')) != NULL); + } else { + cbmapput(attrs, "TYPE", -1, pv, -1, TRUE); + } + } + if((pv = cbmapget(attrs, "content-disposition", -1, NULL)) != NULL){ + if((ep = strchr(pv, ';')) != NULL){ + cbmapput(attrs, "DISPOSITION", -1, pv, ep - pv, TRUE); + do { + ep++; + while(ep[0] == ' '){ + ep++; + } + if(cbstrfwimatch(ep, "filename=")){ + ep += 9; + if(ep[0] == '"') ep++; + pv = ep; + while(ep[0] != '\0' && ep[0] != '"'){ + ep++; + } + cbmapput(attrs, "FILENAME", -1, pv, ep - pv, TRUE); + } else if(cbstrfwimatch(ep, "name=")){ + ep += 5; + if(ep[0] == '"') ep++; + pv = ep; + while(ep[0] != '\0' && ep[0] != '"'){ + ep++; + } + cbmapput(attrs, "NAME", -1, pv, ep - pv, TRUE); + } + } while((ep = strchr(ep, ';')) != NULL); + } else { + cbmapput(attrs, "DISPOSITION", -1, pv, -1, TRUE); + } + } + } + if(sp) *sp = size; + CB_MEMDUP(rv, ptr, size); + return rv; +} + + +/* Split multipart data in MIME into its parts. */ +CBLIST *cbmimeparts(const char *ptr, int size, const char *boundary){ + CBLIST *list; + const char *pv, *ep; + int i, blen; + assert(ptr && boundary); + if(size < 0) size = strlen(ptr); + CB_LISTOPEN(list); + if((blen = strlen(boundary)) < 1) return list; + pv = NULL; + for(i = 0; i < size; i++){ + if(ptr[i] == '-' && ptr[i+1] == '-' && i + 2 + blen < size && + cbstrfwmatch(ptr + i + 2, boundary) && strchr("\t\n\v\f\r ", ptr[i+2+blen])){ + pv = ptr + i + 2 + blen; + if(*pv == '\r') pv++; + if(*pv == '\n') pv++; + size -= pv - ptr; + ptr = pv; + break; + } + } + if(!pv) return list; + for(i = 0; i < size; i++){ + if(ptr[i] == '-' && ptr[i+1] == '-' && i + 2 + blen < size && + cbstrfwmatch(ptr + i + 2, boundary) && strchr("\t\n\v\f\r -", ptr[i+2+blen])){ + ep = ptr + i; + if(ep > ptr && ep[-1] == '\n') ep--; + if(ep > ptr && ep[-1] == '\r') ep--; + if(ep > pv) CB_LISTPUSH(list, pv, ep - pv); + pv = ptr + i + 2 + blen; + if(*pv == '\r') pv++; + if(*pv == '\n') pv++; + } + } + return list; +} + + +/* Encode a string with MIME encoding. */ +char *cbmimeencode(const char *str, const char *encname, int base){ + char *buf, *wp, *enc; + int len; + assert(str && encname); + len = strlen(str); + CB_MALLOC(buf, len * 3 + strlen(encname) + 16); + wp = buf; + wp += sprintf(wp, "=?%s?%c?", encname, base ? 'B' : 'Q'); + enc = base ? cbbaseencode(str, len) : cbquoteencode(str, len); + wp += sprintf(wp, "%s?=", enc); + free(enc); + return buf; +} + + +/* Decode a string encoded with MIME encoding. */ +char *cbmimedecode(const char *str, char *enp){ + char *buf, *wp, *tmp, *dec; + const char *pv, *ep; + int quoted; + assert(str); + if(enp) sprintf(enp, "US-ASCII"); + CB_MALLOC(buf, strlen(str) + 1); + wp = buf; + while(*str != '\0'){ + if(cbstrfwmatch(str, "=?")){ + str += 2; + pv = str; + if(!(ep = strchr(str, '?'))) continue; + if(enp && ep - pv < CB_ENCBUFSIZ){ + memcpy(enp, pv, ep - pv); + enp[ep-pv] = '\0'; + } + pv = ep + 1; + quoted = (*pv == 'Q' || *pv == 'q'); + if(*pv != '\0') pv++; + if(*pv != '\0') pv++; + if(!(ep = strchr(pv, '?'))) continue; + CB_MEMDUP(tmp, pv, ep - pv); + dec = quoted ? cbquotedecode(tmp, NULL) : cbbasedecode(tmp, NULL); + wp += sprintf(wp, "%s", dec); + free(dec); + free(tmp); + str = ep + 1; + if(*str != '\0') str++; + } else { + *(wp++) = *str; + str++; + } + } + *wp = '\0'; + return buf; +} + + +/* Split a string of CSV into rows. */ +CBLIST *cbcsvrows(const char *str){ + CBLIST *list; + const char *pv; + int quoted; + assert(str); + CB_LISTOPEN(list); + pv = str; + quoted = FALSE; + while(TRUE){ + if(*str == '"') quoted = !quoted; + if(!quoted && (*str == '\r' || *str == '\n')){ + CB_LISTPUSH(list, pv, str - pv); + if(str[0] == '\r' && str[1] == '\n') str++; + str++; + pv = str; + } else if(*str == '\0'){ + if(str > pv) CB_LISTPUSH(list, pv, str - pv); + break; + } else { + str++; + } + } + return list; +} + + +/* Split a string of a row of CSV into cells. */ +CBLIST *cbcsvcells(const char *str){ + CBLIST *list, *uelist; + const char *pv; + char *tmp; + int i, quoted; + assert(str); + CB_LISTOPEN(list); + pv = str; + quoted = FALSE; + while(TRUE){ + if(*str == '"') quoted = !quoted; + if(!quoted && *str == ','){ + CB_LISTPUSH(list, pv, str - pv); + str++; + pv = str; + } else if(*str == '\0'){ + CB_LISTPUSH(list, pv, str - pv); + break; + } else { + str++; + } + } + CB_LISTOPEN(uelist); + for(i = 0; i < CB_LISTNUM(list); i++){ + tmp = cbcsvunescape(CB_LISTVAL(list, i)); + CB_LISTPUSH(uelist, tmp, strlen(tmp)); + free(tmp); + } + CB_LISTCLOSE(list); + return uelist; +} + + +/* Escape a string with the meta characters of CSV. */ +char *cbcsvescape(const char *str){ + char *buf, *wp; + int i; + assert(str); + CB_MALLOC(buf, strlen(str) * 2 + 3); + wp = buf; + *(wp++) = '"'; + for(i = 0; str[i] != '\0'; i++){ + if(str[i] == '"') *(wp++) = '"'; + *(wp++) = str[i]; + } + *(wp++) = '"'; + *wp = '\0'; + return buf; +} + + +/* Unescape a string with the escaped meta characters of CSV. */ +char *cbcsvunescape(const char *str){ + char *buf, *wp; + int i, len; + assert(str); + len = strlen(str); + if(str[0] == '"'){ + str++; + len--; + if(str[len-1] == '"') len--; + } + CB_MALLOC(buf, len + 1); + wp = buf; + for(i = 0; i < len; i++){ + if(str[i] == '"'){ + if(str[i+1] == '"') *(wp++) = str[i++]; + } else { + *(wp++) = str[i]; + } + } + *wp = '\0'; + return buf; +} + + +/* Split a string of XML into tags and text sections. */ +CBLIST *cbxmlbreak(const char *str, int cr){ + CBLIST *list; + CBDATUM *datum; + int i, pv, tag; + char *ep; + assert(str); + CB_LISTOPEN(list); + i = 0; + pv = 0; + tag = FALSE; + while(TRUE){ + if(str[i] == '\0'){ + if(i > pv) CB_LISTPUSH(list, str + pv, i - pv); + break; + } else if(!tag && str[i] == '<'){ + if(str[i+1] == '!' && str[i+2] == '-' && str[i+3] == '-'){ + if(i > pv) CB_LISTPUSH(list, str + pv, i - pv); + if((ep = strstr(str + i, "-->")) != NULL){ + if(!cr) CB_LISTPUSH(list, str + i, ep - str - i + 3); + i = ep - str + 2; + pv = i + 1; + } + } else if(str[i+1] == '!' && str[i+2] == '[' && cbstrfwimatch(str + i, " pv) CB_LISTPUSH(list, str + pv, i - pv); + if((ep = strstr(str + i, "]]>")) != NULL){ + i += 9; + CB_DATUMOPEN(datum); + while(str + i < ep){ + if(str[i] == '&'){ + CB_DATUMCAT(datum, "&", 5); + } else if(str[i] == '<'){ + CB_DATUMCAT(datum, "<", 4); + } else if(str[i] == '>'){ + CB_DATUMCAT(datum, ">", 4); + } else { + CB_DATUMCAT(datum, str + i, 1); + } + i++; + } + if(CB_DATUMSIZE(datum) > 0) CB_LISTPUSH(list, CB_DATUMPTR(datum), CB_DATUMSIZE(datum)); + CB_DATUMCLOSE(datum); + i = ep - str + 2; + pv = i + 1; + } + } else { + if(i > pv) CB_LISTPUSH(list, str + pv, i - pv); + tag = TRUE; + pv = i; + } + } else if(tag && str[i] == '>'){ + if(i > pv) CB_LISTPUSH(list, str + pv, i - pv + 1); + tag = FALSE; + pv = i + 1; + } + i++; + } + return list; +} + + +/* Get the map of attributes of a XML tag. */ +CBMAP *cbxmlattrs(const char *str){ + CBMAP *map; + const unsigned char *rp, *key, *val; + char *copy, *raw; + int ksiz, vsiz; + assert(str); + map = cbmapopenex(CB_MAPPBNUM); + rp = (unsigned char *)str; + while(*rp == '<' || *rp == '/' || *rp == '?' || *rp == '!' || *rp == ' '){ + rp++; + } + key = rp; + while(*rp > 0x20 && *rp != '/' && *rp != '>'){ + rp++; + } + cbmapput(map, "", -1, (char *)key, rp - key, FALSE); + while(*rp != '\0'){ + while(*rp != '\0' && (*rp <= 0x20 || *rp == '/' || *rp == '?' || *rp == '>')){ + rp++; + } + key = rp; + while(*rp > 0x20 && *rp != '/' && *rp != '>' && *rp != '='){ + rp++; + } + ksiz = rp - key; + while(*rp != '\0' && (*rp == '=' || *rp <= 0x20)){ + rp++; + } + if(*rp == '"'){ + rp++; + val = rp; + while(*rp != '\0' && *rp != '"'){ + rp++; + } + vsiz = rp - val; + } else if(*rp == '\''){ + rp++; + val = rp; + while(*rp != '\0' && *rp != '\''){ + rp++; + } + vsiz = rp - val; + } else { + val = rp; + while(*rp > 0x20 && *rp != '"' && *rp != '\'' && *rp != '>'){ + rp++; + } + vsiz = rp - val; + } + if(*rp != '\0') rp++; + if(ksiz > 0){ + CB_MEMDUP(copy, (char *)val, vsiz); + raw = cbxmlunescape(copy); + cbmapput(map, (char *)key, ksiz, raw, -1, FALSE); + free(raw); + free(copy); + } + } + return map; +} + + +/* Escape a string with the meta characters of XML. */ +char *cbxmlescape(const char *str){ + CBDATUM *datum; + assert(str); + CB_DATUMOPEN(datum); + while(*str != '\0'){ + switch(*str){ + case '&': + CB_DATUMCAT(datum, "&", 5); + break; + case '<': + CB_DATUMCAT(datum, "<", 4); + break; + case '>': + CB_DATUMCAT(datum, ">", 4); + break; + case '"': + CB_DATUMCAT(datum, """, 6); + break; + case '\'': + CB_DATUMCAT(datum, "'", 6); + break; + default: + CB_DATUMCAT(datum, str, 1); + break; + } + str++; + } + return cbdatumtomalloc(datum, NULL); +} + + +/* Unescape a string with the entity references of XML. */ +char *cbxmlunescape(const char *str){ + CBDATUM *datum; + assert(str); + CB_DATUMOPEN(datum); + while(*str != '\0'){ + if(*str == '&'){ + if(cbstrfwmatch(str, "&")){ + CB_DATUMCAT(datum, "&", 1); + str += 5; + } else if(cbstrfwmatch(str, "<")){ + CB_DATUMCAT(datum, "<", 1); + str += 4; + } else if(cbstrfwmatch(str, ">")){ + CB_DATUMCAT(datum, ">", 1); + str += 4; + } else if(cbstrfwmatch(str, """)){ + CB_DATUMCAT(datum, "\"", 1); + str += 6; + } else if(cbstrfwmatch(str, "'")){ + CB_DATUMCAT(datum, "'", 1); + str += 6; + } else { + CB_DATUMCAT(datum, str, 1); + str++; + } + } else { + CB_DATUMCAT(datum, str, 1); + str++; + } + } + return cbdatumtomalloc(datum, NULL); +} + + +/* Compress a serial object with ZLIB. */ +char *cbdeflate(const char *ptr, int size, int *sp){ + assert(ptr && sp); + if(!_qdbm_deflate) return NULL; + return _qdbm_deflate(ptr, size, sp, _QDBM_ZMZLIB); +} + + +/* Decompress a serial object compressed with ZLIB. */ +char *cbinflate(const char *ptr, int size, int *sp){ + assert(ptr && size >= 0); + if(!_qdbm_inflate) return NULL; + return _qdbm_inflate(ptr, size, sp, _QDBM_ZMZLIB); +} + + +/* Compress a serial object with GZIP. */ +char *cbgzencode(const char *ptr, int size, int *sp){ + assert(ptr && sp); + if(!_qdbm_deflate) return NULL; + return _qdbm_deflate(ptr, size, sp, _QDBM_ZMGZIP); +} + + +/* Decompress a serial object compressed with GZIP. */ +char *cbgzdecode(const char *ptr, int size, int *sp){ + assert(ptr && size >= 0); + if(!_qdbm_inflate) return NULL; + return _qdbm_inflate(ptr, size, sp, _QDBM_ZMGZIP); +} + + +/* Get the CRC32 checksum of a serial object. */ +unsigned int cbgetcrc(const char *ptr, int size){ + assert(ptr); + if(!_qdbm_inflate) return 0; + return _qdbm_getcrc(ptr, size); +} + + +/* Compress a serial object with LZO. */ +char *cblzoencode(const char *ptr, int size, int *sp){ + assert(ptr && sp); + if(!_qdbm_lzoencode) return NULL; + return _qdbm_lzoencode(ptr, size, sp); +} + + +/* Decompress a serial object compressed with LZO. */ +char *cblzodecode(const char *ptr, int size, int *sp){ + assert(ptr && size >= 0); + if(!_qdbm_lzodecode) return NULL; + return _qdbm_lzodecode(ptr, size, sp); +} + + +/* Compress a serial object with BZIP2. */ +char *cbbzencode(const char *ptr, int size, int *sp){ + assert(ptr && sp); + if(!_qdbm_bzencode) return NULL; + return _qdbm_bzencode(ptr, size, sp); +} + + +/* Decompress a serial object compressed with BZIP2. */ +char *cbbzdecode(const char *ptr, int size, int *sp){ + assert(ptr && size >= 0); + if(!_qdbm_bzdecode) return NULL; + return _qdbm_bzdecode(ptr, size, sp); +} + + +/* Convert the character encoding of a string. */ +char *cbiconv(const char *ptr, int size, const char *icode, const char *ocode, int *sp, int *mp){ + char *res; + assert(ptr && icode && ocode); + if(!_qdbm_iconv) return NULL; + if((res = _qdbm_iconv(ptr, size, icode, ocode, sp, mp)) != NULL) return res; + if(!cbstricmp(icode, ocode)){ + if(sp) *sp = size; + if(mp) *mp = 0; + CB_MEMDUP(res, ptr, size < 0 ? strlen(ptr) : size); + return res; + } + return NULL; +} + + +/* Detect the encoding of a string automatically. */ +const char *cbencname(const char *ptr, int size){ + assert(ptr); + if(!_qdbm_encname) return "ISO-8859-1"; + return _qdbm_encname(ptr, size); +} + + +/* Get the jet lag of the local time in seconds. */ +int cbjetlag(void){ + struct tm ts, *tp; + time_t t, gt, lt; + if((t = time(NULL)) < 0) return 0; + if(!(tp = _qdbm_gmtime(&t, &ts))) return 0; + if((gt = mktime(tp)) < 0) return 0; + if(!(tp = _qdbm_localtime(&t, &ts))) return 0; + if((lt = mktime(tp)) < 0) return 0; + return lt - gt; +} + + +/* Get the Gregorian calendar of a time. */ +void cbcalendar(time_t t, int jl, int *yearp, int *monp, int *dayp, + int *hourp, int *minp, int *secp){ + struct tm ts, *tp; + if(t < 0) t = time(NULL); + t += jl; + if(!(tp = _qdbm_gmtime(&t, &ts))) return; + if(yearp) *yearp = tp->tm_year + 1900; + if(monp) *monp = tp->tm_mon + 1; + if(dayp) *dayp = tp->tm_mday; + if(hourp) *hourp = tp->tm_hour; + if(minp) *minp = tp->tm_min; + if(secp) *secp = tp->tm_sec; +} + + +/* Get the day of week of a date. */ +int cbdayofweek(int year, int mon, int day){ + if(mon < 3){ + year--; + mon += 12; + } + return (day + ((8 + (13 * mon)) / 5) + (year + (year / 4) - (year / 100) + (year / 400))) % 7; +} + + +/* Get the string for a date in W3CDTF. */ +char *cbdatestrwww(time_t t, int jl){ + char date[CB_DATEBUFSIZ], tzone[CB_DATEBUFSIZ], *rv; + int year, mon, day, hour, min, sec; + cbcalendar(t, jl, &year, &mon, &day, &hour, &min, &sec); + jl /= 60; + if(jl == 0){ + sprintf(tzone, "Z"); + } else if(jl < 0){ + jl *= -1; + sprintf(tzone, "-%02d:%02d", jl / 60, jl % 60); + } else { + sprintf(tzone, "+%02d:%02d", jl / 60, jl % 60); + } + sprintf(date, "%04d-%02d-%02dT%02d:%02d:%02d%s", year, mon, day, hour, min, sec, tzone); + CB_MEMDUP(rv, date, strlen(date)); + return rv; +} + + +/* Get the string for a date in RFC 1123 format. */ +char *cbdatestrhttp(time_t t, int jl){ + char date[CB_DATEBUFSIZ], *wp, *rv; + int year, mon, day, hour, min, sec; + cbcalendar(t, jl, &year, &mon, &day, &hour, &min, &sec); + jl /= 60; + wp = date; + switch(cbdayofweek(year, mon, day)){ + case 0: wp += sprintf(wp, "Sun, "); break; + case 1: wp += sprintf(wp, "Mon, "); break; + case 2: wp += sprintf(wp, "Tue, "); break; + case 3: wp += sprintf(wp, "Wed, "); break; + case 4: wp += sprintf(wp, "Thu, "); break; + case 5: wp += sprintf(wp, "Fri, "); break; + case 6: wp += sprintf(wp, "Sat, "); break; + } + wp += sprintf(wp, "%02d ", day); + switch(mon){ + case 1: wp += sprintf(wp, "Jan "); break; + case 2: wp += sprintf(wp, "Feb "); break; + case 3: wp += sprintf(wp, "Mar "); break; + case 4: wp += sprintf(wp, "Apr "); break; + case 5: wp += sprintf(wp, "May "); break; + case 6: wp += sprintf(wp, "Jun "); break; + case 7: wp += sprintf(wp, "Jul "); break; + case 8: wp += sprintf(wp, "Aug "); break; + case 9: wp += sprintf(wp, "Sep "); break; + case 10: wp += sprintf(wp, "Oct "); break; + case 11: wp += sprintf(wp, "Nov "); break; + case 12: wp += sprintf(wp, "Dec "); break; + } + wp += sprintf(wp, "%04d %02d:%02d:%02d ", year, hour, min, sec); + if(jl == 0){ + wp += sprintf(wp, "GMT"); + } else if(jl < 0){ + jl *= -1; + wp += sprintf(wp, "-%02d%02d", jl / 60, jl % 60); + } else { + wp += sprintf(wp, "+%02d%02d", jl / 60, jl % 60); + } + CB_MEMDUP(rv, date, strlen(date)); + return rv; +} + + +/* Get the time value of a date string in decimal, W3CDTF, or RFC 1123. */ +time_t cbstrmktime(const char *str){ + const char *crp; + char *pv, *rp; + int len, clen; + time_t t; + struct tm ts; + assert(str); + while(*str > '\0' && *str <= ' '){ + str++; + } + if(*str == '\0') return -1; + if(str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) return (time_t)strtol(str + 2, NULL, 16); + memset(&ts, 0, sizeof(struct tm)); + ts.tm_year = 70; + ts.tm_mon = 0; + ts.tm_mday = 1; + ts.tm_hour = 0; + ts.tm_min = 0; + ts.tm_sec = 0; + ts.tm_isdst = 0; + len = strlen(str); + t = (time_t)strtol(str, &pv, 10); + if(*(signed char *)pv >= '\0' && *pv <= ' '){ + while(*pv > '\0' && *pv <= ' '){ + pv++; + } + if(*pv == '\0') return t; + } + if((pv[0] == 's' || pv[0] == 'S') && ((signed char *)pv)[1] >= '\0' && pv[1] <= ' ') + return t; + if((pv[0] == 'm' || pv[0] == 'M') && ((signed char *)pv)[1] >= '\0' && pv[1] <= ' ') + return t * 60; + if((pv[0] == 'h' || pv[0] == 'H') && ((signed char *)pv)[1] >= '\0' && pv[1] <= ' ') + return t * 60 * 60; + if((pv[0] == 'd' || pv[0] == 'D') && ((signed char *)pv)[1] >= '\0' && pv[1] <= ' ') + return t * 60 * 60 * 24; + if(len > 4 && str[4] == '-'){ + ts.tm_year = atoi(str) - 1900; + if((pv = strchr(str, '-')) != NULL && pv - str == 4){ + rp = pv + 1; + ts.tm_mon = atoi(rp) - 1; + if((pv = strchr(rp, '-')) != NULL && pv - str == 7){ + rp = pv + 1; + ts.tm_mday = atoi(rp); + if((pv = strchr(rp, 'T')) != NULL && pv - str == 10){ + rp = pv + 1; + ts.tm_hour = atoi(rp); + if((pv = strchr(rp, ':')) != NULL && pv - str == 13){ + rp = pv + 1; + ts.tm_min = atoi(rp); + } + if((pv = strchr(rp, ':')) != NULL && pv - str == 16){ + rp = pv + 1; + ts.tm_sec = atoi(rp); + } + if((pv = strchr(rp, '.')) != NULL && pv - str >= 19) rp = pv + 1; + strtol(rp, &pv, 10); + if((*pv == '+' || *pv == '-') && strlen(pv) >= 6 && pv[3] == ':') + ts.tm_sec -= (atoi(pv + 1) * 3600 + atoi(pv + 4) * 60) * (pv[0] == '+' ? 1 : -1); + } + } + } + ts.tm_sec += cbjetlag(); + return mktime(&ts); + } + if(len > 4 && str[4] == '/'){ + ts.tm_year = atoi(str) - 1900; + if((pv = strchr(str, '/')) != NULL && pv - str == 4){ + rp = pv + 1; + ts.tm_mon = atoi(rp) - 1; + if((pv = strchr(rp, '/')) != NULL && pv - str == 7){ + rp = pv + 1; + ts.tm_mday = atoi(rp); + if((pv = strchr(rp, ' ')) != NULL && pv - str == 10){ + rp = pv + 1; + ts.tm_hour = atoi(rp); + if((pv = strchr(rp, ':')) != NULL && pv - str == 13){ + rp = pv + 1; + ts.tm_min = atoi(rp); + } + if((pv = strchr(rp, ':')) != NULL && pv - str == 16){ + rp = pv + 1; + ts.tm_sec = atoi(rp); + } + if((pv = strchr(rp, '.')) != NULL && pv - str >= 19) rp = pv + 1; + strtol(rp, &pv, 10); + if((*pv == '+' || *pv == '-') && strlen(pv) >= 6 && pv[3] == ':') + ts.tm_sec -= (atoi(pv + 1) * 3600 + atoi(pv + 4) * 60) * (pv[0] == '+' ? 1 : -1); + } + } + } + ts.tm_sec += cbjetlag(); + return mktime(&ts); + } + crp = str; + if(len >= 4 && str[3] == ',') crp = str + 4; + while(*crp == ' '){ + crp++; + } + ts.tm_mday = atoi(crp); + while((*crp >= '0' && *crp <= '9') || *crp == ' '){ + crp++; + } + if(cbstrfwimatch(crp, "Jan")){ + ts.tm_mon = 0; + } else if(cbstrfwimatch(crp, "Feb")){ + ts.tm_mon = 1; + } else if(cbstrfwimatch(crp, "Mar")){ + ts.tm_mon = 2; + } else if(cbstrfwimatch(crp, "Apr")){ + ts.tm_mon = 3; + } else if(cbstrfwimatch(crp, "May")){ + ts.tm_mon = 4; + } else if(cbstrfwimatch(crp, "Jun")){ + ts.tm_mon = 5; + } else if(cbstrfwimatch(crp, "Jul")){ + ts.tm_mon = 6; + } else if(cbstrfwimatch(crp, "Aug")){ + ts.tm_mon = 7; + } else if(cbstrfwimatch(crp, "Sep")){ + ts.tm_mon = 8; + } else if(cbstrfwimatch(crp, "Oct")){ + ts.tm_mon = 9; + } else if(cbstrfwimatch(crp, "Nov")){ + ts.tm_mon = 10; + } else if(cbstrfwimatch(crp, "Dec")){ + ts.tm_mon = 11; + } else { + ts.tm_mon = -1; + } + if(ts.tm_mon >= 0) crp += 3; + while(*crp == ' '){ + crp++; + } + ts.tm_year = atoi(crp); + if(ts.tm_year >= 1969) ts.tm_year -= 1900; + while(*crp >= '0' && *crp <= '9'){ + crp++; + } + while(*crp == ' '){ + crp++; + } + if(ts.tm_mday > 0 && ts.tm_mon >= 0 && ts.tm_year >= 0){ + clen = strlen(crp); + if(clen >= 8 && crp[2] == ':' && crp[5] == ':'){ + ts.tm_hour = atoi(crp + 0); + ts.tm_min = atoi(crp + 3); + ts.tm_sec = atoi(crp + 6); + if(clen >= 14 && crp[8] == ' ' && (crp[9] == '+' || crp[9] == '-')){ + ts.tm_sec -= ((crp[10] - '0') * 36000 + (crp[11] - '0') * 3600 + + (crp[12] - '0') * 600 + (crp[13] - '0') * 60) * (crp[9] == '+' ? 1 : -1); + } else if(clen > 9){ + if(!strcmp(crp + 9, "JST")){ + ts.tm_sec -= 9 * 3600; + } else if(!strcmp(crp + 9, "CCT")){ + ts.tm_sec -= 8 * 3600; + } else if(!strcmp(crp + 9, "KST")){ + ts.tm_sec -= 9 * 3600; + } else if(!strcmp(crp + 9, "EDT")){ + ts.tm_sec -= -4 * 3600; + } else if(!strcmp(crp + 9, "EST")){ + ts.tm_sec -= -5 * 3600; + } else if(!strcmp(crp + 9, "CDT")){ + ts.tm_sec -= -5 * 3600; + } else if(!strcmp(crp + 9, "CST")){ + ts.tm_sec -= -6 * 3600; + } else if(!strcmp(crp + 9, "MDT")){ + ts.tm_sec -= -6 * 3600; + } else if(!strcmp(crp + 9, "MST")){ + ts.tm_sec -= -7 * 3600; + } else if(!strcmp(crp + 9, "PDT")){ + ts.tm_sec -= -7 * 3600; + } else if(!strcmp(crp + 9, "PST")){ + ts.tm_sec -= -8 * 3600; + } else if(!strcmp(crp + 9, "HDT")){ + ts.tm_sec -= -9 * 3600; + } else if(!strcmp(crp + 9, "HST")){ + ts.tm_sec -= -10 * 3600; + } + } + } + ts.tm_sec += cbjetlag(); + return mktime(&ts); + } + return -1; +} + + +/* Get user and system processing times. */ +void cbproctime(double *usrp, double *sysp){ + struct tms buf; + times(&buf); + if(usrp) *usrp = (double)buf.tms_utime / sysconf(_SC_CLK_TCK); + if(sysp) *sysp = (double)buf.tms_stime / sysconf(_SC_CLK_TCK); +} + + +/* Ensure that the standard I/O is binary mode. */ +void cbstdiobin(void){ + if(setmode(0, O_BINARY) == -1 || setmode(1, O_BINARY) == -1 || setmode(2, O_BINARY) == -1) + cbmyfatal("setmode failed"); +} + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Show error message on the standard error output and exit. */ +void *cbmyfatal(const char *message){ + char buf[CB_MSGBUFSIZ]; + assert(message); + if(cbfatalfunc){ + cbfatalfunc(message); + } else { + sprintf(buf, "fatal error: %s\n", message); + write(2, buf, strlen(buf)); + } + exit(1); + return NULL; +} + + +/* Create a datum handle from an allocated region. */ +CBDATUM *cbdatumopenbuf(char *ptr, int size){ + CBDATUM *datum; + assert(ptr && size >= 0); + CB_REALLOC(ptr, size + 1); + CB_MALLOC(datum, sizeof(*datum)); + datum->dptr = ptr; + datum->dptr[size] = '\0'; + datum->dsize = size; + datum->asize = size; + return datum; +} + + +/* Set a buffer to a datum handle. */ +void cbdatumsetbuf(CBDATUM *datum, char *ptr, int size){ + assert(datum && ptr && size >= 0); + free(datum->dptr); + CB_REALLOC(ptr, size + 1); + datum->dptr = ptr; + datum->dptr[size] = '\0'; + datum->dsize = size; + datum->asize = size; +} + + +/* Add an allocated element at the end of a list. */ +void cblistpushbuf(CBLIST *list, char *ptr, int size){ + int index; + assert(list && ptr && size >= 0); + index = list->start + list->num; + if(index >= list->anum){ + list->anum *= 2; + CB_REALLOC(list->array, list->anum * sizeof(list->array[0])); + } + list->array[index].dptr = ptr; + list->array[index].dsize = size; + list->num++; +} + + +/* Get a map handle with specifying the number of buckets. */ +CBMAP *cbmapopenex(int bnum){ + CBMAP *map; + int i; + assert(bnum > 0); + CB_MALLOC(map, sizeof(*map)); + CB_MALLOC(map->buckets, sizeof(map->buckets[0]) * bnum); + for(i = 0; i < bnum; i++){ + map->buckets[i] = NULL; + } + map->first = NULL; + map->last = NULL; + map->cur = NULL; + map->bnum = bnum; + map->rnum = 0; + return map; +} + + + +/************************************************************************************************* + * private objects + *************************************************************************************************/ + + +/* Handler to invoke the global garbage collector. */ +static void cbggchandler(void){ + cbggckeeper(NULL, NULL); +} + + +/* Manage resources of the global garbage collector. + `ptr' specifies the pointer to add to the collection. If it is `NULL', all resources are + released. + `func' specifies the pointer to the function to release the resources. */ +static void cbggckeeper(void *ptr, void (*func)(void *)){ + static void **parray = NULL; + static void (**farray)(void *) = NULL; + static int onum = 0; + static int asiz = CB_GCUNIT; + int i; + if(!ptr){ + if(!parray) return; + for(i = onum - 1; i >= 0; i--){ + farray[i](parray[i]); + } + free(parray); + free(farray); + parray = NULL; + farray = NULL; + onum = 0; + asiz = CB_GCUNIT; + return; + } + if(!parray){ + CB_MALLOC(parray, sizeof(void *) * asiz); + CB_MALLOC(farray, sizeof(void *) * asiz); + if(atexit(cbggchandler) != 0) cbmyfatal("gc failed"); + } + if(onum >= asiz){ + asiz *= 2; + CB_REALLOC(parray, sizeof(void *) * asiz); + CB_REALLOC(farray, sizeof(void *) * asiz); + } + parray[onum] = ptr; + farray[onum] = func; + onum++; +} + + +/* Utility function for quick sort. + `bp' specifies the pointer to the pointer to an array. + `nmemb' specifies the number of elements of the array. + `size' specifies the size of each element. + `pswap' specifies the pointer to the swap region for a pivot. + `vswap' specifies the pointer to the swap region for elements. + `compar' specifies the pointer to comparing function. */ +static void cbqsortsub(char *bp, int nmemb, int size, char *pswap, char *vswap, + int(*compar)(const void *, const void *)){ + int top, bottom; + assert(bp && nmemb >= 0 && size > 0 && pswap && vswap && compar); + if(nmemb < 10){ + if(nmemb > 1) cbisort(bp, nmemb, size, compar); + return; + } + top = 0; + bottom = nmemb - 1; + memcpy(pswap, bp + (nmemb / 2) * size, size); + while(top - 1 < bottom){ + if(compar(bp + top * size, pswap) < 0){ + top++; + } else if(compar(bp + bottom * size, pswap) > 0){ + bottom--; + } else { + if(top != bottom){ + memcpy(vswap, bp + top * size, size); + memcpy(bp + top * size, bp + bottom * size, size); + memcpy(bp + bottom * size, vswap, size); + } + top++; + bottom--; + } + } + cbqsortsub(bp, top, size, pswap, vswap, compar); + cbqsortsub(bp + (bottom + 1) * size, nmemb - bottom - 1, size, pswap, vswap, compar); +} + + +/* Compare two list elements. + `a' specifies the pointer to one element. + `b' specifies the pointer to the other element. + The return value is positive if a is big, negative if b is big, else, it is 0. */ +static int cblistelemcmp(const void *a, const void *b){ + int i, size; + CBLISTDATUM *ap, *bp; + char *ao, *bo; + assert(a && b); + ap = (CBLISTDATUM *)a; + bp = (CBLISTDATUM *)b; + ao = ap->dptr; + bo = bp->dptr; + size = ap->dsize < bp->dsize ? ap->dsize : bp->dsize; + for(i = 0; i < size; i++){ + if(ao[i] > bo[i]) return 1; + if(ao[i] < bo[i]) return -1; + } + return ap->dsize - bp->dsize; +} + + +/* Compare two keys. + `abuf' specifies the pointer to the region of the former. + `asiz' specifies the size of the region. + `bbuf' specifies the pointer to the region of the latter. + `bsiz' specifies the size of the region. + The return value is 0 if two equals, positive if the formar is big, else, negative. */ +static int cbkeycmp(const char *abuf, int asiz, const char *bbuf, int bsiz){ + assert(abuf && asiz >= 0 && bbuf && bsiz >= 0); + if(asiz > bsiz) return 1; + if(asiz < bsiz) return -1; + return memcmp(abuf, bbuf, asiz); +} + + + +/* END OF FILE */ diff --git a/qdbm/cabin.h b/qdbm/cabin.h new file mode 100644 index 00000000..230ec150 --- /dev/null +++ b/qdbm/cabin.h @@ -0,0 +1,1544 @@ +/************************************************************************************************* + * The utitlity API of QDBM + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#ifndef _CABIN_H /* duplication check */ +#define _CABIN_H + +#if defined(__cplusplus) /* export for C++ */ +extern "C" { +#endif + + +#include +#include + + +#if defined(_MSC_VER) && !defined(QDBM_INTERNAL) && !defined(QDBM_STATIC) +#define MYEXTERN extern __declspec(dllimport) +#else +#define MYEXTERN extern +#endif + + + +/************************************************************************************************* + * API + *************************************************************************************************/ + + +#define CB_DATUMUNIT 12 /* allocation unit size of a datum handle */ +#define CB_LISTUNIT 64 /* allocation unit number of a list handle */ +#define CB_MAPBNUM 4093 /* bucket size of a map handle */ + +typedef struct { /* type of structure for a basic datum */ + char *dptr; /* pointer to the region */ + int dsize; /* size of the region */ + int asize; /* size of the allocated region */ +} CBDATUM; + +typedef struct { /* type of structure for an element of a list */ + char *dptr; /* pointer to the region */ + int dsize; /* size of the effective region */ +} CBLISTDATUM; + +typedef struct { /* type of structure for a list */ + CBLISTDATUM *array; /* array of data */ + int anum; /* number of the elements of the array */ + int start; /* start index of using elements */ + int num; /* number of using elements */ +} CBLIST; + +typedef struct _CBMAPDATUM { /* type of structure for an element of a map */ + int ksiz; /* size of the region of the key */ + int vsiz; /* size of the region of the value */ + int hash; /* second hash value */ + struct _CBMAPDATUM *left; /* pointer to the left child */ + struct _CBMAPDATUM *right; /* pointer to the right child */ + struct _CBMAPDATUM *prev; /* pointer to the previous element */ + struct _CBMAPDATUM *next; /* pointer to the next element */ +} CBMAPDATUM; + +typedef struct { /* type of structure for a map */ + CBMAPDATUM **buckets; /* bucket array */ + CBMAPDATUM *first; /* pointer to the first element */ + CBMAPDATUM *last; /* pointer to the last element */ + CBMAPDATUM *cur; /* pointer to the current element */ + int bnum; /* number of buckets */ + int rnum; /* number of records */ +} CBMAP; + +typedef struct { /* type of structure for a heap */ + char *base; /* base pointer */ + char *swap; /* region for swapping */ + int size; /* size of each record */ + int num; /* currnet number of records */ + int max; /* maximum number of records */ + int(*compar)(const void *, const void *); /* comparing function */ +} CBHEAP; + + +/* Call back function for handling a fatal error. + The argument specifies the error message. The initial value of this variable is `NULL'. + If the value is `NULL', the default function is called when a fatal error occurs. A fatal + error occurs when memory allocation is failed. */ +MYEXTERN void (*cbfatalfunc)(const char *); + + +/* Allocate a region on memory. + `size' specifies the size of the region. + The return value is the pointer to the allocated region. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +void *cbmalloc(size_t size); + + +/* Re-allocate a region on memory. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. + The return value is the pointer to the re-allocated region. + Because the region of the return value is allocated with the `realloc' call, it should be + released with the `free' call if it is no longer in use. */ +void *cbrealloc(void *ptr, size_t size); + + +/* Duplicate a region on memory. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + The return value is the pointer to the allocated region of the duplicate. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if + it is no longer in use. */ +char *cbmemdup(const char *ptr, int size); + + +/* Free a region on memory. + `ptr' specifies the pointer to a region. If it is `NULL', this function has no effect. + Although this function is just a wrapper of `free' call, this is useful in applications using + another package of the `malloc' series. */ +void cbfree(void *ptr); + + +/* Register the pointer or handle of an object to the global garbage collector. + `ptr' specifies the pointer or handle of an object. + `func' specifies the pointer to a function to release resources of the object. Its argument + is the pointer or handle of the object to release. + This function assures that resources of an object are released when the process exits + normally by returning from the `main' function or calling the `exit' function. */ +void cbglobalgc(void *ptr, void (*func)(void *)); + + +/* Exercise the global garbage collector explicitly. + Note that you should not use objects registered to the global garbage collector any longer + after calling this function. Because the global garbage collecter is initialized and you + can register new objects into it. */ +void cbggcsweep(void); + + +/* Check availability of allocation of the virtual memory. + `size' specifies the size of region to be allocated newly. + The return value is true if allocation should be success, or false if not. */ +int cbvmemavail(size_t size); + + +/* Sort an array using insert sort. + `base' spacifies the pointer to an array. + `nmemb' specifies the number of elements of the array. + `size' specifies the size of each element. + `compar' specifies the pointer to comparing function. The two arguments specify the pointers + of elements. The comparing function should returns positive if the former is big, negative + if the latter is big, 0 if both are equal. + Insert sort is useful only if most elements have been sorted already. */ +void cbisort(void *base, int nmemb, int size, int(*compar)(const void *, const void *)); + + +/* Sort an array using shell sort. + `base' spacifies the pointer to an array. + `nmemb' specifies the number of elements of the array. + `size' specifies the size of each element. + `compar' specifies the pointer to comparing function. The two arguments specify the pointers + of elements. The comparing function should returns positive if the former is big, negative + if the latter is big, 0 if both are equal. + If most elements have been sorted, shell sort may be faster than heap sort or quick sort. */ +void cbssort(void *base, int nmemb, int size, int(*compar)(const void *, const void *)); + + +/* Sort an array using heap sort. + `base' spacifies the pointer to an array. + `nmemb' specifies the number of elements of the array. + `size' specifies the size of each element. + `compar' specifies the pointer to comparing function. The two arguments specify the pointers + of elements. The comparing function should returns positive if the former is big, negative + if the latter is big, 0 if both are equal. + Although heap sort is robust against bias of input, quick sort is faster in most cases. */ +void cbhsort(void *base, int nmemb, int size, int(*compar)(const void *, const void *)); + + +/* Sort an array using quick sort. + `base' spacifies the pointer to an array. + `nmemb' specifies the number of elements of the array. + `size' specifies the size of each element. + `compar' specifies the pointer to comparing function. The two arguments specify the pointers + of elements. The comparing function should returns positive if the former is big, negative + if the latter is big, 0 if both are equal. + Being sensitive to bias of input, quick sort is the fastest sorting algorithm. */ +void cbqsort(void *base, int nmemb, int size, int(*compar)(const void *, const void *)); + + +/* Compare two strings with case insensitive evaluation. + `astr' specifies the pointer of one string. + `astr' specifies the pointer of the other string. + The return value is positive if the former is big, negative if the latter is big, 0 if both + are equivalent. + Upper cases and lower cases of alphabets in ASCII code are not distinguished. */ +int cbstricmp(const char *astr, const char *bstr); + + +/* Check whether a string begins with a key. + `str' specifies the pointer of a target string. + `key' specifies the pointer of a forward matching key string. + The return value is true if the target string begins with the key, else, it is false. */ +int cbstrfwmatch(const char *str, const char *key); + + +/* Check whether a string begins with a key, with case insensitive evaluation. + `str' specifies the pointer of a target string. + `key' specifies the pointer of a forward matching key string. + The return value is true if the target string begins with the key, else, it is false. + Upper cases and lower cases of alphabets in ASCII code are not distinguished. */ +int cbstrfwimatch(const char *str, const char *key); + + +/* Check whether a string ends with a key. + `str' specifies the pointer of a target string. + `key' specifies the pointer of a backward matching key string. + The return value is true if the target string ends with the key, else, it is false. */ +int cbstrbwmatch(const char *str, const char *key); + + +/* Check whether a string ends with a key, with case insensitive evaluation. + `str' specifies the pointer of a target string. + `key' specifies the pointer of a backward matching key string. + The return value is true if the target string ends with the key, else, it is false. + Upper cases and lower cases of alphabets in ASCII code are not distinguished. */ +int cbstrbwimatch(const char *str, const char *key); + + +/* Locate a substring in a string using KMP method. + `haystack' specifies the pointer of a target string. + `needle' specifies the pointer of a substring to be found. + The return value is the pointer to the beginning of the substring or `NULL' if the substring + is not found. + In most cases, `strstr' as a built-in function of the compiler is faster than this function. */ +char *cbstrstrkmp(const char *haystack, const char *needle); + + +/* Locate a substring in a string using BM method. + `haystack' specifies the pointer of a target string. + `needle' specifies the pointer of a substring to be found. + The return value is the pointer to the beginning of the substring or `NULL' if the substring + is not found. + In most cases, `strstr' as a built-in function of the compiler is faster than this function. */ +char *cbstrstrbm(const char *haystack, const char *needle); + + +/* Convert the letters of a string to upper case. + `str' specifies the pointer of a string to convert. + The return value is the pointer to the string. */ +char *cbstrtoupper(char *str); + + +/* Convert the letters of a string to lower case. + `str' specifies the pointer of a string to convert. + The return value is the pointer to the string. */ +char *cbstrtolower(char *str); + + +/* Cut space characters at head or tail of a string. + `str' specifies the pointer of a string to convert. + The return value is the pointer to the string. */ +char *cbstrtrim(char *str); + + +/* Squeeze space characters in a string and trim it. + `str' specifies the pointer of a string to convert. + The return value is the pointer to the string. */ +char *cbstrsqzspc(char *str); + + +/* Count the number of characters in a string of UTF-8. + `str' specifies the pointer of a string of UTF-8. + The return value is the number of characters in the string. */ +int cbstrcountutf(const char *str); + + +/* Cut a string of UTF-8 at the specified number of characters. + `str' specifies the pointer of a string of UTF-8. + `num' specifies the number of characters to be kept. + The return value is the pointer to the string. */ +char *cbstrcututf(char *str, int num); + + +/* Get a datum handle. + `ptr' specifies the pointer to the region of the initial content. If it is `NULL', an empty + datum is created. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + The return value is a datum handle. */ +CBDATUM *cbdatumopen(const char *ptr, int size); + + +/* Copy a datum. + `datum' specifies a datum handle. + The return value is a new datum handle. */ +CBDATUM *cbdatumdup(const CBDATUM *datum); + + +/* Free a datum handle. + `datum' specifies a datum handle. + Because the region of a closed handle is released, it becomes impossible to use the handle. */ +void cbdatumclose(CBDATUM *datum); + + +/* Concatenate a datum and a region. + `datum' specifies a datum handle. + `ptr' specifies the pointer to the region to be appended. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. */ +void cbdatumcat(CBDATUM *datum, const char *ptr, int size); + + +/* Get the pointer of the region of a datum. + `datum' specifies a datum handle. + The return value is the pointer of the region of a datum. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. */ +const char *cbdatumptr(const CBDATUM *datum); + + +/* Get the size of the region of a datum. + `datum' specifies a datum handle. + The return value is the size of the region of a datum. */ +int cbdatumsize(const CBDATUM *datum); + + +/* Change the size of the region of a datum. + `datum' specifies a datum handle. + `size' specifies the new size of the region. + If the new size is bigger than the one of old, the surplus region is filled with zero codes. */ +void cbdatumsetsize(CBDATUM *datum, int size); + + +/* Perform formatted output into a datum. + `format' specifies a printf-like format string. + The conversion character `%' can be used with such flag characters as `s', `d', `o', `u', + `x', `X', `c', `e', `E', `f', `g', `G', `@', `?', `:', `%'. `@' works as with `s' but escapes + meta characters of XML. `?' works as with `s' but escapes meta characters of URL. `:' works + as with `s' but performs MIME encoding as UTF-8. The other conversion character work as with + each original. */ +void cbdatumprintf(CBDATUM *datum, const char *format, ...); + + +/* Convert a datum to an allocated region. + `datum' specifies a datum handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer to the region of the datum. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. Because the region of the original datam is released, it should not be + released again. */ +char *cbdatumtomalloc(CBDATUM *datum, int *sp); + + +/* Get a list handle. + The return value is a list handle. */ +CBLIST *cblistopen(void); + + +/* Copy a list. + `list' specifies a list handle. + The return value is a new list handle. */ +CBLIST *cblistdup(const CBLIST *list); + + +/* Close a list handle. + `list' specifies a list handle. + Because the region of a closed handle is released, it becomes impossible to use the handle. */ +void cblistclose(CBLIST *list); + + +/* Get the number of elements of a list. + `list' specifies a list handle. + The return value is the number of elements of the list. */ +int cblistnum(const CBLIST *list); + + +/* Get the pointer to the region of an element of a list. + `list' specifies a list handle. + `index' specifies the index of an element. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer to the region of the value. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. If `index' is equal to or more than + the number of elements, the return value is `NULL'. */ +const char *cblistval(const CBLIST *list, int index, int *sp); + + +/* Add an element at the end of a list. + `list' specifies a list handle. + `ptr' specifies the pointer to the region of an element. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. */ +void cblistpush(CBLIST *list, const char *ptr, int size); + + +/* Remove an element of the end of a list. + `list' specifies a list handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer to the region of the value. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. If the list is empty, the return value is `NULL'. */ +char *cblistpop(CBLIST *list, int *sp); + + +/* Add an element at the top of a list. + `list' specifies a list handle. + `ptr' specifies the pointer to the region of an element. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. */ +void cblistunshift(CBLIST *list, const char *ptr, int size); + + +/* Remove an element of the top of a list. + `list' specifies a list handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer to the region of the value. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. If the list is empty, the return value is `NULL'. */ +char *cblistshift(CBLIST *list, int *sp); + + +/* Add an element at the specified location of a list. + `list' specifies a list handle. + `index' specifies the index of an element. + `ptr' specifies the pointer to the region of the element. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. */ +void cblistinsert(CBLIST *list, int index, const char *ptr, int size); + + +/* Remove an element at the specified location of a list. + `list' specifies a list handle. + `index' specifies the index of an element. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer to the region of the value. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. If `index' is equal to or more than the number of elements, no element + is removed and the return value is `NULL'. */ +char *cblistremove(CBLIST *list, int index, int *sp); + + +/* Overwrite an element at the specified location of a list. + `list' specifies a list handle. + `index' specifies the index of an element. + `ptr' specifies the pointer to the region of the new content. + `size' specifies the size of the new content. If it is negative, the size is assigned with + `strlen(ptr)'. + If `index' is equal to or more than the number of elements, this function has no effect. */ +void cblistover(CBLIST *list, int index, const char *ptr, int size); + + +/* Sort elements of a list in lexical order. + `list' specifies a list handle. + Quick sort is used for sorting. */ +void cblistsort(CBLIST *list); + + +/* Search a list for an element using liner search. + `list' specifies a list handle. + `ptr' specifies the pointer to the region of a key. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + The return value is the index of a corresponding element or -1 if there is no corresponding + element. If two or more elements corresponds, the former returns. */ +int cblistlsearch(const CBLIST *list, const char *ptr, int size); + + +/* Search a list for an element using binary search. + `list' specifies a list handle. It should be sorted in lexical order. + `ptr' specifies the pointer to the region of a key. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + The return value is the index of a corresponding element or -1 if there is no corresponding + element. If two or more elements corresponds, which returns is not defined. */ +int cblistbsearch(const CBLIST *list, const char *ptr, int size); + + +/* Serialize a list into a byte array. + `list' specifies a list handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. + The return value is the pointer to the region of the result serial region. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cblistdump(const CBLIST *list, int *sp); + + +/* Redintegrate a serialized list. + `ptr' specifies the pointer to a byte array. + `size' specifies the size of the region. + The return value is a new list handle. */ +CBLIST *cblistload(const char *ptr, int size); + + +/* Get a map handle. + The return value is a map handle. */ +CBMAP *cbmapopen(void); + + +/* Copy a map. + `map' specifies a map handle. + The return value is a new map handle. + The iterator of the source map is initialized. */ +CBMAP *cbmapdup(CBMAP *map); + + +/* Close a map handle. + `map' specifies a map handle. + Because the region of a closed handle is released, it becomes impossible to use the handle. */ +void cbmapclose(CBMAP *map); + + +/* Store a record into a map. + `map' specifies a map handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region of the value. If it is negative, the size is + assigned with `strlen(vbuf)'. + `over' specifies whether the value of the duplicated record is overwritten or not. + If `over' is false and the key is duplicated, the return value is false, else, it is true. */ +int cbmapput(CBMAP *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int over); + + +/* Concatenate a value at the end of the value of the existing record. + `map' specifies a map handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region of the value. If it is negative, the size is + assigned with `strlen(vbuf)'. + If there is no corresponding record, a new record is created. */ +void cbmapputcat(CBMAP *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz); + + +/* Delete a record in a map. + `map' specifies a map handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is true. False is returned when no record corresponds to + the specified key. */ +int cbmapout(CBMAP *map, const char *kbuf, int ksiz); + + +/* Retrieve a record in a map. + `map' specifies a map handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record. `NULL' is returned when no record corresponds. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. */ +const char *cbmapget(const CBMAP *map, const char *kbuf, int ksiz, int *sp); + + +/* Move a record to the edge of a map. + `map' specifies a map handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `head' specifies the destination which is head if it is true or tail if else. + If successful, the return value is true. False is returned when no record corresponds to + the specified key. */ +int cbmapmove(CBMAP *map, const char *kbuf, int ksiz, int head); + + +/* Initialize the iterator of a map. + `map' specifies a map handle. + The iterator is used in order to access the key of every record stored in a map. */ +void cbmapiterinit(CBMAP *map); + + +/* Get the next key of the iterator of a map. + `map' specifies a map handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the next key, else, it is + `NULL'. `NULL' is returned when no record is to be get out of the iterator. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. The order of iteration is assured + to be the same of the one of storing. */ +const char *cbmapiternext(CBMAP *map, int *sp); + + +/* Get the value binded to the key fetched from the iterator of a map. + `kbuf' specifies the pointer to the region of a iteration key. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer to the region of the value of the corresponding record. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. */ +const char *cbmapiterval(const char *kbuf, int *sp); + + +/* Get the number of the records stored in a map. + `map' specifies a map handle. + The return value is the number of the records stored in the map. */ +int cbmaprnum(const CBMAP *map); + + +/* Get the list handle contains all keys in a map. + `map' specifies a map handle. + The return value is the list handle contains all keys in the map. + Because the handle of the return value is opened with the function `cblistopen', it should + be closed with the function `cblistclose' if it is no longer in use. */ +CBLIST *cbmapkeys(CBMAP *map); + + +/* Get the list handle contains all values in a map. + `map' specifies a map handle. + The return value is the list handle contains all values in the map. + Because the handle of the return value is opened with the function `cblistopen', it should + be closed with the function `cblistclose' if it is no longer in use. */ +CBLIST *cbmapvals(CBMAP *map); + + +/* Serialize a map into a byte array. + `map' specifies a map handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. + The return value is the pointer to the region of the result serial region. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cbmapdump(CBMAP *map, int *sp); + + +/* Redintegrate a serialized map. + `ptr' specifies the pointer to a byte array. + `size' specifies the size of the region. + The return value is a new map handle. */ +CBMAP *cbmapload(const char *ptr, int size); + + +/* Extract a record from a serialized map. + `ptr' specifies the pointer to a byte array. + `size' specifies the size of the region. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record. `NULL' is returned when no record corresponds. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. */ +char *cbmaploadone(const char *ptr, int size, const char *kbuf, int ksiz, int *sp); + + +/* Get a heap handle. + `size' specifies the size of each record. + `max' specifies the maximum number of records in the heap. + `compar' specifies the pointer to comparing function. The two arguments specify the pointers + of records. The comparing function should returns positive if the former is big, negative + if the latter is big, 0 if both are equal. + The return value is a heap handle. */ +CBHEAP *cbheapopen(int size, int max, int(*compar)(const void *, const void *)); + + +/* Copy a heap. + `heap' specifies a heap handle. + The return value is a new heap handle. */ +CBHEAP *cbheapdup(CBHEAP *heap); + + +/* Close a heap handle. + `heap' specifies a heap handle. + Because the region of a closed handle is released, it becomes impossible to use the handle. */ +void cbheapclose(CBHEAP *heap); + + +/* Get the number of the records stored in a heap. + `heap' specifies a heap handle. + The return value is the number of the records stored in the heap. */ +int cbheapnum(CBHEAP *heap); + + +/* Insert a record into a heap. + `heap' specifies a heap handle. + `ptr' specifies the pointer to the region of a record. + The return value is true if the record is added, else false. + If the new record is bigger than the biggest existing regord, the new record is not added. + If the new record is added and the number of records exceeds the maximum number, the biggest + existing record is removed. */ +int cbheapinsert(CBHEAP *heap, const void *ptr); + + +/* Get the pointer to the region of a record in a heap. + `heap' specifies a heap handle. + `index' specifies the index of a record. + The return value is the pointer to the region of the record. + If `index' is equal to or more than the number of records, the return value is `NULL'. Note + that records are organized by the nagative order the comparing function. */ +const void *cbheapval(CBHEAP *heap, int index); + + +/* Convert a heap to an allocated region. + `heap' specifies a heap handle. + `np' specifies the pointer to a variable to which the number of records of the return value + is assigned. If it is `NULL', it is not used. + The return value is the pointer to the region of the heap. Records are sorted. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. Because the region of the original + heap is released, it should not be released again. */ +void *cbheaptomalloc(CBHEAP *heap, int *np); + + +/* Allocate a formatted string on memory. + `format' specifies a printf-like format string. The conversion character `%' can be used + with such flag characters as `d', `o', `u', `x', `X', `e', `E', `f', `g', `G', `c', `s', and + `%'. Specifiers of the field length and the precision can be put between the conversion + characters and the flag characters. The specifiers consist of decimal characters, `.', `+', + `-', and the space character. + The other arguments are used according to the format string. + The return value is the pointer to the allocated region of the result string. Because the + region of the return value is allocated with the `malloc' call, it should be released with + the `free' call if it is no longer in use. */ +char *cbsprintf(const char *format, ...); + + +/* Replace some patterns in a string. + `str' specifies the pointer to a source string. + `pairs' specifies the handle of a map composed of pairs of replacement. The key of each pair + specifies a pattern before replacement and its value specifies the pattern after replacement. + The return value is the pointer to the allocated region of the result string. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cbreplace(const char *str, CBMAP *pairs); + + +/* Make a list by splitting a serial datum. + `ptr' specifies the pointer to the region of the source content. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + `delim' specifies a string containing delimiting characters. If it is `NULL', zero code is + used as a delimiter. + The return value is a list handle. + If two delimiters are successive, it is assumed that an empty element is between the two. + Because the handle of the return value is opened with the function `cblistopen', it should + be closed with the function `cblistclose'. */ +CBLIST *cbsplit(const char *ptr, int size, const char *delim); + + +/* Read whole data of a file. + `name' specifies the name of a file. If it is `NULL', the standard input is specified. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer to the allocated region of the read data. Because an + additional zero code is appended at the end of the region of the return value, the return + value can be treated as a character string. Because the region of the return value is + allocated with the `malloc' call, it should be released with the `free' call if it is no + longer in use. */ +char *cbreadfile(const char *name, int *sp); + + +/* Write a serial datum into a file. + `name specifies the name of a file. If it is `NULL', the standard output is specified. + `ptr' specifies the pointer to the region of the source content. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + If successful, the return value is true, else, it is false. + If the file exists, it is overwritten. Else, a new file is created. */ +int cbwritefile(const char *name, const char *ptr, int size); + + +/* Read every line of a file. + `name' specifies the name of a file. If it is `NULL', the standard input is specified. + The return value is a list handle of the lines if successful, else it is NULL. Line + separators are cut out. Because the handle of the return value is opened with the function + `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use. */ +CBLIST *cbreadlines(const char *name); + + +/* Read names of files in a directory. + `name' specifies the name of a directory. + The return value is a list handle of names if successful, else it is NULL. + Because the handle of the return value is opened with the function `cblistopen', it should + be closed with the function `cblistclose' if it is no longer in use. */ +CBLIST *cbdirlist(const char *name); + + +/* Get the status of a file or a directory. + `name' specifies the name of a file or a directory. + `dirp' specifies the pointer to a variable to which whether the file is a directory is + assigned. If it is `NULL', it is not used. + `sizep' specifies the pointer to a variable to which the size of the file is assigned. If it + is `NULL', it is not used. + `mtimep' specifies the pointer to a variable to which the last modified time of the file is + assigned. If it is `NULL', it is not used. + If successful, the return value is true, else, false. False is returned when the file does + not exist or the permission is denied. */ +int cbfilestat(const char *name, int *isdirp, int *sizep, time_t *mtimep); + + +/* Remove a file or a directory and its sub ones recursively. + `name' specifies the name of a file or a directory. + If successful, the return value is true, else, false. False is returned when the file does + not exist or the permission is denied. */ +int cbremove(const char *name); + + +/* Break up a URL into elements. + `str' specifies the pointer to a string of URL. + The return value is a map handle. Each key of the map is the name of an element. The key + "self" specifies the URL itself. The key "scheme" specifies the scheme. The key "host" + specifies the host of the server. The key "port" specifies the port number of the server. + The key "authority" specifies the authority information. The key "path" specifies the path + of the resource. The key "file" specifies the file name without the directory section. The + key "query" specifies the query string. The key "fragment" specifies the fragment string. + Supported schema are HTTP, HTTPS, FTP, and FILE. Absolute URL and relative URL are supported. + Because the handle of the return value is opened with the function `cbmapopen', it should + be closed with the function `cbmapclose' if it is no longer in use. */ +CBMAP *cburlbreak(const char *str); + + +/* Resolve a relative URL with another absolute URL. + `base' specifies an absolute URL of a base location. + `target' specifies a URL to be resolved. + The return value is a resolved URL. If the target URL is relative, a new URL of relative + location from the base location is returned. Else, a copy of the target URL is returned. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cburlresolve(const char *base, const char *target); + + +/* Encode a serial object with URL encoding. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + The return value is the pointer to the result string. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cburlencode(const char *ptr, int size); + + +/* Decode a string encoded with URL encoding. + `str' specifies the pointer to an encoded string. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer to the region of the result. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if + it is no longer in use. */ +char *cburldecode(const char *str, int *sp); + + +/* Encode a serial object with Base64 encoding. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + The return value is the pointer to the result string. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cbbaseencode(const char *ptr, int size); + + +/* Decode a string encoded with Base64 encoding. + `str' specifies the pointer to an encoded string. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer to the region of the result. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if + it is no longer in use. */ +char *cbbasedecode(const char *str, int *sp); + + +/* Encode a serial object with quoted-printable encoding. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + The return value is the pointer to the result string. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cbquoteencode(const char *ptr, int size); + + +/* Decode a string encoded with quoted-printable encoding. + `str' specifies the pointer to an encoded string. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer to the region of the result. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if + it is no longer in use. */ +char *cbquotedecode(const char *str, int *sp); + + +/* Split a string of MIME into headers and the body. + `ptr' specifies the pointer to the region of MIME data. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + `attrs' specifies a map handle to store attributes. If it is `NULL', it is not used. Each + key of the map is an attribute name uncapitalized. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + The return value is the pointer of the body data. + If the content type is defined, the attribute map has the key "TYPE" specifying the type. If + the character encoding is defined, the key "CHARSET" specifies the encoding name. If the + boundary string of multipart is defined, the key "BOUNDARY" specifies the string. If the + content disposition is defined, the key "DISPOSITION" specifies the direction. If the file + name is defined, the key "FILENAME" specifies the name. If the attribute name is defined, + the key "NAME" specifies the name. Because the region of the return value is allocated with + the `malloc' call, it should be released with the `free' call if it is no longer in use. */ +char *cbmimebreak(const char *ptr, int size, CBMAP *attrs, int *sp); + + +/* Split multipart data of MIME into its parts. + `ptr' specifies the pointer to the region of multipart data of MIME. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + `boundary' specifies the pointer to the region of the boundary string. + The return value is a list handle. Each element of the list is the string of a part. + Because the handle of the return value is opened with the function `cblistopen', it should + be closed with the function `cblistclose' if it is no longer in use. */ +CBLIST *cbmimeparts(const char *ptr, int size, const char *boundary); + + +/* Encode a string with MIME encoding. + `str' specifies the pointer to a string. + `encname' specifies a string of the name of the character encoding. + The return value is the pointer to the result string. + `base' specifies whether to use Base64 encoding. If it is false, quoted-printable is used. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cbmimeencode(const char *str, const char *encname, int base); + + +/* Decode a string encoded with MIME encoding. + `str' specifies the pointer to an encoded string. + `enp' specifies the pointer to a region into which the name of encoding is written. If it is + `NULL', it is not used. The size of the buffer should be equal to or more than 32 bytes. + The return value is the pointer to the result string. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cbmimedecode(const char *str, char *enp); + + +/* Split a string of CSV into rows. + `str' specifies the pointer to the region of an CSV string. + The return value is a list handle. Each element of the list is a string of a row. + Because the handle of the return value is opened with the function `cblistopen', it should + be closed with the function `cblistclose' if it is no longer in use. The character encoding + of the input string should be US-ASCII, UTF-8, ISO-8859-*, EUC-*, or Shift_JIS. Being + compatible with MS-Excel, these functions for CSV can handle cells including such meta + characters as comma, between double quotation marks. */ +CBLIST *cbcsvrows(const char *str); + + +/* Split the string of a row of CSV into cells. + `str' specifies the pointer to the region of a row of CSV. + The return value is a list handle. Each element of the list is the unescaped string of a + cell of the row. + Because the handle of the return value is opened with the function `cblistopen', it should + be closed with the function `cblistclose' if it is no longer in use. */ +CBLIST *cbcsvcells(const char *str); + + +/* Escape a string with the meta characters of CSV. + `str' specifies the pointer to the region of a string. + The return value is the pointer to the escaped string sanitized of meta characters. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cbcsvescape(const char *str); + + +/* Unescape a string with the escaped meta characters of CSV. + `str' specifies the pointer to the region of a string with meta characters. + The return value is the pointer to the unescaped string. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cbcsvunescape(const char *str); + + +/* Split a string of XML into tags and text sections. + `str' specifies the pointer to the region of an XML string. + `cr' specifies whether to remove comments. + The return value is a list handle. Each element of the list is the string of a tag or a + text section. + Because the handle of the return value is opened with the function `cblistopen', it should + be closed with the function `cblistclose' if it is no longer in use. The character encoding + of the input string should be US-ASCII, UTF-8, ISO-8859-*, EUC-*, or Shift_JIS. Because + these functions for XML are not XML parser with validation check, it can handle also HTML + and SGML. */ +CBLIST *cbxmlbreak(const char *str, int cr); + + +/* Get the map of attributes of an XML tag. + `str' specifies the pointer to the region of a tag string. + The return value is a map handle. Each key of the map is the name of an attribute. Each + value is unescaped. You can get the name of the tag with the key of an empty string. + Because the handle of the return value is opened with the function `cbmapopen', it should + be closed with the function `cbmapclose' if it is no longer in use. */ +CBMAP *cbxmlattrs(const char *str); + + +/* Escape a string with the meta characters of XML. + `str' specifies the pointer to the region of a string. + The return value is the pointer to the escaped string sanitized of meta characters. + This function converts only `&', `<', `>', and `"'. Because the region of the return value + is allocated with the `malloc' call, it should be released with the `free' call if it is no + longer in use. */ +char *cbxmlescape(const char *str); + + +/* Unescape a string with the entity references of XML. + `str' specifies the pointer to the region of a string with meta characters. + The return value is the pointer to the unescaped string. + This function restores only `&', `<', `>', and `"'. Because the region of the + return value is allocated with the `malloc' call, it should be released with the `free' call + if it is no longer in use. */ +char *cbxmlunescape(const char *str); + + +/* Compress a serial object with ZLIB. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. + If successful, the return value is the pointer to the result object, else, it is `NULL'. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. This function is available only if + QDBM was built with ZLIB enabled. */ +char *cbdeflate(const char *ptr, int size, int *sp); + + +/* Decompress a serial object compressed with ZLIB. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the result object, else, it is `NULL'. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. This function is available only if QDBM was built with ZLIB enabled. */ +char *cbinflate(const char *ptr, int size, int *sp); + + +/* Compress a serial object with GZIP. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. + If successful, the return value is the pointer to the result object, else, it is `NULL'. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. This function is available only if + QDBM was built with ZLIB enabled. */ +char *cbgzencode(const char *ptr, int size, int *sp); + + +/* Decompress a serial object compressed with GZIP. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the result object, else, it is `NULL'. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. This function is available only if QDBM was built with ZLIB enabled. */ +char *cbgzdecode(const char *ptr, int size, int *sp); + + +/* Get the CRC32 checksum of a serial object. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + The return value is the CRC32 checksum of the object. + This function is available only if QDBM was built with ZLIB enabled. */ +unsigned int cbgetcrc(const char *ptr, int size); + + +/* Compress a serial object with LZO. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. + If successful, the return value is the pointer to the result object, else, it is `NULL'. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. This function is available only if + QDBM was built with LZO enabled. */ +char *cblzoencode(const char *ptr, int size, int *sp); + + +/* Decompress a serial object compressed with LZO. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the result object, else, it is `NULL'. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. This function is available only if QDBM was built with LZO enabled. */ +char *cblzodecode(const char *ptr, int size, int *sp); + + +/* Compress a serial object with BZIP2. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. + If successful, the return value is the pointer to the result object, else, it is `NULL'. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. This function is available only if + QDBM was built with LZO enabled. */ +char *cbbzencode(const char *ptr, int size, int *sp); + + +/* Decompress a serial object compressed with BZIP2. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the result object, else, it is `NULL'. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. This function is available only if QDBM was built with LZO enabled. */ +char *cbbzdecode(const char *ptr, int size, int *sp); + + +/* Convert the character encoding of a string. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + `icode' specifies the name of encoding of the input string. + `ocode' specifies the name of encoding of the output string. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + `mp' specifies the pointer to a variable to which the number of missing characters by failure + of conversion is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the result object, else, it is `NULL'. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. This function is available only if QDBM was built with ICONV enabled. */ +char *cbiconv(const char *ptr, int size, const char *icode, const char *ocode, int *sp, int *mp); + + +/* Detect the encoding of a string automatically. + `ptr' specifies the pointer to a region. + `size' specifies the size of the region. If it is negative, the size is assigned with + `strlen(ptr)'. + The return value is the string of the encoding name of the string. + As it stands, US-ASCII, ISO-2022-JP, Shift_JIS, CP932, EUC-JP, UTF-8, UTF-16, UTF-16BE, + and UTF-16LE are supported. If none of them matches, ISO-8859-1 is selected. This function + is available only if QDBM was built with ICONV enabled. */ +const char *cbencname(const char *ptr, int size); + + +/* Get the jet lag of the local time in seconds. + The return value is the jet lag of the local time in seconds. */ +int cbjetlag(void); + + +/* Get the Gregorian calendar of a time. + `t' specifies a source time. If it is negative, the current time is specified. + `jl' specifies the jet lag of a location in seconds. + `yearp' specifies the pointer to a variable to which the year is assigned. If it is `NULL', + it is not used. + `monp' specifies the pointer to a variable to which the month is assigned. If it is `NULL', + it is not used. 1 means January and 12 means December. + `dayp' specifies the pointer to a variable to which the day of the month is assigned. If it + is `NULL', it is not used. + `hourp' specifies the pointer to a variable to which the hours is assigned. If it is `NULL', + it is not used. + `minp' specifies the pointer to a variable to which the minutes is assigned. If it is `NULL', + it is not used. + `secp' specifies the pointer to a variable to which the seconds is assigned. If it is `NULL', + it is not used. */ +void cbcalendar(time_t t, int jl, int *yearp, int *monp, int *dayp, + int *hourp, int *minp, int *secp); + + +/* Get the day of week of a date. + `year' specifies the year of a date. + `mon' specifies the month of the date. + `day' specifies the day of the date. + The return value is the day of week of the date. 0 means Sunday and 6 means Saturday. */ +int cbdayofweek(int year, int mon, int day); + + +/* Get the string for a date in W3CDTF. + `t' specifies a source time. If it is negative, the current time is specified. + `jl' specifies the jet lag of a location in seconds. + The return value is the string of the date in W3CDTF (YYYY-MM-DDThh:mm:ddTZD). + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cbdatestrwww(time_t t, int jl); + + +/* Get the string for a date in RFC 1123 format. + `t' specifies a source time. If it is negative, the current time is specified. + `jl' specifies the jet lag of a location in seconds. + The return value is the string of the date in RFC 1123 format (Wdy, DD-Mon-YYYY hh:mm:dd TZD). + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *cbdatestrhttp(time_t t, int jl); + + +/* Get the time value of a date string in decimal, hexadecimal, W3CDTF, or RFC 822 (1123). + `str' specifies a date string in decimal, hexadecimal, W3CDTF, or RFC 822 (1123). + The return value is the time value of the date or -1 if the format is invalid. + Decimal can be trailed by "s" for in seconds, "m" for in minutes, "h" for in hours, + and "d" for in days. */ +time_t cbstrmktime(const char *str); + + +/* Get user and system processing times. + `usrp' specifies the pointer to a variable to which the user processing time is assigned. + If it is `NULL', it is not used. The unit of time is seconds. + `sysp' specifies the pointer to a variable to which the system processing time is assigned. + If it is `NULL', it is not used. The unit of time is seconds. */ +void cbproctime(double *usrp, double *sysp); + + +/* Ensure that the standard I/O is binary mode. + This function is useful for applications on dosish file systems. */ +void cbstdiobin(void); + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Show error message on the standard error output and exit. + `message' specifies an error message. + This function does not return. */ +void *cbmyfatal(const char *message); + + +/* Create a datum handle from an allocated region. + `ptr' specifies the pointer to the region of an element. The region should be allocated with + malloc and it is released by the function. + `size' specifies the size of the region. */ +CBDATUM *cbdatumopenbuf(char *ptr, int size); + + +/* Set a buffer to a datum handle. + `ptr' specifies the pointer to the region of an element. The region should be allocated with + malloc and it is released by the function. + `size' specifies the size of the region. */ +void cbdatumsetbuf(CBDATUM *datum, char *ptr, int size); + + +/* Add an allocated element at the end of a list. + `list' specifies a list handle. + `ptr' specifies the pointer to the region of an element. The region should be allocated with + malloc and it is released by the function. + `size' specifies the size of the region. */ +void cblistpushbuf(CBLIST *list, char *ptr, int size); + + +/* Get a map handle with specifying the number of buckets. + `bnum' specifies the number of buckets. + The return value is a map handle. */ +CBMAP *cbmapopenex(int bnum); + + +/* Alias of `cbmalloc'. */ +#define CB_MALLOC(CB_ptr, CB_size) \ + (((CB_ptr) = malloc(CB_size)) ? (CB_ptr) : cbmyfatal("out of memory")) + + +/* Alias of `cbrealloc'. */ +#define CB_REALLOC(CB_ptr, CB_size) \ + (((CB_ptr) = realloc((CB_ptr), (CB_size))) ? (CB_ptr) : cbmyfatal("out of memory")) + + +/* Alias of `cbmemdup'. + However, `size' should not be negative. */ +#define CB_MEMDUP(CB_res, CB_ptr, CB_size) \ + do { \ + CB_MALLOC((CB_res), (CB_size) + 1); \ + memcpy((CB_res), (CB_ptr), (CB_size)); \ + (CB_res)[(CB_size)] = '\0'; \ + } while(FALSE) + + +/* Get the size of padding bytes for pointer alignment. + `hsiz' specifies the header size of the object. + The return value is the size of padding bytes. */ +#define CB_ALIGNPAD(CB_hsiz) \ + (((CB_hsiz | ~-(int)sizeof(void *)) + 1) - CB_hsiz) + + +/* Alias of `cbdatumopen'. + However, no dafault data is specified. */ +#define CB_DATUMOPEN(CB_datum) \ + do { \ + CB_MALLOC((CB_datum), sizeof(*(CB_datum))); \ + CB_MALLOC((CB_datum)->dptr, CB_DATUMUNIT); \ + (CB_datum)->dptr[0] = '\0'; \ + (CB_datum)->dsize = 0; \ + (CB_datum)->asize = CB_DATUMUNIT; \ + } while(FALSE) + + +/* Alias of `cbdatumopen'. + However, `size' should not be negative. */ +#define CB_DATUMOPEN2(CB_datum, CB_ptr, CB_size) \ + do { \ + CB_DATUMOPEN((CB_datum)); \ + CB_DATUMCAT((CB_datum), (CB_ptr), (CB_size)); \ + } while(FALSE) + + +/* Alias of `cbdatumclose'. */ +#define CB_DATUMCLOSE(CB_datum) \ + do { \ + free((CB_datum)->dptr); \ + free((CB_datum)); \ + } while(FALSE) + + +/* Alias of `cbdatumcat'. + However, `size' should not be negative. */ +#define CB_DATUMCAT(CB_datum, CB_ptr, CB_size) \ + do { \ + if((CB_datum)->dsize + (CB_size) >= (CB_datum)->asize){ \ + (CB_datum)->asize = (CB_datum)->asize * 2 + (CB_size) + 1; \ + CB_REALLOC((CB_datum)->dptr, (CB_datum)->asize); \ + } \ + memcpy((CB_datum)->dptr + (CB_datum)->dsize, (CB_ptr), (CB_size)); \ + (CB_datum)->dsize += (CB_size); \ + (CB_datum)->dptr[(CB_datum)->dsize] = '\0'; \ + } while(FALSE) + + +/* Alias of `cbdatumptr'. */ +#define CB_DATUMPTR(CB_datum) ((const char *)((CB_datum)->dptr)) + + +/* Alias of `cbdatumsize'. */ +#define CB_DATUMSIZE(CB_datum) ((int)((CB_datum)->dsize)) + + +/* Alias of `cbdatumsetsize'. */ +#define CB_DATUMSETSIZE(CB_datum, CB_size) \ + do { \ + if((CB_size) <= (CB_datum)->dsize){ \ + (CB_datum)->dsize = (CB_size); \ + (CB_datum)->dptr[(CB_size)] = '\0'; \ + } else { \ + if((CB_size) >= (CB_datum)->asize){ \ + (CB_datum)->asize = (CB_datum)->asize * 2 + (CB_size) + 1; \ + CB_REALLOC((CB_datum)->dptr, (CB_datum)->asize); \ + } \ + memset((CB_datum)->dptr + (CB_datum)->dsize, 0, ((CB_size) - (CB_datum)->dsize) + 1); \ + (CB_datum)->dsize = (CB_size); \ + } \ + } while(FALSE) + + +/* Alias of `cbdatumtomalloc'. */ +#define CB_DATUMTOMALLOC(CB_datum, CB_ptr, CB_size) \ + do { \ + (CB_ptr) = (CB_datum)->dptr; \ + (CB_size) = (CB_datum)->dsize; \ + free((CB_datum)); \ + } while(FALSE) + + +/* Alias of `cblistopen'. */ +#define CB_LISTOPEN(CB_list) \ + do { \ + CB_MALLOC((CB_list), sizeof(*(CB_list))); \ + (CB_list)->anum = CB_LISTUNIT; \ + CB_MALLOC((CB_list)->array, sizeof((CB_list)->array[0]) * (CB_list)->anum); \ + (CB_list)->start = 0; \ + (CB_list)->num = 0; \ + } while(FALSE) + + +/* Alias of `cblistopen'. + However, `anum' is specified for the number of initial allocated elements. */ +#define CB_LISTOPEN2(CB_list, CB_anum) \ + do { \ + CB_MALLOC((CB_list), sizeof(*(CB_list))); \ + (CB_list)->anum = (CB_anum) > 4 ? (CB_anum) : 4; \ + CB_MALLOC((CB_list)->array, sizeof((CB_list)->array[0]) * (CB_list)->anum); \ + (CB_list)->start = 0; \ + (CB_list)->num = 0; \ + } while(FALSE) + + +/* Alias of `cblistclose'. */ +#define CB_LISTCLOSE(CB_list) \ + do { \ + int _CB_i, _CB_end; \ + _CB_end = (CB_list)->start + (CB_list)->num; \ + for(_CB_i = (CB_list)->start; _CB_i < _CB_end; _CB_i++){ \ + free((CB_list)->array[_CB_i].dptr); \ + } \ + free((CB_list)->array); \ + free((CB_list)); \ + } while(FALSE) + + +/* Alias of `cblistnum'. */ +#define CB_LISTNUM(CB_list) \ + ((int)((CB_list)->num)) + + +/* Alias of `cblistval'. + However, `sp' is ignored. */ +#define CB_LISTVAL(CB_list, CB_index) \ + ((const char *)((CB_list)->array[(CB_list)->start+(CB_index)].dptr)) + + +/* Alias of `cblistval'. + However, `size' is used instead of `sp'. */ +#define CB_LISTVAL2(CB_list, CB_index, CB_size) \ + ((CB_size) = (CB_list)->array[(CB_list)->start+(CB_index)].dsize, \ + (const char *)((CB_list)->array[(CB_list)->start+(CB_index)].dptr)) + + +/* Alias of `cblistpush'. + However, `size' should not be negative. */ +#define CB_LISTPUSH(CB_list, CB_ptr, CB_size) \ + do { \ + int _CB_index; \ + _CB_index = (CB_list)->start + (CB_list)->num; \ + if(_CB_index >= (CB_list)->anum){ \ + (CB_list)->anum *= 2; \ + CB_REALLOC((CB_list)->array, (CB_list)->anum * sizeof((CB_list)->array[0])); \ + } \ + CB_MALLOC((CB_list)->array[_CB_index].dptr, \ + ((CB_size) < CB_DATUMUNIT ? CB_DATUMUNIT : (CB_size)) + 1); \ + memcpy((CB_list)->array[_CB_index].dptr, (CB_ptr), (CB_size)); \ + (CB_list)->array[_CB_index].dptr[(CB_size)] = '\0'; \ + (CB_list)->array[_CB_index].dsize = (CB_size); \ + (CB_list)->num++; \ + } while(FALSE) + + +/* Remove and free an element of the end of a list. + `list' specifies a list handle. */ +#define CB_LISTDROP(CB_list) \ + do { \ + if((CB_list)->num > 0){ \ + free((CB_list)->array[(CB_list)->start+(CB_list)->num-1].dptr); \ + (CB_list)->num--; \ + } \ + } while(FALSE) + + +/* Alias of `cblistinsert'. + However, `index' is not checked and `size' should not be negative. */ +#define CB_LISTINSERT(CB_list, CB_index, CB_ptr, CB_size) \ + do { \ + int _CB_index = (CB_index); \ + _CB_index += (CB_list)->start; \ + if((CB_list)->start + (CB_list)->num >= (CB_list)->anum){ \ + (CB_list)->anum *= 2; \ + CB_REALLOC((CB_list)->array, (CB_list)->anum * sizeof((CB_list)->array[0])); \ + } \ + memmove((CB_list)->array + _CB_index + 1, (CB_list)->array + _CB_index, \ + sizeof((CB_list)->array[0]) * ((CB_list)->start + (CB_list)->num - _CB_index)); \ + CB_MEMDUP((CB_list)->array[_CB_index].dptr, (CB_ptr), (CB_size)); \ + (CB_list)->array[_CB_index].dsize = (CB_size); \ + (CB_list)->num++; \ + } while(FALSE) + + +/* Alias of `cblistpushbuf'. */ +#define CB_LISTPUSHBUF(CB_list, CB_ptr, CB_size) \ + do{ \ + int _CB_index; \ + _CB_index = (CB_list)->start + (CB_list)->num; \ + if(_CB_index >= (CB_list)->anum){ \ + (CB_list)->anum *= 2; \ + CB_REALLOC((CB_list)->array, (CB_list)->anum * sizeof((CB_list)->array[0])); \ + } \ + (CB_list)->array[_CB_index].dptr = (CB_ptr); \ + (CB_list)->array[_CB_index].dsize = (CB_size); \ + (CB_list)->num++; \ + } while(FALSE) \ + + +/* Alias of `cbmapiterval'. + However, `size' is used instead of `sp'. */ +#define CB_MAPITERVAL(CB_vbuf, CB_kbuf, CB_vsiz) \ + do { \ + CBMAPDATUM *_CB_datum; \ + _CB_datum = (CBMAPDATUM *)((CB_kbuf) - sizeof(*_CB_datum)); \ + (CB_vsiz) = _CB_datum->vsiz; \ + (CB_vbuf) = (char *)_CB_datum + sizeof(*_CB_datum) + \ + _CB_datum->ksiz + CB_ALIGNPAD(_CB_datum->ksiz); \ + } while(FALSE) + + + +#undef MYEXTERN + +#if defined(__cplusplus) /* export for C++ */ +} +#endif + +#endif /* duplication check */ + + +/* END OF FILE */ diff --git a/qdbm/cbcodec.c b/qdbm/cbcodec.c new file mode 100644 index 00000000..1ab45153 --- /dev/null +++ b/qdbm/cbcodec.c @@ -0,0 +1,1079 @@ +/************************************************************************************************* + * Popular encoders and decoders + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define DEFCODE "UTF-8" /* default encoding */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +char *readstdin(int *sp); +int runurl(int argc, char **argv); +int runbase(int argc, char **argv); +int runquote(int argc, char **argv); +int runmime(int argc, char **argv); +int runcsv(int argc, char **argv); +int runxml(int argc, char **argv); +int runzlib(int argc, char **argv); +int runlzo(int argc, char **argv); +int runbzip(int argc, char **argv); +int runiconv(int argc, char **argv); +int rundate(int argc, char **argv); +void shouucsmap(void); + + +/* main routine */ +int main(int argc, char **argv){ + int rv; + cbstdiobin(); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "url")){ + rv = runurl(argc, argv); + } else if(!strcmp(argv[1], "base")){ + rv = runbase(argc, argv); + } else if(!strcmp(argv[1], "quote")){ + rv = runquote(argc, argv); + } else if(!strcmp(argv[1], "mime")){ + rv = runmime(argc, argv); + } else if(!strcmp(argv[1], "csv")){ + rv = runcsv(argc, argv); + } else if(!strcmp(argv[1], "xml")){ + rv = runxml(argc, argv); + } else if(!strcmp(argv[1], "zlib")){ + rv = runzlib(argc, argv); + } else if(!strcmp(argv[1], "lzo")){ + rv = runlzo(argc, argv); + } else if(!strcmp(argv[1], "bzip")){ + rv = runbzip(argc, argv); + } else if(!strcmp(argv[1], "iconv")){ + rv = runiconv(argc, argv); + } else if(!strcmp(argv[1], "date")){ + rv = rundate(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + char *tmp; + int tsiz; + fprintf(stderr, "%s: popular encoders and decoders\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s url [-d] [-br] [-rs base target] [-l] [-e expr] [file]\n", progname); + fprintf(stderr, " %s base [-d] [-l] [-c num] [-e expr] [file]\n", progname); + fprintf(stderr, " %s quote [-d] [-l] [-c num] [-e expr] [file]\n", progname); + fprintf(stderr, " %s mime [-d] [-hd] [-bd] [-part num] [-l] [-ec code] [-qp] [-dc] [-e expr]" + " [file]\n", progname); + fprintf(stderr, " %s csv [-d] [-t] [-l] [-e expr] [-html] [file]\n", progname); + fprintf(stderr, " %s xml [-d] [-p] [-l] [-e expr] [-tsv] [file]\n", progname); + if((tmp = cbdeflate("", 0, &tsiz)) != NULL){ + fprintf(stderr, " %s zlib [-d] [-gz] [-crc] [file]\n", progname); + free(tmp); + } + if((tmp = cblzoencode("", 0, &tsiz)) != NULL){ + fprintf(stderr, " %s lzo [-d] [file]\n", progname); + free(tmp); + } + if((tmp = cbbzencode("", 0, &tsiz)) != NULL){ + fprintf(stderr, " %s bzip [-d] [file]\n", progname); + free(tmp); + } + if((tmp = cbiconv("", 0, "US-ASCII", "US-ASCII", NULL, NULL)) != NULL){ + fprintf(stderr, " %s iconv [-ic code] [-oc code] [-ol ltype] [-cn] [-wc] [-um] [file]\n", + progname); + free(tmp); + } + fprintf(stderr, " %s date [-wf] [-rf] [-utc] [str]\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* read the standard input */ +char *readstdin(int *sp){ + char *buf; + int i, blen, c; + blen = 256; + buf = cbmalloc(blen); + for(i = 0; (c = getchar()) != EOF; i++){ + if(i >= blen - 1) buf = cbrealloc(buf, blen *= 2); + buf[i] = c; + } + buf[i] = '\0'; + if(sp) *sp = i; + return buf; +} + + +/* parse arguments of url command */ +int runurl(int argc, char **argv){ + CBMAP *map; + int i, size, dec, br, line; + const char *val; + char *base, *target, *expr, *file, *buf, *res; + dec = FALSE; + br = FALSE; + line = FALSE; + base = NULL; + target = NULL; + expr = NULL; + file = NULL; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + dec = TRUE; + } else if(!strcmp(argv[i], "-br")){ + br = TRUE; + } else if(!strcmp(argv[i], "-rs")){ + if(++i >= argc) usage(); + base = argv[i]; + if(++i >= argc) usage(); + target = argv[i]; + } else if(!strcmp(argv[i], "-l")){ + line = TRUE; + } else if(!strcmp(argv[i], "-e")){ + if(++i >= argc) usage(); + expr = argv[i]; + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + buf = NULL; + if(base){ + size = strlen(base); + buf = cbmemdup(base, size); + } else if(expr){ + size = strlen(expr); + buf = cbmemdup(expr, size); + } else if(file){ + if(!(buf = cbreadfile(file, &size))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + buf = readstdin(&size); + } + if(target){ + res = cburlresolve(base, target); + printf("%s", res); + free(res); + } else if(br){ + map = cburlbreak(buf); + if((val = cbmapget(map, "self", -1, NULL))) printf("self\t%s\n", val); + if((val = cbmapget(map, "scheme", -1, NULL))) printf("scheme\t%s\n", val); + if((val = cbmapget(map, "host", -1, NULL))) printf("host\t%s\n", val); + if((val = cbmapget(map, "port", -1, NULL))) printf("port\t%s\n", val); + if((val = cbmapget(map, "authority", -1, NULL))) printf("authority\t%s\n", val); + if((val = cbmapget(map, "path", -1, NULL))) printf("path\t%s\n", val); + if((val = cbmapget(map, "file", -1, NULL))) printf("file\t%s\n", val); + if((val = cbmapget(map, "query", -1, NULL))) printf("query\t%s\n", val); + if((val = cbmapget(map, "fragment", -1, NULL))) printf("fragment\t%s\n", val); + cbmapclose(map); + } else if(dec){ + res = cburldecode(buf, &size); + for(i = 0; i < size; i++){ + putchar(res[i]); + } + free(res); + } else { + res = cburlencode(buf, size); + for(i = 0; res[i] != '\0'; i++){ + putchar(res[i]); + } + free(res); + } + if(line) putchar('\n'); + free(buf); + return 0; +} + + +/* parse arguments of base command */ +int runbase(int argc, char **argv){ + int i, ci, size, dec, line, cols; + char *expr, *file, *buf, *res; + dec = FALSE; + line = FALSE; + cols = -1; + expr = NULL; + file = NULL; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + dec = TRUE; + } else if(!strcmp(argv[i], "-l")){ + line = TRUE; + } else if(!strcmp(argv[i], "-c")){ + if(++i >= argc) usage(); + cols = atoi(argv[i]); + } else if(!strcmp(argv[i], "-e")){ + if(++i >= argc) usage(); + expr = argv[i]; + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + buf = NULL; + if(expr){ + size = strlen(expr); + buf = cbmemdup(expr, size); + } else if(file){ + if(!(buf = cbreadfile(file, &size))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + buf = readstdin(&size); + } + if(dec){ + res = cbbasedecode(buf, &size); + for(i = 0; i < size; i++){ + putchar(res[i]); + } + free(res); + } else { + res = cbbaseencode(buf, size); + ci = 0; + for(i = 0; res[i] != '\0'; i++){ + if(cols > 0 && ci >= cols){ + putchar('\n'); + ci = 0; + } + putchar(res[i]); + ci++; + } + free(res); + } + if(line) putchar('\n'); + free(buf); + return 0; +} + + +/* parse arguments of quote command */ +int runquote(int argc, char **argv){ + int i, ci, size, dec, line, cols; + char *expr, *file, *buf, *res; + dec = FALSE; + line = FALSE; + cols = -1; + expr = NULL; + file = NULL; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + dec = TRUE; + } else if(!strcmp(argv[i], "-l")){ + line = TRUE; + } else if(!strcmp(argv[i], "-c")){ + if(++i >= argc) usage(); + cols = atoi(argv[i]); + } else if(!strcmp(argv[i], "-e")){ + if(++i >= argc) usage(); + expr = argv[i]; + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + buf = NULL; + if(expr){ + size = strlen(expr); + buf = cbmemdup(expr, size); + } else if(file){ + if(!(buf = cbreadfile(file, &size))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + buf = readstdin(&size); + } + if(dec){ + res = cbquotedecode(buf, &size); + for(i = 0; i < size; i++){ + putchar(res[i]); + } + free(res); + } else { + res = cbquoteencode(buf, size); + ci = 0; + for(i = 0; res[i] != '\0'; i++){ + if(cols > 0 && (ci >= cols || (ci >= cols - 2 && res[i] == '='))){ + printf("=\n"); + ci = 0; + } + if(res[i] == '\r' || res[i] == '\n') ci = 0; + putchar(res[i]); + ci++; + } + free(res); + } + if(line) putchar('\n'); + free(buf); + return 0; +} + + +/* parse arguments of mime command */ +int runmime(int argc, char **argv){ + CBMAP *attrs; + CBLIST *parts; + int i, size, dec, line, qp, dc, hd, bd, pnum, rsiz, bsiz; + const char *key, *body; + char *code, *expr, *file, *buf, *res, renc[64]; + dec = FALSE; + hd = FALSE; + bd = FALSE; + pnum = 0; + line = FALSE; + dc = FALSE; + qp = FALSE; + code = NULL; + expr = NULL; + file = NULL; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + dec = TRUE; + } else if(!strcmp(argv[i], "-hd")){ + hd = TRUE; + } else if(!strcmp(argv[i], "-bd")){ + bd = TRUE; + } else if(!strcmp(argv[i], "-part")){ + if(++i >= argc) usage(); + pnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-l")){ + line = TRUE; + } else if(!strcmp(argv[i], "-ec")){ + if(++i >= argc) usage(); + code = argv[i]; + } else if(!strcmp(argv[i], "-qp")){ + qp = TRUE; + } else if(!strcmp(argv[i], "-dc")){ + dc = TRUE; + } else if(!strcmp(argv[i], "-e")){ + if(++i >= argc) usage(); + expr = argv[i]; + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + buf = NULL; + if(expr){ + size = strlen(expr); + buf = cbmemdup(expr, size); + } else if(file){ + if(!(buf = cbreadfile(file, &size))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + buf = readstdin(&size); + } + if(hd || bd || pnum > 0){ + attrs = cbmapopen(); + res = cbmimebreak(buf, size, attrs, &rsiz); + if(pnum > 0){ + parts = NULL; + if(!(key = cbmapget(attrs, "TYPE", -1, NULL)) || !cbstrfwimatch(key, "multipart/") || + !(key = cbmapget(attrs, "BOUNDARY", -1, NULL)) || + !(parts = cbmimeparts(res, rsiz, key)) || cblistnum(parts) < pnum){ + fprintf(stderr, "%s: not multipart or no such part\n", progname); + if(parts) cblistclose(parts); + free(res); + cbmapclose(attrs); + free(buf); + return 1; + } + body = cblistval(parts, pnum - 1, &bsiz); + for(i = 0; i < bsiz; i++){ + putchar(body[i]); + } + cblistclose(parts); + } else if(hd){ + cbmapiterinit(attrs); + while((key = cbmapiternext(attrs, NULL)) != NULL){ + printf("%s\t%s\n", key, cbmapget(attrs, key, -1, NULL)); + } + } else { + for(i = 0; i < rsiz; i++){ + putchar(res[i]); + } + } + free(res); + cbmapclose(attrs); + } else if(dec){ + res = cbmimedecode(buf, renc); + printf("%s", dc ? renc : res); + free(res); + } else { + res = cbmimeencode(buf, code ? code : DEFCODE, !qp); + printf("%s", res); + free(res); + } + if(line) putchar('\n'); + free(buf); + return 0; +} + + +/* parse arguments of csv command */ +int runcsv(int argc, char **argv){ + CBLIST *rows, *cells; + int i, j, k, dec, tb, line, html; + const char *row, *cell; + char *expr, *file, *buf, *res; + dec = FALSE; + tb = FALSE; + line = FALSE; + html = FALSE; + expr = NULL; + file = NULL; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + dec = TRUE; + } else if(!strcmp(argv[i], "-t")){ + tb = TRUE; + } else if(!strcmp(argv[i], "-l")){ + line = TRUE; + } else if(!strcmp(argv[i], "-e")){ + if(++i >= argc) usage(); + expr = argv[i]; + } else if(!strcmp(argv[i], "-html")){ + html = TRUE; + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + buf = NULL; + if(expr){ + buf = cbmemdup(expr, -1); + } else if(file){ + if(!(buf = cbreadfile(file, NULL))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + buf = readstdin(NULL); + } + if(tb || html){ + if(html) printf("\n"); + rows = cbcsvrows(buf); + for(i = 0; i < cblistnum(rows); i++){ + if(html) printf(""); + row = cblistval(rows, i, NULL); + cells = cbcsvcells(row); + for(j = 0; j < cblistnum(cells); j++){ + cell = cblistval(cells, j, NULL); + if(html){ + printf(""); + } else { + if(j > 0) putchar('\t'); + for(k = 0; cell[k] != '\0'; k++){ + if(((unsigned char *)cell)[k] >= 0x20) putchar(cell[k]); + } + } + } + cblistclose(cells); + if(html) printf(""); + putchar('\n'); + } + cblistclose(rows); + if(html) printf("
"); + for(k = 0; cell[k] != '\0'; k++){ + if(cell[k] == '\r' || cell[k] == '\n'){ + printf("
"); + if(cell[k] == '\r' && cell[k] == '\n') k++; + } else { + switch(cell[k]){ + case '&': printf("&"); break; + case '<': printf("<"); break; + case '>': printf(">"); break; + default: putchar(cell[k]); break; + } + } + } + printf("
\n"); + } else if(dec){ + res = cbcsvunescape(buf); + for(i = 0; res[i] != '\0'; i++){ + putchar(res[i]); + } + free(res); + } else { + res = cbcsvescape(buf); + for(i = 0; res[i] != '\0'; i++){ + putchar(res[i]); + } + free(res); + } + if(line) putchar('\n'); + free(buf); + return 0; +} + + +/* parse arguments of xml command */ +int runxml(int argc, char **argv){ + CBLIST *elems; + CBMAP *attrs; + int i, j, dec, pb, line, tsv, div; + const char *elem, *attr; + char *expr, *file, *buf, *res; + dec = FALSE; + pb = FALSE; + line = FALSE; + tsv = FALSE; + expr = NULL; + file = NULL; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + dec = TRUE; + } else if(!strcmp(argv[i], "-p")){ + pb = TRUE; + } else if(!strcmp(argv[i], "-l")){ + line = TRUE; + } else if(!strcmp(argv[i], "-e")){ + if(++i >= argc) usage(); + expr = argv[i]; + } else if(!strcmp(argv[i], "-tsv")){ + tsv = TRUE; + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + buf = NULL; + if(expr){ + buf = cbmemdup(expr, -1); + } else if(file){ + if(!(buf = cbreadfile(file, NULL))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + buf = readstdin(NULL); + } + if(pb || tsv){ + elems = cbxmlbreak(buf, FALSE); + for(i = 0; i < cblistnum(elems); i++){ + elem = cblistval(elems, i, NULL); + div = FALSE; + if(elem[0] == '<'){ + if(cbstrfwimatch(elem, "")){ + printf("EMPTAG"); + div = TRUE; + } else { + printf("BEGTAG"); + div = TRUE; + } + } else { + printf("TEXT"); + } + putchar('\t'); + if(tsv){ + if(div){ + attrs = cbxmlattrs(elem); + cbmapiterinit(attrs); + for(j = 0; (attr = cbmapiternext(attrs, NULL)) != NULL; j++){ + if(j < 1){ + printf("%s", cbmapget(attrs, attr, -1, NULL)); + } else { + printf("\t%s\t%s", attr, cbmapget(attrs, attr, -1, NULL)); + } + } + cbmapclose(attrs); + } else { + res = cbxmlunescape(elem); + for(j = 0; elem[j] != '\0'; j++){ + if(((unsigned char *)elem)[j] < 0x20 || elem[j] == '%'){ + printf("%%%02X", elem[j]); + } else { + putchar(elem[j]); + } + } + free(res); + } + } else { + printf("%s", elem); + } + putchar('\n'); + } + cblistclose(elems); + } else if(dec){ + res = cbxmlunescape(buf); + for(i = 0; res[i] != '\0'; i++){ + putchar(res[i]); + } + free(res); + } else { + res = cbxmlescape(buf); + for(i = 0; res[i] != '\0'; i++){ + putchar(res[i]); + } + free(res); + } + if(line) putchar('\n'); + free(buf); + return 0; +} + + +/* parse arguments of zlib command */ +int runzlib(int argc, char **argv){ + unsigned int sum; + int i, bsiz, rsiz, dec, gz, crc; + char *file, *buf, *res; + dec = FALSE; + gz = FALSE; + crc = FALSE; + file = NULL; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + dec = TRUE; + } else if(!strcmp(argv[i], "-gz")){ + gz = TRUE; + } else if(!strcmp(argv[i], "-crc")){ + crc = TRUE; + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + buf = NULL; + if(file){ + if(!(buf = cbreadfile(file, &bsiz))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + buf = readstdin(&bsiz); + } + if(crc){ + sum = cbgetcrc(buf, bsiz); + for(i = 0; i < sizeof(int); i++){ + printf("%02x", sum / 0x1000000); + sum <<= 8; + } + putchar('\n'); + } else if(dec){ + if(!(res = gz ? cbgzdecode(buf, bsiz, &rsiz) : cbinflate(buf, bsiz, &rsiz))){ + fprintf(stderr, "%s: inflate failed\n", progname); + free(buf); + return 1; + } + for(i = 0; i < rsiz; i++){ + putchar(res[i]); + } + free(res); + } else { + if(!(res = gz ? cbgzencode(buf, bsiz, &rsiz) : cbdeflate(buf, bsiz, &rsiz))){ + fprintf(stderr, "%s: deflate failed\n", progname); + free(buf); + return 1; + } + for(i = 0; i < rsiz; i++){ + putchar(res[i]); + } + free(res); + } + free(buf); + return 0; +} + + +/* parse arguments of lzo command */ +int runlzo(int argc, char **argv){ + int i, bsiz, rsiz, dec; + char *file, *buf, *res; + dec = FALSE; + file = NULL; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + dec = TRUE; + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + buf = NULL; + if(file){ + if(!(buf = cbreadfile(file, &bsiz))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + buf = readstdin(&bsiz); + } + if(dec){ + if(!(res = cblzodecode(buf, bsiz, &rsiz))){ + fprintf(stderr, "%s: decode failed\n", progname); + free(buf); + return 1; + } + for(i = 0; i < rsiz; i++){ + putchar(res[i]); + } + free(res); + } else { + if(!(res = cblzoencode(buf, bsiz, &rsiz))){ + fprintf(stderr, "%s: encode failed\n", progname); + free(buf); + return 1; + } + for(i = 0; i < rsiz; i++){ + putchar(res[i]); + } + free(res); + } + free(buf); + return 0; +} + + +/* parse arguments of bzip command */ +int runbzip(int argc, char **argv){ + int i, bsiz, rsiz, dec; + char *file, *buf, *res; + dec = FALSE; + file = NULL; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + dec = TRUE; + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + buf = NULL; + if(file){ + if(!(buf = cbreadfile(file, &bsiz))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + buf = readstdin(&bsiz); + } + if(dec){ + if(!(res = cbbzdecode(buf, bsiz, &rsiz))){ + fprintf(stderr, "%s: decode failed\n", progname); + free(buf); + return 1; + } + for(i = 0; i < rsiz; i++){ + putchar(res[i]); + } + free(res); + } else { + if(!(res = cbbzencode(buf, bsiz, &rsiz))){ + fprintf(stderr, "%s: encode failed\n", progname); + free(buf); + return 1; + } + for(i = 0; i < rsiz; i++){ + putchar(res[i]); + } + free(res); + } + free(buf); + return 0; +} + + +/* parse arguments of iconv command */ +int runiconv(int argc, char **argv){ + CBDATUM *datum; + const char *rcode; + char *icode, *ocode, *ltype, *file, *buf, *res, *norm, *orig; + int i, cn, wc, bsiz, rsiz, nsiz, osiz, miss; + icode = NULL; + ocode = NULL; + ltype = NULL; + file = NULL; + cn = FALSE; + wc = FALSE; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-ic")){ + if(++i >= argc) usage(); + icode = argv[i]; + } else if(!strcmp(argv[i], "-oc")){ + if(++i >= argc) usage(); + ocode = argv[i]; + } else if(!strcmp(argv[i], "-ol")){ + if(++i >= argc) usage(); + ltype = argv[i]; + } else if(!strcmp(argv[i], "-cn")){ + cn = TRUE; + } else if(!strcmp(argv[i], "-wc")){ + wc = TRUE; + } else if(!strcmp(argv[i], "-um")){ + shouucsmap(); + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + buf = NULL; + if(file){ + if(!(buf = cbreadfile(file, &bsiz))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + buf = readstdin(&bsiz); + } + miss = 0; + if(cn){ + printf("%s\n", cbencname(buf, bsiz)); + } else if(wc){ + printf("%d\n", cbstrcountutf(buf)); + } else { + rcode = icode ? icode : cbencname(buf, bsiz); + if(!(res = cbiconv(buf, bsiz, rcode, ocode ? ocode : DEFCODE, + &rsiz, &miss))){ + fprintf(stderr, "%s: iconv failed\n", progname); + free(buf); + return 1; + } + if(miss > 0) fprintf(stderr, "%s: missing %d characters\n", progname, miss); + if(ltype && (!cbstricmp(ltype, "u") || !cbstricmp(ltype, "unix") || + !cbstricmp(ltype, "lf"))){ + ltype = "\n"; + } else if(ltype && (!cbstricmp(ltype, "d") || !cbstricmp(ltype, "dos") || + !cbstricmp(ltype, "crlf"))){ + ltype = "\r\n"; + } else if(ltype && (!cbstricmp(ltype, "m") || !cbstricmp(ltype, "mac") || + !cbstricmp(ltype, "cr"))){ + ltype = "\r"; + } else { + ltype = NULL; + } + if(ltype){ + if(!(norm = cbiconv(res, rsiz, ocode, "UTF-8", &nsiz, NULL))){ + fprintf(stderr, "%s: iconv failed\n", progname); + free(res); + free(buf); + return 1; + } + datum = cbdatumopen(NULL, -1); + for(i = 0; i < nsiz; i++){ + if(norm[i] == '\r'){ + if(norm[i+1] == '\n') i++; + cbdatumcat(datum, ltype, -1); + } else if(norm[i] == '\n'){ + cbdatumcat(datum, ltype, -1); + } else { + cbdatumcat(datum, norm + i, 1); + } + } + if(!(orig = cbiconv(cbdatumptr(datum), cbdatumsize(datum), "UTF-8", ocode, &osiz, NULL))){ + fprintf(stderr, "%s: iconv failed\n", progname); + cbdatumclose(datum); + free(norm); + free(res); + free(buf); + return 1; + } + for(i = 0; i < osiz; i++){ + putchar(orig[i]); + } + free(orig); + cbdatumclose(datum); + free(norm); + } else { + for(i = 0; i < rsiz; i++){ + putchar(res[i]); + } + } + free(res); + } + free(buf); + return miss > 0 ? 1 : 0; +} + + +/* parse arguments of date command */ +int rundate(int argc, char **argv){ + int i, wb, rb, utc, jl; + char *date, *res; + time_t t; + wb = FALSE; + rb = FALSE; + utc = FALSE; + date = NULL; + for(i = 2; i < argc; i++){ + if(!date && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-wf")){ + wb = TRUE; + } else if(!strcmp(argv[i], "-rf")){ + rb = TRUE; + } else if(!strcmp(argv[i], "-utc")){ + utc = TRUE; + } else { + usage(); + } + } else if(!date){ + date = argv[i]; + } else { + usage(); + } + } + jl = utc ? 0 : cbjetlag(); + if(date){ + t = cbstrmktime(date); + } else { + t = time(NULL); + } + if(wb){ + res = cbdatestrwww(t, jl); + } else if(rb){ + res = cbdatestrhttp(t, jl); + } else { + res = cbsprintf("%d", (int)t); + } + if(t >= 0){ + printf("%s\n", res); + } else { + if(date){ + fprintf(stderr, "%s: %s: invalid date format\n", progname, date); + } else { + fprintf(stderr, "%s: invalid time setting\n", progname); + } + } + free(res); + return 0; +} + + +/* show mapping of UCS-2 and exit. */ +void shouucsmap(void){ + unsigned char buf[2], *tmp; + int i, j, tsiz; + for(i = 0; i < 65536; i++){ + buf[0] = i / 256; + buf[1] = i % 256; + printf("%d\t", i); + printf("U+%02X%02X\t", buf[0], buf[1]); + printf("\"\\x%x\\x%x\"\t", buf[0], buf[1]); + if((tmp = (unsigned char *)cbiconv((char *)buf, 2, "UTF-16BE", "UTF-8", + &tsiz, NULL)) != NULL){ + if(tsiz > 0){ + printf("\""); + for(j = 0; j < tsiz; j++){ + printf("\\x%x", tmp[j]); + } + printf("\""); + } else { + printf("NULL"); + } + free(tmp); + } + printf("\n"); + } + exit(0); +} + + + +/* END OF FILE */ diff --git a/qdbm/cbtest.c b/qdbm/cbtest.c new file mode 100644 index 00000000..d1c84e0d --- /dev/null +++ b/qdbm/cbtest.c @@ -0,0 +1,924 @@ +/************************************************************************************************* + * Test cases of Cabin + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define RECBUFSIZ 32 /* buffer for records */ +#define TEXTBUFSIZ 262144 /* buffer for text */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +int runsort(int argc, char **argv); +int runstrstr(int argc, char **argv); +int runlist(int argc, char **argv); +int runmap(int argc, char **argv); +int runheap(int argc, char **argv); +int runwicked(int argc, char **argv); +int runmisc(int argc, char **argv); +int printfflush(const char *format, ...); +int strpcmp(const void *ap, const void *bp); +int intpcmp(const void *ap, const void *bp); +int myrand(void); +int dosort(int rnum, int disp); +int dostrstr(int rnum, int disp); +int dolist(int rnum, int disp); +int domap(int rnum, int bnum, int disp); +int doheap(int rnum, int max, int disp); +int dowicked(int rnum); +int domisc(void); + + +/* main routine */ +int main(int argc, char **argv){ + int rv; + cbstdiobin(); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "sort")){ + rv = runsort(argc, argv); + } else if(!strcmp(argv[1], "strstr")){ + rv = runstrstr(argc, argv); + } else if(!strcmp(argv[1], "list")){ + rv = runlist(argc, argv); + } else if(!strcmp(argv[1], "map")){ + rv = runmap(argc, argv); + } else if(!strcmp(argv[1], "heap")){ + rv = runheap(argc, argv); + } else if(!strcmp(argv[1], "wicked")){ + rv = runwicked(argc, argv); + } else if(!strcmp(argv[1], "misc")){ + rv = runmisc(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: test cases for Cabin\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s sort [-d] rnum\n", progname); + fprintf(stderr, " %s strstr [-d] rnum\n", progname); + fprintf(stderr, " %s list [-d] rnum\n", progname); + fprintf(stderr, " %s map [-d] rnum [bnum]\n", progname); + fprintf(stderr, " %s heap [-d] rnum [top]\n", progname); + fprintf(stderr, " %s wicked rnum\n", progname); + fprintf(stderr, " %s misc\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of sort command */ +int runsort(int argc, char **argv){ + int i, rnum, disp, rv; + char *rstr; + rstr = NULL; + rnum = 0; + disp = FALSE; + for(i = 2; i < argc; i++){ + if(argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + disp = TRUE; + } else { + usage(); + } + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = dosort(rnum, disp); + return rv; +} + + +/* parse arguments of strstr command */ +int runstrstr(int argc, char **argv){ + int i, rnum, disp, rv; + char *rstr; + rstr = NULL; + rnum = 0; + disp = FALSE; + for(i = 2; i < argc; i++){ + if(argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + disp = TRUE; + } else { + usage(); + } + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = dostrstr(rnum, disp); + return rv; +} + + +/* parse arguments of list command */ +int runlist(int argc, char **argv){ + int i, rnum, disp, rv; + char *rstr; + rstr = NULL; + rnum = 0; + disp = FALSE; + for(i = 2; i < argc; i++){ + if(argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + disp = TRUE; + } else { + usage(); + } + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = dolist(rnum, disp); + return rv; +} + + +/* parse arguments of map command */ +int runmap(int argc, char **argv){ + int i, rnum, bnum, disp, rv; + char *rstr, *bstr; + rstr = NULL; + bstr = NULL; + rnum = 0; + bnum = -1; + disp = FALSE; + for(i = 2; i < argc; i++){ + if(argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + disp = TRUE; + } else { + usage(); + } + } else if(!rstr){ + rstr = argv[i]; + } else if(!bstr){ + bstr = argv[i]; + } else { + usage(); + } + } + if(!rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + if(bstr) bnum = atoi(bstr); + rv = domap(rnum, bnum, disp); + return rv; +} + + +/* parse arguments of heap command */ +int runheap(int argc, char **argv){ + int i, rnum, max, disp, rv; + char *rstr, *mstr; + rstr = NULL; + mstr = NULL; + rnum = 0; + max = -1; + disp = FALSE; + for(i = 2; i < argc; i++){ + if(argv[i][0] == '-'){ + if(!strcmp(argv[i], "-d")){ + disp = TRUE; + } else { + usage(); + } + } else if(!rstr){ + rstr = argv[i]; + } else if(!mstr){ + mstr = argv[i]; + } else { + usage(); + } + } + if(!rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + if(mstr) max = atoi(mstr); + if(max < 0) max = rnum; + rv = doheap(rnum, max, disp); + rv = 0; + return rv; +} + + +/* parse arguments of wicked command */ +int runwicked(int argc, char **argv){ + int i, rnum, rv; + char *rstr; + rstr = NULL; + rnum = 0; + for(i = 2; i < argc; i++){ + if(argv[i][0] == '-'){ + usage(); + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = dowicked(rnum); + return rv; +} + + +/* parse arguments of misc command */ +int runmisc(int argc, char **argv){ + int rv; + rv = domisc(); + return rv; +} + + +/* print formatted string and flush the buffer */ +int printfflush(const char *format, ...){ + va_list ap; + int rv; + va_start(ap, format); + rv = vprintf(format, ap); + if(fflush(stdout) == EOF) rv = -1; + va_end(ap); + return rv; +} + + +/* comparing function for strings */ +int strpcmp(const void *ap, const void *bp){ + return strcmp(*(char **)ap, *(char **)bp); +} + + +/* comparing function for integers */ +int intpcmp(const void *ap, const void *bp){ + return *(int *)ap - *(int *)bp; +} + + +/* pseudo random number generator */ +int myrand(void){ + static int cnt = 0; + if(cnt == 0) srand(time(NULL)); + return (rand() * rand() + (rand() >> (sizeof(int) * 4)) + (cnt++)) & INT_MAX; +} + + +/* perform sort command */ +int dosort(int rnum, int disp){ + char **ivector1, **ivector2, **ivector3, **ivector4, **ivector5; + char buf[RECBUFSIZ]; + int i, len, err; + if(!disp) printfflush("\n rnum=%d\n\n", rnum); + ivector1 = cbmalloc(rnum * sizeof(ivector1[0])); + ivector2 = cbmalloc(rnum * sizeof(ivector2[0])); + ivector3 = cbmalloc(rnum * sizeof(ivector3[0])); + ivector4 = cbmalloc(rnum * sizeof(ivector4[0])); + ivector5 = cbmalloc(rnum * sizeof(ivector5[0])); + err = FALSE; + for(i = 0; i < rnum; i++){ + len = sprintf(buf, "%08d", myrand() % rnum + 1); + ivector1[i] = cbmemdup(buf, len); + ivector2[i] = cbmemdup(buf, len); + ivector3[i] = cbmemdup(buf, len); + ivector4[i] = cbmemdup(buf, len); + ivector5[i] = cbmemdup(buf, len); + } + if(!disp) printfflush("Sorting with insert sort ... "); + cbisort(ivector1, rnum, sizeof(ivector1[0]), strpcmp); + if(!disp) printfflush("ok\n"); + if(!disp) printfflush("Sorting with shell sort ... "); + cbssort(ivector2, rnum, sizeof(ivector2[0]), strpcmp); + if(!disp) printfflush("ok\n"); + if(!disp) printfflush("Sorting with heap sort ... "); + cbhsort(ivector3, rnum, sizeof(ivector3[0]), strpcmp); + if(!disp) printfflush("ok\n"); + if(!disp) printfflush("Sorting with quick sort ... "); + cbqsort(ivector4, rnum, sizeof(ivector4[0]), strpcmp); + if(!disp) printfflush("ok\n"); + for(i = 0; i < rnum; i++){ + if(disp) printfflush("%s\t%s\t%s\t%s\t[%s]\n", + ivector1[i], ivector2[i], ivector3[i], ivector4[i], ivector5[i]); + if(strcmp(ivector1[i], ivector2[i])) err = TRUE; + if(strcmp(ivector1[i], ivector3[i])) err = TRUE; + if(strcmp(ivector1[i], ivector4[i])) err = TRUE; + free(ivector1[i]); + free(ivector2[i]); + free(ivector3[i]); + free(ivector4[i]); + free(ivector5[i]); + } + free(ivector1); + free(ivector2); + free(ivector3); + free(ivector4); + free(ivector5); + if(err) fprintf(stderr, "%s: sorting failed\n", progname); + if(!disp && !err) printfflush("all ok\n\n"); + return err ? 1 : 0; +} + + +/* perform strstr command */ +int dostrstr(int rnum, int disp){ + char *text, buf[RECBUFSIZ], *std, *kmp, *bm; + int i, j, len, err; + text = cbmalloc(TEXTBUFSIZ); + for(i = 0; i < TEXTBUFSIZ - 1; i++){ + text[i] = 'a' + myrand() % ('z' - 'a'); + } + text[i] = '\0'; + err = FALSE; + if(!disp) printfflush("Locating substrings ... "); + for(i = 0; i < rnum; i++){ + len = myrand() % (RECBUFSIZ - 1); + for(j = 0; j < len; j++){ + buf[j] = 'a' + myrand() % ('z' - 'a'); + } + buf[j] = 0; + std = strstr(text, buf); + kmp = cbstrstrkmp(text, buf); + bm = cbstrstrbm(text, buf); + if(kmp != std || bm != std){ + err = TRUE; + break; + } + if(disp && std) printf("%s\n", buf); + } + if(err) fprintf(stderr, "%s: string scanning failed\n", progname); + if(!disp && !err){ + printfflush("ok\n"); + printfflush("all ok\n\n"); + } + free(text); + return err ? 1 : 0; +} + + +/* perform list command */ +int dolist(int rnum, int disp){ + CBLIST *list; + const char *vbuf; + char buf[RECBUFSIZ], *tmp; + int i, err, len, vsiz; + if(!disp) printfflush("\n rnum=%d\n\n", rnum); + list = cblistopen(); + err = FALSE; + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", i); + cblistpush(list, buf, len); + if(!disp && rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + if(disp){ + for(i = 0; i < cblistnum(list); i++){ + if((vbuf = cblistval(list, i, &vsiz)) != NULL){ + printfflush("%s:%d\n", vbuf, vsiz); + } else { + fprintf(stderr, "%s: val error\n", progname); + err = TRUE; + break; + } + } + printfflush("\n"); + while((tmp = cblistpop(list, &vsiz)) != NULL){ + printfflush("%s:%d\n", tmp, vsiz); + free(tmp); + } + } + cblistclose(list); + if(!disp && !err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform list command */ +int domap(int rnum, int bnum, int disp){ + CBMAP *map; + const char *kbuf, *vbuf; + char buf[RECBUFSIZ]; + int i, err, len, ksiz, vsiz; + if(!disp) printfflush("\n rnum=%d bnum=%d\n\n", rnum, bnum); + map = bnum > 0 ? cbmapopenex(bnum) : cbmapopen(); + err = FALSE; + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", i); + if(!cbmapput(map, buf, len, buf, len, FALSE)){ + fprintf(stderr, "%s: put error\n", progname); + err = TRUE; + break; + } + if(!disp && rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + if(disp){ + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", i); + if((vbuf = cbmapget(map, buf, len, &vsiz)) != NULL){ + printfflush("%s:%d\t%s:%d\n", buf, len, vbuf, vsiz); + } else { + fprintf(stderr, "%s: get error\n", progname); + } + } + printfflush("\n"); + cbmapiterinit(map); + while((kbuf = cbmapiternext(map, &ksiz)) != NULL){ + vbuf = cbmapiterval(kbuf, &vsiz); + printfflush("%s:%d\t%s:%d\n", kbuf, ksiz, vbuf, vsiz); + } + } + cbmapclose(map); + if(!disp && !err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform heap command */ +int doheap(int rnum, int max, int disp){ + CBHEAP *heap; + int *orig, *ary; + int i, err, num, anum; + if(!disp) printfflush("\n rnum=%d max=%d\n\n", rnum, max); + orig = disp ? cbmalloc(rnum * sizeof(int) + 1) : NULL; + heap = cbheapopen(sizeof(int), max, intpcmp); + err = FALSE; + for(i = 1; i <= rnum; i++){ + num = myrand() % rnum + 1; + if(orig) orig[i-1] = num; + cbheapinsert(heap, &num); + if(!disp && rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + if(disp){ + for(i = 0; i < cbheapnum(heap); i++){ + printf("%d\n", *(int *)cbheapval(heap, i)); + } + printf("\n"); + qsort(orig, rnum, sizeof(int), intpcmp); + ary = (int *)cbheaptomalloc(heap, &anum); + if(anum != rnum && anum != max) err = TRUE; + for(i = 0; i < anum; i++){ + printf("%d\t%d\n", ary[i], orig[i]); + if(ary[i] != orig[i]) err = TRUE; + } + free(ary); + } else { + cbheapclose(heap); + } + free(orig); + if(!disp && !err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform wicked command */ +int dowicked(int rnum){ + CBLIST *list; + CBMAP *map; + int i, len; + char buf[RECBUFSIZ], *tmp; + printfflush("\n rnum=%d\n\n", rnum); + list = cblistopen(); + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%d", myrand() % rnum + 1); + switch(myrand() % 16){ + case 0: + free(cblistpop(list, NULL)); + putchar('O'); + break; + case 1: + cblistunshift(list, buf, len); + putchar('U'); + break; + case 2: + free(cblistshift(list, NULL)); + putchar('S'); + break; + case 3: + cblistinsert(list, myrand() % (cblistnum(list) + 1), buf, len); + putchar('I'); + break; + case 4: + free(cblistremove(list, myrand() % (cblistnum(list) + 1), NULL)); + putchar('R'); + break; + case 5: + cblistover(list, myrand() % (cblistnum(list) + 1), buf, len); + putchar('V'); + break; + case 6: + tmp = cbmemdup(buf, len); + cblistpushbuf(list, tmp, len); + putchar('B'); + break; + default: + cblistpush(list, buf, len); + putchar('P'); + break; + } + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + cblistclose(list); + map = cbmapopen(); + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%d", myrand() % rnum + 1); + switch(myrand() % 16){ + case 0: + cbmapput(map, buf, len, buf, len, FALSE); + putchar('I'); + break; + case 1: + cbmapputcat(map, buf, len, buf, len); + putchar('C'); + break; + case 2: + cbmapget(map, buf, len, NULL); + putchar('V'); + break; + case 3: + cbmapout(map, buf, len); + putchar('D'); + break; + case 4: + cbmapmove(map, buf, len, myrand() % 2); + putchar('M'); + break; + default: + cbmapput(map, buf, len, buf, len, TRUE); + putchar('O'); + break; + } + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + cbmapclose(map); + printfflush("ok\n\n"); + return 0; +} + + +/* perform misc command */ +int domisc(void){ + CBDATUM *odatum, *ndatum; + CBLIST *olist, *nlist, *elems, *glist; + CBMAP *omap, *nmap, *pairs, *gmap; + int i, j, ssiz, osiz, tsiz, jl; + char kbuf[RECBUFSIZ], vbuf[RECBUFSIZ], *sbuf, spbuf[1024], *tmp, *orig, renc[64]; + const char *op, *np; + time_t t; + printfflush("\n\n"); + printfflush("Checking memory allocation ... "); + tmp = cbmalloc(1024); + for(i = 1; i <= 65536; i *= 2){ + tmp = cbrealloc(tmp, i); + } + cbfree(tmp); + printfflush("ok\n"); + printfflush("Checking basic datum ... "); + odatum = cbdatumopen("x", -1); + for(i = 0; i < 1000; i++){ + cbdatumcat(odatum, "x", 1); + } + cbdatumclose(odatum); + tmp = cbmalloc(3); + memcpy(tmp, "abc", 3); + odatum = cbdatumopenbuf(tmp, 3); + for(i = 0; i < 1000; i++){ + cbdatumcat(odatum, ".", 1); + } + ndatum = cbdatumdup(odatum); + for(i = 0; i < 1000; i++){ + cbdatumcat(ndatum, "*", 1); + } + for(i = 0; i < 1000; i++){ + tmp = cbmalloc(3); + memcpy(tmp, "123", 3); + cbdatumsetbuf(ndatum, tmp, 3); + } + cbdatumprintf(ndatum, "[%s\t%08d\t%08o\t%08x\t%08.1f\t%@\t%?\t%:]", + "mikio", 1978, 1978, 1978, 1978.0211, "<>&#!+-*/%", "<>&#!+-*/%", "<>&#!+-*/%"); + cbdatumclose(ndatum); + cbdatumclose(odatum); + printfflush("ok\n"); + printfflush("Checking serialization of list ... "); + olist = cblistopen(); + for(i = 1; i <= 1000; i++){ + sprintf(vbuf, "%d", i); + cblistpush(olist, vbuf, -1); + } + sbuf = cblistdump(olist, &ssiz); + nlist = cblistload(sbuf, ssiz); + free(sbuf); + for(i = 0; i < cblistnum(olist); i++){ + op = cblistval(olist, i, NULL); + np = cblistval(nlist, i, NULL); + if(!op || !np || strcmp(op, np)){ + cblistclose(nlist); + cblistclose(olist); + fprintf(stderr, "%s: validation failed\n", progname); + return 1; + } + } + cblistclose(nlist); + cblistclose(olist); + printfflush("ok\n"); + printfflush("Checking serialization of map ... "); + omap = cbmapopen(); + for(i = 1; i <= 1000; i++){ + sprintf(kbuf, "%X", i); + sprintf(vbuf, "[%d]", i); + cbmapput(omap, kbuf, -1, vbuf, -1, TRUE); + } + sbuf = cbmapdump(omap, &ssiz); + nmap = cbmapload(sbuf, ssiz); + free(cbmaploadone(sbuf, ssiz, "1", 2, &tsiz)); + free(cbmaploadone(sbuf, ssiz, "33", 2, &tsiz)); + free(sbuf); + cbmapiterinit(omap); + while((op = cbmapiternext(omap, NULL)) != NULL){ + if(!(np = cbmapget(nmap, op, -1, NULL))){ + cbmapclose(nmap); + cbmapclose(omap); + fprintf(stderr, "%s: validation failed\n", progname); + return 1; + } + } + cbmapclose(nmap); + cbmapclose(omap); + printfflush("ok\n"); + printfflush("Checking string utilities ... "); + sprintf(spbuf, "[%08d/%08o/%08u/%08x/%08X/%08.3e/%08.3E/%08.3f/%08.3g/%08.3G/%c/%s/%%]", + 123456, 123456, 123456, 123456, 123456, + 123456.789, 123456.789, 123456.789, 123456.789, 123456.789, + 'A', "hoge"); + tmp = cbsprintf("[%08d/%08o/%08u/%08x/%08X/%08.3e/%08.3E/%08.3f/%08.3g/%08.3G/%c/%s/%%]", + 123456, 123456, 123456, 123456, 123456, + 123456.789, 123456.789, 123456.789, 123456.789, 123456.789, + 'A', "hoge"); + while(strcmp(spbuf, tmp)){ + free(tmp); + fprintf(stderr, "%s: cbsprintf is invalid\n", progname); + return 1; + } + free(tmp); + pairs = cbmapopen(); + cbmapput(pairs, "aa", -1, "AAA", -1, TRUE); + cbmapput(pairs, "bb", -1, "BBB", -1, TRUE); + cbmapput(pairs, "cc", -1, "CCC", -1, TRUE); + cbmapput(pairs, "ZZZ", -1, "z", -1, TRUE); + tmp = cbreplace("[aaaaabbbbbcccccdddddZZZZ]", pairs); + if(strcmp(tmp, "[AAAAAAaBBBBBBbCCCCCCcdddddzZ]")){ + free(tmp); + cbmapclose(pairs); + fprintf(stderr, "%s: cbreplace is invalid\n", progname); + return 1; + } + free(tmp); + cbmapclose(pairs); + elems = cbsplit("aa bb,ccc-dd,", -1, " ,-"); + if(cblistnum(elems) != 5 || strcmp(cblistval(elems, 0, NULL), "aa") || + strcmp(cblistval(elems, 1, NULL), "bb") || strcmp(cblistval(elems, 2, NULL), "ccc") || + strcmp(cblistval(elems, 3, NULL), "dd") || strcmp(cblistval(elems, 4, NULL), "")){ + cblistclose(elems); + fprintf(stderr, "%s: cbsplit is invalid\n", progname); + return 1; + } + cblistclose(elems); + if(cbstricmp("abc", "ABC") || !cbstricmp("abc", "abcd")){ + fprintf(stderr, "%s: cbstricmp is invalid\n", progname); + return 1; + } + if(!cbstrfwmatch("abcd", "abc") || cbstrfwmatch("abc", "abcd")){ + fprintf(stderr, "%s: cbstrfwmatch is invalid\n", progname); + return 1; + } + if(!cbstrfwimatch("abcd", "ABC") || cbstrfwmatch("abc", "ABCD")){ + fprintf(stderr, "%s: cbstrfwimatch is invalid\n", progname); + return 1; + } + if(!cbstrbwmatch("dcba", "cba") || cbstrbwmatch("cba", "dcba")){ + fprintf(stderr, "%s: cbstrbwmatch is invalid\n", progname); + return 1; + } + if(!cbstrbwimatch("dcba", "CBA") || cbstrbwimatch("cba", "DCBA")){ + fprintf(stderr, "%s: cbstrbwimatch is invalid\n", progname); + return 1; + } + tmp = cbmemdup(" \r\n[Quick Database Manager]\r\n ", -1); + if(cbstrtoupper(tmp) != tmp || strcmp(tmp, " \r\n[QUICK DATABASE MANAGER]\r\n ")){ + free(tmp); + fprintf(stderr, "%s: cbstrtoupper is invalid\n", progname); + return 1; + } + if(cbstrtolower(tmp) != tmp || strcmp(tmp, " \r\n[quick database manager]\r\n ")){ + free(tmp); + fprintf(stderr, "%s: cbstrtolower is invalid\n", progname); + return 1; + } + if(cbstrtrim(tmp) != tmp || strcmp(tmp, "[quick database manager]")){ + free(tmp); + fprintf(stderr, "%s: cbstrtrim is invalid\n", progname); + return 1; + } + if(cbstrsqzspc(tmp) != tmp || strcmp(tmp, "[quick database manager]")){ + free(tmp); + fprintf(stderr, "%s: cbstrsqzspc is invalid\n", progname); + return 1; + } + cbstrcututf(tmp, 5); + if(cbstrcountutf(tmp) != 5){ + free(tmp); + fprintf(stderr, "%s: cbstrcututf or cbstrcountutf is invalid\n", progname); + return 1; + } + free(tmp); + printfflush("ok\n"); + printfflush("Checking encoding utilities ... "); + strcpy(spbuf, "My name is \xca\xbf\xce\xd3\xb4\xb4\xcd\xba.\n\n\n"); + tmp = cbbaseencode(spbuf, -1); + orig = cbbasedecode(tmp, &osiz); + if(osiz != strlen(spbuf) || strcmp(orig, spbuf)){ + free(orig); + free(tmp); + fprintf(stderr, "%s: Base64 encoding is invalid\n", progname); + return 1; + } + free(orig); + free(tmp); + strcpy(spbuf, "My name is \xca\xbf\xce\xd3\xb4\xb4\xcd\xba.\n\n\n"); + tmp = cbquoteencode(spbuf, -1); + orig = cbquotedecode(tmp, &osiz); + if(osiz != strlen(spbuf) || strcmp(orig, spbuf)){ + free(orig); + free(tmp); + fprintf(stderr, "%s: quoted-printable encoding is invalid\n", progname); + return 1; + } + free(orig); + free(tmp); + strcpy(spbuf, "My name is \xca\xbf\xce\xd3\xb4\xb4\xcd\xba.\n\n\n"); + tmp = cbmimeencode(spbuf, "ISO-8859-1", TRUE); + orig = cbmimedecode(tmp, renc); + if(osiz != strlen(spbuf) || strcmp(orig, spbuf) || strcmp(renc, "ISO-8859-1")){ + free(orig); + free(tmp); + fprintf(stderr, "%s: MIME encoding is invalid\n", progname); + return 1; + } + free(orig); + free(tmp); + strcpy(spbuf, "\"He says...\r\n\"\"What PROGRAM are they watching?\"\"\""); + tmp = cbcsvunescape(spbuf); + orig = cbcsvescape(tmp); + if(strcmp(orig, spbuf)){ + free(orig); + free(tmp); + fprintf(stderr, "%s: CSV escaping is invalid\n", progname); + return 1; + } + free(orig); + free(tmp); + strcpy(spbuf, "<Nuts&Milk> is "very" surfin'!"); + tmp = cbxmlunescape(spbuf); + orig = cbxmlescape(tmp); + if(strcmp(orig, spbuf)){ + free(orig); + free(tmp); + fprintf(stderr, "%s: XML escaping is invalid\n", progname); + return 1; + } + free(orig); + free(tmp); + printfflush("ok\n"); + printfflush("Checking date utilities ... "); + for(i = 0; i < 200; i++){ + jl = (myrand() % 23) * 1800; + if(myrand() % 2 == 0) jl *= -1; + t = myrand() % (INT_MAX - 3600 * 24 * 365 * 6) + 3600 * 24 * 365 * 5; + tmp = cbdatestrwww(t, jl); + t = cbstrmktime(tmp); + orig = cbdatestrwww(t, jl); + if(strcmp(orig, tmp)){ + free(orig); + free(tmp); + fprintf(stderr, "%s: W3CDTF formatter is invalid\n", progname); + return 1; + } + free(orig); + free(tmp); + tmp = cbdatestrhttp(t, jl); + t = cbstrmktime(tmp); + orig = cbdatestrhttp(t, jl); + if(strcmp(orig, tmp)){ + free(orig); + free(tmp); + fprintf(stderr, "%s: RFC 822 date formatter is invalid\n", progname); + return 1; + } + free(orig); + free(tmp); + } + printfflush("ok\n"); + printfflush("Checking the global garbage collector ... "); + for(i = 0; i < 512; i++){ + glist = cblistopen(); + cbglobalgc(glist, (void (*)(void *))cblistclose); + for(j = 0; j < 10; j++){ + sprintf(kbuf, "%08d", j); + cblistpush(glist, kbuf, -1); + } + gmap = cbmapopen(); + cbglobalgc(gmap, (void (*)(void *))cbmapclose); + for(j = 0; j < 10; j++){ + sprintf(kbuf, "%08d", j); + cbmapput(gmap, kbuf, -1, kbuf, -1, TRUE); + } + if(myrand() % 64 == 0){ + cbvmemavail(100); + cbggcsweep(); + } + } + printfflush("ok\n"); + printfflush("all ok\n\n"); + return 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/configure b/qdbm/configure new file mode 100755 index 00000000..60e3d2fa --- /dev/null +++ b/qdbm/configure @@ -0,0 +1,3913 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.59 for qdbm 1.8.77. +# +# Copyright (C) 2003 Free Software Foundation, Inc. +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' +elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then + set -o posix +fi +DUALCASE=1; export DUALCASE # for MKS sh + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# Work around bugs in pre-3.0 UWIN ksh. +$as_unset ENV MAIL MAILPATH +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1; then + as_expr=expr +else + as_expr=false +fi + +if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)$' \| \ + . : '\(.\)' 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; } + /^X\/\(\/\/\)$/{ s//\1/; q; } + /^X\/\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + + +# PATH needs CR, and LINENO needs CR and PATH. +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x$as_lineno_3" = "x$as_lineno_2" || { + # Find who we are. Look in the path if we contain no path at all + # relative or not. + case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done + + ;; + esac + # We did not find ourselves, most probably we were run as `sh COMMAND' + # in which case we are not to be found in the path. + if test "x$as_myself" = x; then + as_myself=$0 + fi + if test ! -f "$as_myself"; then + { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2 + { (exit 1); exit 1; }; } + fi + case $CONFIG_SHELL in + '') + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for as_base in sh bash ksh sh5; do + case $as_dir in + /*) + if ("$as_dir/$as_base" -c ' + as_lineno_1=$LINENO + as_lineno_2=$LINENO + as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x$as_lineno_3" = "x$as_lineno_2" ') 2>/dev/null; then + $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; } + $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; } + CONFIG_SHELL=$as_dir/$as_base + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$0" ${1+"$@"} + fi;; + esac + done +done +;; + esac + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line before each line; the second 'sed' does the real + # work. The second script uses 'N' to pair each line-number line + # with the numbered line, and appends trailing '-' during + # substitution so that $LINENO is not a special case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # second 'sed' script. Blame Lee E. McMahon for sed's syntax. :-) + sed '=' <$as_myself | + sed ' + N + s,$,-, + : loop + s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3, + t loop + s,-$,, + s,^['$as_cr_digits']*\n,, + ' >$as_me.lineno && + chmod +x $as_me.lineno || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensible to this). + . ./$as_me.lineno + # Exit status is that of the last command. + exit +} + + +case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in + *c*,-n*) ECHO_N= ECHO_C=' +' ECHO_T=' ' ;; + *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; + *) ECHO_N= ECHO_C='\c' ECHO_T= ;; +esac + +if expr a : '\(a\)' >/dev/null 2>&1; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + # We could just check for DJGPP; but this test a) works b) is more generic + # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). + if test -f conf$$.exe; then + # Don't use ln at all; we don't have any links + as_ln_s='cp -p' + else + as_ln_s='ln -s' + fi +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.file + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +as_executable_p="test -f" + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +# IFS +# We need space, tab and new line, in precisely that order. +as_nl=' +' +IFS=" $as_nl" + +# CDPATH. +$as_unset CDPATH + + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +exec 6>&1 + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_config_libobj_dir=. +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} + +# Maximum number of lines to put in a shell here document. +# This variable seems obsolete. It should probably be removed, and +# only ac_max_sed_lines should be used. +: ${ac_max_here_lines=38} + +# Identity of this package. +PACKAGE_NAME='qdbm' +PACKAGE_TARNAME='qdbm' +PACKAGE_VERSION='1.8.77' +PACKAGE_STRING='qdbm 1.8.77' +PACKAGE_BUGREPORT='' + +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT LIBVER LIBREV TARGETS MYDEFS MYOPTS MGWLIBS LD AR LIBOBJS LTLIBOBJS' +ac_subst_files='' + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datadir='${prefix}/share' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +libdir='${exec_prefix}/lib' +includedir='${prefix}/include' +oldincludedir='/usr/include' +infodir='${prefix}/info' +mandir='${prefix}/man' + +ac_prev= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval "$ac_prev=\$ac_option" + ac_prev= + continue + fi + + ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'` + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_option in + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad | --data | --dat | --da) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \ + | --da=*) + datadir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/-/_/g'` + eval "enable_$ac_feature=no" ;; + + -enable-* | --enable-*) + ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/-/_/g'` + case $ac_option in + *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; + *) ac_optarg=yes ;; + esac + eval "enable_$ac_feature='$ac_optarg'" ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst \ + | --locals | --local | --loca | --loc | --lo) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* \ + | --locals=* | --local=* | --loca=* | --loc=* | --lo=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package| sed 's/-/_/g'` + case $ac_option in + *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;; + *) ac_optarg=yes ;; + esac + eval "with_$ac_package='$ac_optarg'" ;; + + -without-* | --without-*) + ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/-/_/g'` + eval "with_$ac_package=no" ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) { echo "$as_me: error: unrecognized option: $ac_option +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 + { (exit 1); exit 1; }; } + ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` + eval "$ac_envvar='$ac_optarg'" + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + { echo "$as_me: error: missing argument to $ac_option" >&2 + { (exit 1); exit 1; }; } +fi + +# Be sure to have absolute paths. +for ac_var in exec_prefix prefix +do + eval ac_val=$`echo $ac_var` + case $ac_val in + [\\/$]* | ?:[\\/]* | NONE | '' ) ;; + *) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; };; + esac +done + +# Be sure to have absolute paths. +for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \ + localstatedir libdir includedir oldincludedir infodir mandir +do + eval ac_val=$`echo $ac_var` + case $ac_val in + [\\/$]* | ?:[\\/]* ) ;; + *) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; };; + esac +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then its parent. + ac_confdir=`(dirname "$0") 2>/dev/null || +$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$0" : 'X\(//\)[^/]' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| \ + . : '\(.\)' 2>/dev/null || +echo X"$0" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } + /^X\(\/\/\)[^/].*/{ s//\1/; q; } + /^X\(\/\/\)$/{ s//\1/; q; } + /^X\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r $srcdir/$ac_unique_file; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r $srcdir/$ac_unique_file; then + if test "$ac_srcdir_defaulted" = yes; then + { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2 + { (exit 1); exit 1; }; } + else + { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 + { (exit 1); exit 1; }; } + fi +fi +(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null || + { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2 + { (exit 1); exit 1; }; } +srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'` +ac_env_build_alias_set=${build_alias+set} +ac_env_build_alias_value=$build_alias +ac_cv_env_build_alias_set=${build_alias+set} +ac_cv_env_build_alias_value=$build_alias +ac_env_host_alias_set=${host_alias+set} +ac_env_host_alias_value=$host_alias +ac_cv_env_host_alias_set=${host_alias+set} +ac_cv_env_host_alias_value=$host_alias +ac_env_target_alias_set=${target_alias+set} +ac_env_target_alias_value=$target_alias +ac_cv_env_target_alias_set=${target_alias+set} +ac_cv_env_target_alias_value=$target_alias +ac_env_CC_set=${CC+set} +ac_env_CC_value=$CC +ac_cv_env_CC_set=${CC+set} +ac_cv_env_CC_value=$CC +ac_env_CFLAGS_set=${CFLAGS+set} +ac_env_CFLAGS_value=$CFLAGS +ac_cv_env_CFLAGS_set=${CFLAGS+set} +ac_cv_env_CFLAGS_value=$CFLAGS +ac_env_LDFLAGS_set=${LDFLAGS+set} +ac_env_LDFLAGS_value=$LDFLAGS +ac_cv_env_LDFLAGS_set=${LDFLAGS+set} +ac_cv_env_LDFLAGS_value=$LDFLAGS +ac_env_CPPFLAGS_set=${CPPFLAGS+set} +ac_env_CPPFLAGS_value=$CPPFLAGS +ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set} +ac_cv_env_CPPFLAGS_value=$CPPFLAGS + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures qdbm 1.8.77 to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +_ACEOF + + cat <<_ACEOF +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --datadir=DIR read-only architecture-independent data [PREFIX/share] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --infodir=DIR info documentation [PREFIX/info] + --mandir=DIR man documentation [PREFIX/man] +_ACEOF + + cat <<\_ACEOF +_ACEOF +fi + +if test -n "$ac_init_help"; then + case $ac_init_help in + short | recursive ) echo "Configuration of qdbm 1.8.77:";; + esac + cat <<\_ACEOF + +Optional Features: + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-debug build for debugging + --enable-devel build for development + --enable-stable build for stable release + --enable-pthread use POSIX thread and make APIs thread-safe + --disable-lock build for environments without file locking + --disable-mmap build for environments without memory mapping + --enable-zlib feature ZLIB for B+ tree and inverted index + --enable-lzo feature LZO for B+ tree and inverted index + --enable-bzip feature BZIP2 for B+ tree and inverted index + --enable-iconv feature ICONV utilities + --disable-warn hide warnings in the configuration + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + CPPFLAGS C/C++ preprocessor flags, e.g. -I if you have + headers in a nonstandard directory + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +_ACEOF +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + ac_popdir=`pwd` + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d $ac_dir || continue + ac_builddir=. + +if test "$ac_dir" != .; then + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A "../" for each directory in $ac_dir_suffix. + ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'` +else + ac_dir_suffix= ac_top_builddir= +fi + +case $srcdir in + .) # No --srcdir option. We are building in place. + ac_srcdir=. + if test -z "$ac_top_builddir"; then + ac_top_srcdir=. + else + ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'` + fi ;; + [\\/]* | ?:[\\/]* ) # Absolute path. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir ;; + *) # Relative path. + ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_builddir$srcdir ;; +esac + +# Do not use `cd foo && pwd` to compute absolute paths, because +# the directories may not exist. +case `pwd` in +.) ac_abs_builddir="$ac_dir";; +*) + case "$ac_dir" in + .) ac_abs_builddir=`pwd`;; + [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";; + *) ac_abs_builddir=`pwd`/"$ac_dir";; + esac;; +esac +case $ac_abs_builddir in +.) ac_abs_top_builddir=${ac_top_builddir}.;; +*) + case ${ac_top_builddir}. in + .) ac_abs_top_builddir=$ac_abs_builddir;; + [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;; + *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;; + esac;; +esac +case $ac_abs_builddir in +.) ac_abs_srcdir=$ac_srcdir;; +*) + case $ac_srcdir in + .) ac_abs_srcdir=$ac_abs_builddir;; + [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;; + *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;; + esac;; +esac +case $ac_abs_builddir in +.) ac_abs_top_srcdir=$ac_top_srcdir;; +*) + case $ac_top_srcdir in + .) ac_abs_top_srcdir=$ac_abs_builddir;; + [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;; + *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;; + esac;; +esac + + cd $ac_dir + # Check for guested configure; otherwise get Cygnus style configure. + if test -f $ac_srcdir/configure.gnu; then + echo + $SHELL $ac_srcdir/configure.gnu --help=recursive + elif test -f $ac_srcdir/configure; then + echo + $SHELL $ac_srcdir/configure --help=recursive + elif test -f $ac_srcdir/configure.ac || + test -f $ac_srcdir/configure.in; then + echo + $ac_configure --help + else + echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi + cd $ac_popdir + done +fi + +test -n "$ac_init_help" && exit 0 +if $ac_init_version; then + cat <<\_ACEOF +qdbm configure 1.8.77 +generated by GNU Autoconf 2.59 + +Copyright (C) 2003 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit 0 +fi +exec 5>config.log +cat >&5 <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by qdbm $as_me 1.8.77, which was +generated by GNU Autoconf 2.59. Invocation command line was + + $ $0 $@ + +_ACEOF +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +hostinfo = `(hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + echo "PATH: $as_dir" +done + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_sep= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*) + ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; + 2) + ac_configure_args1="$ac_configure_args1 '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'" + # Get rid of the leading space. + ac_sep=" " + ;; + esac + done +done +$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } +$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Be sure not to use single quotes in there, as some shells, +# such as our DU 5.0 friend, will then `close' the trap. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + cat <<\_ASBOX +## ---------------- ## +## Cache variables. ## +## ---------------- ## +_ASBOX + echo + # The following way of writing the cache mishandles newlines in values, +{ + (set) 2>&1 | + case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in + *ac_space=\ *) + sed -n \ + "s/'"'"'/'"'"'\\\\'"'"''"'"'/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p" + ;; + *) + sed -n \ + "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" + ;; + esac; +} + echo + + cat <<\_ASBOX +## ----------------- ## +## Output variables. ## +## ----------------- ## +_ASBOX + echo + for ac_var in $ac_subst_vars + do + eval ac_val=$`echo $ac_var` + echo "$ac_var='"'"'$ac_val'"'"'" + done | sort + echo + + if test -n "$ac_subst_files"; then + cat <<\_ASBOX +## ------------- ## +## Output files. ## +## ------------- ## +_ASBOX + echo + for ac_var in $ac_subst_files + do + eval ac_val=$`echo $ac_var` + echo "$ac_var='"'"'$ac_val'"'"'" + done | sort + echo + fi + + if test -s confdefs.h; then + cat <<\_ASBOX +## ----------- ## +## confdefs.h. ## +## ----------- ## +_ASBOX + echo + sed "/^$/d" confdefs.h | sort + echo + fi + test "$ac_signal" != 0 && + echo "$as_me: caught signal $ac_signal" + echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core && + rm -rf conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status + ' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -rf conftest* confdefs.h +# AIX cpp loses on an empty file, so make sure it contains at least a newline. +echo >confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer explicitly selected file to automatically selected ones. +if test -z "$CONFIG_SITE"; then + if test "x$prefix" != xNONE; then + CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" + else + CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" + fi +fi +for ac_site_file in $CONFIG_SITE; do + if test -r "$ac_site_file"; then + { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 +echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special + # files actually), so we avoid doing that. + if test -f "$cache_file"; then + { echo "$as_me:$LINENO: loading cache $cache_file" >&5 +echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . $cache_file;; + *) . ./$cache_file;; + esac + fi +else + { echo "$as_me:$LINENO: creating cache $cache_file" >&5 +echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in `(set) 2>&1 | + sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val="\$ac_cv_env_${ac_var}_value" + eval ac_new_val="\$ac_env_${ac_var}_value" + case $ac_old_set,$ac_new_set in + set,) + { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 +echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { echo "$as_me:$LINENO: former value: $ac_old_val" >&5 +echo "$as_me: former value: $ac_old_val" >&2;} + { echo "$as_me:$LINENO: current value: $ac_new_val" >&5 +echo "$as_me: current value: $ac_new_val" >&2;} + ac_cache_corrupted=: + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*) + ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 +echo "$as_me: error: changes in the environment can compromise the build" >&2;} + { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 +echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} + { (exit 1); exit 1; }; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# Export variables +LIBVER=14 +LIBREV=13 +TARGETS="all" +MYDEFS="" +MYOPTS="" +MGWLIBS="" +LD="ld" +AR="ar" + +# Building paths +pathtmp="$PATH" +PATH="$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" +PATH="$PATH:/usr/ccs/bin:/usr/ucb:/usr/xpg4/bin:/usr/xpg6/bin:$pathtmp" +LIBRARY_PATH="$HOME/lib:/usr/local/lib:$LIBRARY_PATH" +LD_LIBRARY_PATH="$HOME/lib:/usr/local/lib:$LD_LIBRARY_PATH" +CPATH="$HOME/include:/usr/local/include:$CPATH" +export PATH LIBRARY_PATH LD_LIBRARY_PATH CPATH + + + +#================================================================ +# Options +#================================================================ + + +# Internal variables +enables="" +ispthread="" +iszlib="" +isiconv="" +isnowarn="" + +# Debug mode +# Check whether --enable-debug or --disable-debug was given. +if test "${enable_debug+set}" = set; then + enableval="$enable_debug" + +fi; +if test "$enable_debug" = "yes" +then + TARGETS="debug" + enables="$enables (debug)" +fi + +# Developping mode +# Check whether --enable-devel or --disable-devel was given. +if test "${enable_devel+set}" = set; then + enableval="$enable_devel" + +fi; +if test "$enable_devel" = "yes" +then + TARGETS="devel" + enables="$enables (devel)" +fi + +# Stable mode +# Check whether --enable-stable or --disable-stable was given. +if test "${enable_stable+set}" = set; then + enableval="$enable_stable" + +fi; +if test "$enable_stable" = "yes" +then + TARGETS="stable" + enables="$enables (stable)" +fi + +# Enable POSIX thread +# Check whether --enable-pthread or --disable-pthread was given. +if test "${enable_pthread+set}" = set; then + enableval="$enable_pthread" + +fi; +if test "$enable_pthread" = "yes" +then + MYDEFS="$MYDEFS -DMYPTHREAD" + enables="$enables (pthread)" + ispthread="yes" +fi + +# Disable file locking +# Check whether --enable-lock or --disable-lock was given. +if test "${enable_lock+set}" = set; then + enableval="$enable_lock" + +fi; +if test "$enable_lock" = "no" +then + MYDEFS="$MYDEFS -DMYNOLOCK" + enables="$enables (no-lock)" +fi + +# Disable memory mapping +# Check whether --enable-mmap or --disable-mmap was given. +if test "${enable_mmap+set}" = set; then + enableval="$enable_mmap" + +fi; +if test "$enable_mmap" = "no" +then + MYDEFS="$MYDEFS -DMYNOMMAP" + enables="$enables (no-mmap)" +fi + +# Enable ZLIB compression +# Check whether --enable-zlib or --disable-zlib was given. +if test "${enable_zlib+set}" = set; then + enableval="$enable_zlib" + +fi; +if test "$enable_zlib" = "yes" +then + MYDEFS="$MYDEFS -DMYZLIB" + MGWLIBS="-lz $MGWLIBS" + enables="$enables (zlib)" + iszlib="yes" +fi + +# Enable LZO compression +# Check whether --enable-lzo or --disable-lzo was given. +if test "${enable_lzo+set}" = set; then + enableval="$enable_lzo" + +fi; +if test "$enable_lzo" = "yes" +then + MYDEFS="$MYDEFS -DMYLZO" + MGWLIBS="-llzo2 $MGWLIBS" + enables="$enables (lzo)" + islzo="yes" +fi + +# Enable BZIP2 compression +# Check whether --enable-bzip or --disable-bzip was given. +if test "${enable_bzip+set}" = set; then + enableval="$enable_bzip" + +fi; +if test "$enable_bzip" = "yes" +then + MYDEFS="$MYDEFS -DMYBZIP" + MGWLIBS="-lbz2 $MGWLIBS" + enables="$enables (bzip)" + isbzip="yes" +fi + +# Enable ICONV utilities +# Check whether --enable-iconv or --disable-iconv was given. +if test "${enable_iconv+set}" = set; then + enableval="$enable_iconv" + +fi; +if test "$enable_iconv" = "yes" +then + MYDEFS="$MYDEFS -DMYICONV" + MGWLIBS="-liconv $MGWLIBS" + enables="$enables (iconv)" + isiconv="yes" +fi + +# No warning configuration +# Check whether --enable-warn or --disable-warn was given. +if test "${enable_warn+set}" = set; then + enableval="$enable_warn" + +fi; +if test "$enable_warn" = "no" +then + isnowarn="yes" +fi + +# Messages +printf '#================================================================\n' +printf '# Configuring QDBM version %s%s.\n' "$PACKAGE_VERSION" "$enables" +printf '#================================================================\n' + + + +#================================================================ +# Checking Commands to Build with +#================================================================ + + +# C compiler +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + CC=$ac_ct_CC +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + CC=$ac_ct_CC +else + CC="$ac_cv_prog_CC" +fi + +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + + test -n "$ac_ct_CC" && break +done + + CC=$ac_ct_CC +fi + +fi + + +test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&5 +echo "$as_me: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + +# Provide some information about the compiler. +echo "$as_me:$LINENO:" \ + "checking for C compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 + (eval $ac_compiler --version &5) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v &5\"") >&5 + (eval $ac_compiler -v &5) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V &5\"") >&5 + (eval $ac_compiler -V &5) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +echo "$as_me:$LINENO: checking for C compiler default output file name" >&5 +echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6 +ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` +if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5 + (eval $ac_link_default) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # Find the output, starting from the most likely. This scheme is +# not robust to junk in `.', hence go to wildcards (a.*) only as a last +# resort. + +# Be careful to initialize this variable, since it used to be cached. +# Otherwise an old cache value of `no' led to `EXEEXT = no' in a Makefile. +ac_cv_exeext= +# b.out is created by i960 compilers. +for ac_file in a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) + ;; + conftest.$ac_ext ) + # This is the source file. + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + # FIXME: I believe we export ac_cv_exeext for Libtool, + # but it would be cool to find out if it's true. Does anybody + # maintain Libtool? --akim. + export ac_cv_exeext + break;; + * ) + break;; + esac +done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: C compiler cannot create executables +See \`config.log' for more details." >&5 +echo "$as_me: error: C compiler cannot create executables +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } +fi + +ac_exeext=$ac_cv_exeext +echo "$as_me:$LINENO: result: $ac_file" >&5 +echo "${ECHO_T}$ac_file" >&6 + +# Check the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +echo "$as_me:$LINENO: checking whether the C compiler works" >&5 +echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6 +# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 +# If not cross compiling, check that we can run a simple program. +if test "$cross_compiling" != yes; then + if { ac_try='./$ac_file' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { echo "$as_me:$LINENO: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + fi + fi +fi +echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6 + +rm -f a.out a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +# Check the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +echo "$as_me:$LINENO: checking whether we are cross compiling" >&5 +echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6 +echo "$as_me:$LINENO: result: $cross_compiling" >&5 +echo "${ECHO_T}$cross_compiling" >&6 + +echo "$as_me:$LINENO: checking for suffix of executables" >&5 +echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6 +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + export ac_cv_exeext + break;; + * ) break;; + esac +done +else + { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest$ac_cv_exeext +echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5 +echo "${ECHO_T}$ac_cv_exeext" >&6 + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +echo "$as_me:$LINENO: checking for suffix of object files" >&5 +echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6 +if test "${ac_cv_objext+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_objext" >&5 +echo "${ECHO_T}$ac_cv_objext" >&6 +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6 +if test "${ac_cv_c_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_compiler_gnu=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_compiler_gnu=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6 +GCC=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +CFLAGS="-g" +echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 +echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6 +if test "${ac_cv_prog_cc_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_prog_cc_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_prog_cc_g=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_g" >&6 +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +echo "$as_me:$LINENO: checking for $CC option to accept ANSI C" >&5 +echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6 +if test "${ac_cv_prog_cc_stdc+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_prog_cc_stdc=no +ac_save_CC=$CC +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std1 is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std1. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +# Don't try gcc -ansi; that turns off useful extensions and +# breaks some systems' header files. +# AIX -qlanglvl=ansi +# Ultrix and OSF/1 -std1 +# HP-UX 10.20 and later -Ae +# HP-UX older versions -Aa -D_HPUX_SOURCE +# SVR4 -Xc -D__EXTENSIONS__ +for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_prog_cc_stdc=$ac_arg +break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.err conftest.$ac_objext +done +rm -f conftest.$ac_ext conftest.$ac_objext +CC=$ac_save_CC + +fi + +case "x$ac_cv_prog_cc_stdc" in + x|xno) + echo "$as_me:$LINENO: result: none needed" >&5 +echo "${ECHO_T}none needed" >&6 ;; + *) + echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6 + CC="$CC $ac_cv_prog_cc_stdc" ;; +esac + +# Some people use a C++ compiler to compile C. Since we use `exit', +# in C++ we need to declare it. In case someone uses the same compiler +# for both compiling C and C++ we need to have the C++ compiler decide +# the declaration of exit, since it's the most demanding environment. +cat >conftest.$ac_ext <<_ACEOF +#ifndef __cplusplus + choke me +#endif +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + for ac_declaration in \ + '' \ + 'extern "C" void std::exit (int) throw (); using std::exit;' \ + 'extern "C" void std::exit (int); using std::exit;' \ + 'extern "C" void exit (int) throw ();' \ + 'extern "C" void exit (int);' \ + 'void exit (int);' +do + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_declaration +#include +int +main () +{ +exit (42); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +continue +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_declaration +int +main () +{ +exit (42); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +done +rm -f conftest* +if test -n "$ac_declaration"; then + echo '#ifdef __cplusplus' >>confdefs.h + echo $ac_declaration >>confdefs.h + echo '#endif' >>confdefs.h +fi + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +if test "$GCC" != "yes" +then + if test "$isnowarn" != "yes" + then + printf '#================================================================\n' 1>&2 + printf '# WARNING: GCC is required to build this package.\n' 1>&2 + printf '#================================================================\n' 1>&2 + fi +fi +if uname | egrep -i 'Linux' > /dev/null 2>&1 && + uname -m | egrep '(x|i)(3|4|5|6|7|8|9)?86' > /dev/null 2>&1 +then + MYOPTS="-minline-all-stringops" +fi +if uname | egrep -i 'SunOS' > /dev/null 2>&1 +then + MYOPTS="-O1 -fno-omit-frame-pointer -fno-force-addr" +fi +if uname | egrep -i 'BSD' > /dev/null 2>&1 +then + MYOPTS="-O1 -fno-omit-frame-pointer -fno-force-addr" +fi +if gcc --version | egrep -i '^2\.(8|9)' > /dev/null 2>&1 +then + MYOPTS="-O1 -fno-omit-frame-pointer -fno-force-addr" +fi + +# Linker +printf 'checking for ld... ' +if which ld | grep '/ld$' > /dev/null 2>&1 +then + LD=`which ld` + printf '%s\n' "$LD" +else + printf 'no\n' + if test "$isnowarn" != "yes" + then + printf '#================================================================\n' 1>&2 + printf '# WARNING: ld is not found in PATH.\n' 1>&2 + printf '#================================================================\n' 1>&2 + fi +fi + +# Archiver +printf 'checking for ar... ' +if which ar | grep '/ar$' > /dev/null 2>&1 +then + AR=`which ar` + printf '%s\n' "$AR" +else + printf 'no\n' + if test "$isnowarn" != "yes" + then + printf '#================================================================\n' 1>&2 + printf '# WARNING: ar is not found in PATH.\n' 1>&2 + printf '#================================================================\n' 1>&2 + fi +fi + + + +#================================================================ +# Checking Libraries +#================================================================ + + +# Underlying libraries + + +echo "$as_me:$LINENO: checking for main in -lc" >&5 +echo $ECHO_N "checking for main in -lc... $ECHO_C" >&6 +if test "${ac_cv_lib_c_main+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lc $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + +int +main () +{ +main (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_c_main=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_c_main=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_c_main" >&5 +echo "${ECHO_T}$ac_cv_lib_c_main" >&6 +if test $ac_cv_lib_c_main = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBC 1 +_ACEOF + + LIBS="-lc $LIBS" + +fi + + +# for pthread +if test "$ispthread" = "yes" +then + +echo "$as_me:$LINENO: checking for main in -lpthread" >&5 +echo $ECHO_N "checking for main in -lpthread... $ECHO_C" >&6 +if test "${ac_cv_lib_pthread_main+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpthread $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + +int +main () +{ +main (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_pthread_main=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_pthread_main=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_pthread_main" >&5 +echo "${ECHO_T}$ac_cv_lib_pthread_main" >&6 +if test $ac_cv_lib_pthread_main = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBPTHREAD 1 +_ACEOF + + LIBS="-lpthread $LIBS" + +fi + +fi + +# for zlib +if test "$iszlib" = "yes" +then + +echo "$as_me:$LINENO: checking for main in -lz" >&5 +echo $ECHO_N "checking for main in -lz... $ECHO_C" >&6 +if test "${ac_cv_lib_z_main+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lz $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + +int +main () +{ +main (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_z_main=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_z_main=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_z_main" >&5 +echo "${ECHO_T}$ac_cv_lib_z_main" >&6 +if test $ac_cv_lib_z_main = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBZ 1 +_ACEOF + + LIBS="-lz $LIBS" + +fi + +fi + +# for lzo +if test "$islzo" = "yes" +then + +echo "$as_me:$LINENO: checking for main in -llzo2" >&5 +echo $ECHO_N "checking for main in -llzo2... $ECHO_C" >&6 +if test "${ac_cv_lib_lzo2_main+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-llzo2 $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + +int +main () +{ +main (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_lzo2_main=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_lzo2_main=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_lzo2_main" >&5 +echo "${ECHO_T}$ac_cv_lib_lzo2_main" >&6 +if test $ac_cv_lib_lzo2_main = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBLZO2 1 +_ACEOF + + LIBS="-llzo2 $LIBS" + +fi + +fi + +# for bzip +if test "$isbzip" = "yes" +then + +echo "$as_me:$LINENO: checking for main in -lbz2" >&5 +echo $ECHO_N "checking for main in -lbz2... $ECHO_C" >&6 +if test "${ac_cv_lib_bz2_main+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lbz2 $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + +int +main () +{ +main (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_bz2_main=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_bz2_main=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_bz2_main" >&5 +echo "${ECHO_T}$ac_cv_lib_bz2_main" >&6 +if test $ac_cv_lib_bz2_main = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBBZ2 1 +_ACEOF + + LIBS="-lbz2 $LIBS" + +fi + +fi + +# for iconv +if test "$isiconv" = "yes" +then + +echo "$as_me:$LINENO: checking for main in -liconv" >&5 +echo $ECHO_N "checking for main in -liconv... $ECHO_C" >&6 +if test "${ac_cv_lib_iconv_main+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-liconv $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + +int +main () +{ +main (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_iconv_main=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_iconv_main=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_iconv_main" >&5 +echo "${ECHO_T}$ac_cv_lib_iconv_main" >&6 +if test $ac_cv_lib_iconv_main = yes; then + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBICONV 1 +_ACEOF + + LIBS="-liconv $LIBS" + +fi + +fi + +# For old BSDs +if test "$ispthread" = "yes" && uname -a | grep BSD > /dev/null && + test -f /usr/lib/libc_r.a && test ! -f /usr/lib/libpthread.a +then + LIBS=`printf '%s' "$LIBS" | sed 's/-lc/-lc_r/g'` +fi + +# Duplication of QDBM for C +echo "$as_me:$LINENO: checking for main in -lqdbm" >&5 +echo $ECHO_N "checking for main in -lqdbm... $ECHO_C" >&6 +if test "${ac_cv_lib_qdbm_main+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lqdbm $LIBS" +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + +int +main () +{ +main (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_qdbm_main=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_qdbm_main=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_qdbm_main" >&5 +echo "${ECHO_T}$ac_cv_lib_qdbm_main" >&6 +if test $ac_cv_lib_qdbm_main = yes; then + if test "$isnowarn" != "yes" + then + printf '#================================================================\n' 1>&2 + printf '# WARNING: The existing library was detected.\n' 1>&2 + printf '#================================================================\n' 1>&2 + fi + +fi + + + + +#================================================================ +# Generic Settings +#================================================================ + + +# Export variables + + + + + + + + + + + +# Targets + ac_config_files="$ac_config_files Makefile LTmakefile qdbm.spec qdbm.pc" +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, don't put newlines in cache variables' values. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +{ + (set) 2>&1 | + case `(ac_space=' '; set | grep ac_space) 2>&1` in + *ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n \ + "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p" + ;; + esac; +} | + sed ' + t clear + : clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + : end' >>confcache +if diff $cache_file confcache >/dev/null 2>&1; then :; else + if test -w $cache_file; then + test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file" + cat confcache >$cache_file + else + echo "not updating unwritable cache $cache_file" + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/; +s/:*\${srcdir}:*/:/; +s/:*@srcdir@:*/:/; +s/^\([^=]*=[ ]*\):*/\1/; +s/:*$//; +s/^[^=]*=[ ]*$//; +}' +fi + +# Transform confdefs.h into DEFS. +# Protect against shell expansion while executing Makefile rules. +# Protect against Makefile macro expansion. +# +# If the first sed substitution is executed (which looks for macros that +# take arguments), then we branch to the quote section. Otherwise, +# look for a macro that doesn't take arguments. +cat >confdef2opt.sed <<\_ACEOF +t clear +: clear +s,^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\),-D\1=\2,g +t quote +s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\),-D\1=\2,g +t quote +d +: quote +s,[ `~#$^&*(){}\\|;'"<>?],\\&,g +s,\[,\\&,g +s,\],\\&,g +s,\$,$$,g +p +_ACEOF +# We use echo to avoid assuming a particular line-breaking character. +# The extra dot is to prevent the shell from consuming trailing +# line-breaks from the sub-command output. A line-break within +# single-quotes doesn't work because, if this script is created in a +# platform that uses two characters for line-breaks (e.g., DOS), tr +# would break. +ac_LF_and_DOT=`echo; echo .` +DEFS=`sed -n -f confdef2opt.sed confdefs.h | tr "$ac_LF_and_DOT" ' .'` +rm -f confdef2opt.sed + + +ac_libobjs= +ac_ltlibobjs= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_i=`echo "$ac_i" | + sed 's/\$U\././;s/\.o$//;s/\.obj$//'` + # 2. Add them. + ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext" + ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + + +: ${CONFIG_STATUS=./config.status} +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5 +echo "$as_me: creating $CONFIG_STATUS" >&6;} +cat >$CONFIG_STATUS <<_ACEOF +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' +elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then + set -o posix +fi +DUALCASE=1; export DUALCASE # for MKS sh + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# Work around bugs in pre-3.0 UWIN ksh. +$as_unset ENV MAIL MAILPATH +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1; then + as_expr=expr +else + as_expr=false +fi + +if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)$' \| \ + . : '\(.\)' 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; } + /^X\/\(\/\/\)$/{ s//\1/; q; } + /^X\/\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + + +# PATH needs CR, and LINENO needs CR and PATH. +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x$as_lineno_3" = "x$as_lineno_2" || { + # Find who we are. Look in the path if we contain no path at all + # relative or not. + case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done + + ;; + esac + # We did not find ourselves, most probably we were run as `sh COMMAND' + # in which case we are not to be found in the path. + if test "x$as_myself" = x; then + as_myself=$0 + fi + if test ! -f "$as_myself"; then + { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5 +echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;} + { (exit 1); exit 1; }; } + fi + case $CONFIG_SHELL in + '') + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for as_base in sh bash ksh sh5; do + case $as_dir in + /*) + if ("$as_dir/$as_base" -c ' + as_lineno_1=$LINENO + as_lineno_2=$LINENO + as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null` + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x$as_lineno_3" = "x$as_lineno_2" ') 2>/dev/null; then + $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; } + $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; } + CONFIG_SHELL=$as_dir/$as_base + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$0" ${1+"$@"} + fi;; + esac + done +done +;; + esac + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line before each line; the second 'sed' does the real + # work. The second script uses 'N' to pair each line-number line + # with the numbered line, and appends trailing '-' during + # substitution so that $LINENO is not a special case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # second 'sed' script. Blame Lee E. McMahon for sed's syntax. :-) + sed '=' <$as_myself | + sed ' + N + s,$,-, + : loop + s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3, + t loop + s,-$,, + s,^['$as_cr_digits']*\n,, + ' >$as_me.lineno && + chmod +x $as_me.lineno || + { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5 +echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;} + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensible to this). + . ./$as_me.lineno + # Exit status is that of the last command. + exit +} + + +case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in + *c*,-n*) ECHO_N= ECHO_C=' +' ECHO_T=' ' ;; + *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; + *) ECHO_N= ECHO_C='\c' ECHO_T= ;; +esac + +if expr a : '\(a\)' >/dev/null 2>&1; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + # We could just check for DJGPP; but this test a) works b) is more generic + # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04). + if test -f conf$$.exe; then + # Don't use ln at all; we don't have any links + as_ln_s='cp -p' + else + as_ln_s='ln -s' + fi +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.file + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +as_executable_p="test -f" + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +# IFS +# We need space, tab and new line, in precisely that order. +as_nl=' +' +IFS=" $as_nl" + +# CDPATH. +$as_unset CDPATH + +exec 6>&1 + +# Open the log real soon, to keep \$[0] and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. Logging --version etc. is OK. +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX +} >&5 +cat >&5 <<_CSEOF + +This file was extended by qdbm $as_me 1.8.77, which was +generated by GNU Autoconf 2.59. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +_CSEOF +echo "on `(hostname || uname -n) 2>/dev/null | sed 1q`" >&5 +echo >&5 +_ACEOF + +# Files that config.status was made for. +if test -n "$ac_config_files"; then + echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS +fi + +if test -n "$ac_config_headers"; then + echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS +fi + +if test -n "$ac_config_links"; then + echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS +fi + +if test -n "$ac_config_commands"; then + echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS +fi + +cat >>$CONFIG_STATUS <<\_ACEOF + +ac_cs_usage="\ +\`$as_me' instantiates files from templates according to the +current configuration. + +Usage: $0 [OPTIONS] [FILE]... + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + +Configuration files: +$config_files + +Report bugs to ." +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF +ac_cs_version="\\ +qdbm config.status 1.8.77 +configured by $0, generated by GNU Autoconf 2.59, + with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" + +Copyright (C) 2003 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." +srcdir=$srcdir +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If no file are specified by the user, then we need to provide default +# value. By we need to know if files were specified by the user. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "x$1" : 'x\([^=]*\)='` + ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` + ac_shift=: + ;; + -*) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + *) # This is not an option, so the user has probably given explicit + # arguments. + ac_option=$1 + ac_need_defaults=false;; + esac + + case $ac_option in + # Handling of the options. +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --vers* | -V ) + echo "$ac_cs_version"; exit 0 ;; + --he | --h) + # Conflict between --help and --header + { { echo "$as_me:$LINENO: error: ambiguous option: $1 +Try \`$0 --help' for more information." >&5 +echo "$as_me: error: ambiguous option: $1 +Try \`$0 --help' for more information." >&2;} + { (exit 1); exit 1; }; };; + --help | --hel | -h ) + echo "$ac_cs_usage"; exit 0 ;; + --debug | --d* | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + CONFIG_FILES="$CONFIG_FILES $ac_optarg" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg" + ac_need_defaults=false;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) { { echo "$as_me:$LINENO: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&5 +echo "$as_me: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&2;} + { (exit 1); exit 1; }; } ;; + + *) ac_config_targets="$ac_config_targets $1" ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +if \$ac_cs_recheck; then + echo "running $SHELL $0 " $ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6 + exec $SHELL $0 $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion +fi + +_ACEOF + + + + + +cat >>$CONFIG_STATUS <<\_ACEOF +for ac_config_target in $ac_config_targets +do + case "$ac_config_target" in + # Handling of arguments. + "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;; + "LTmakefile" ) CONFIG_FILES="$CONFIG_FILES LTmakefile" ;; + "qdbm.spec" ) CONFIG_FILES="$CONFIG_FILES qdbm.spec" ;; + "qdbm.pc" ) CONFIG_FILES="$CONFIG_FILES qdbm.pc" ;; + *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 +echo "$as_me: error: invalid argument: $ac_config_target" >&2;} + { (exit 1); exit 1; }; };; + esac +done + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason to put it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Create a temporary directory, and hook for its removal unless debugging. +$debug || +{ + trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 + trap '{ (exit 1); exit 1; }' 1 2 13 15 +} + +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./confstat$$-$RANDOM + (umask 077 && mkdir $tmp) +} || +{ + echo "$me: cannot create a temporary directory in ." >&2 + { (exit 1); exit 1; } +} + +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF + +# +# CONFIG_FILES section. +# + +# No need to generate the scripts if there are no CONFIG_FILES. +# This happens for instance when ./config.status config.h +if test -n "\$CONFIG_FILES"; then + # Protect against being on the right side of a sed subst in config.status. + sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g; + s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF +s,@SHELL@,$SHELL,;t t +s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t +s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t +s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t +s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t +s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t +s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t +s,@exec_prefix@,$exec_prefix,;t t +s,@prefix@,$prefix,;t t +s,@program_transform_name@,$program_transform_name,;t t +s,@bindir@,$bindir,;t t +s,@sbindir@,$sbindir,;t t +s,@libexecdir@,$libexecdir,;t t +s,@datadir@,$datadir,;t t +s,@sysconfdir@,$sysconfdir,;t t +s,@sharedstatedir@,$sharedstatedir,;t t +s,@localstatedir@,$localstatedir,;t t +s,@libdir@,$libdir,;t t +s,@includedir@,$includedir,;t t +s,@oldincludedir@,$oldincludedir,;t t +s,@infodir@,$infodir,;t t +s,@mandir@,$mandir,;t t +s,@build_alias@,$build_alias,;t t +s,@host_alias@,$host_alias,;t t +s,@target_alias@,$target_alias,;t t +s,@DEFS@,$DEFS,;t t +s,@ECHO_C@,$ECHO_C,;t t +s,@ECHO_N@,$ECHO_N,;t t +s,@ECHO_T@,$ECHO_T,;t t +s,@LIBS@,$LIBS,;t t +s,@CC@,$CC,;t t +s,@CFLAGS@,$CFLAGS,;t t +s,@LDFLAGS@,$LDFLAGS,;t t +s,@CPPFLAGS@,$CPPFLAGS,;t t +s,@ac_ct_CC@,$ac_ct_CC,;t t +s,@EXEEXT@,$EXEEXT,;t t +s,@OBJEXT@,$OBJEXT,;t t +s,@LIBVER@,$LIBVER,;t t +s,@LIBREV@,$LIBREV,;t t +s,@TARGETS@,$TARGETS,;t t +s,@MYDEFS@,$MYDEFS,;t t +s,@MYOPTS@,$MYOPTS,;t t +s,@MGWLIBS@,$MGWLIBS,;t t +s,@LD@,$LD,;t t +s,@AR@,$AR,;t t +s,@LIBOBJS@,$LIBOBJS,;t t +s,@LTLIBOBJS@,$LTLIBOBJS,;t t +CEOF + +_ACEOF + + cat >>$CONFIG_STATUS <<\_ACEOF + # Split the substitutions into bite-sized pieces for seds with + # small command number limits, like on Digital OSF/1 and HP-UX. + ac_max_sed_lines=48 + ac_sed_frag=1 # Number of current file. + ac_beg=1 # First line for current file. + ac_end=$ac_max_sed_lines # Line after last line for current file. + ac_more_lines=: + ac_sed_cmds= + while $ac_more_lines; do + if test $ac_beg -gt 1; then + sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag + else + sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag + fi + if test ! -s $tmp/subs.frag; then + ac_more_lines=false + else + # The purpose of the label and of the branching condition is to + # speed up the sed processing (if there are no `@' at all, there + # is no need to browse any of the substitutions). + # These are the two extra sed commands mentioned above. + (echo ':t + /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed + if test -z "$ac_sed_cmds"; then + ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed" + else + ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed" + fi + ac_sed_frag=`expr $ac_sed_frag + 1` + ac_beg=$ac_end + ac_end=`expr $ac_end + $ac_max_sed_lines` + fi + done + if test -z "$ac_sed_cmds"; then + ac_sed_cmds=cat + fi +fi # test -n "$CONFIG_FILES" + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue + # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". + case $ac_file in + - | *:- | *:-:* ) # input from stdin + cat >$tmp/stdin + ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` + ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; + *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'` + ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;; + * ) ac_file_in=$ac_file.in ;; + esac + + # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories. + ac_dir=`(dirname "$ac_file") 2>/dev/null || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| \ + . : '\(.\)' 2>/dev/null || +echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } + /^X\(\/\/\)[^/].*/{ s//\1/; q; } + /^X\(\/\/\)$/{ s//\1/; q; } + /^X\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + { if $as_mkdir_p; then + mkdir -p "$ac_dir" + else + as_dir="$ac_dir" + as_dirs= + while test ! -d "$as_dir"; do + as_dirs="$as_dir $as_dirs" + as_dir=`(dirname "$as_dir") 2>/dev/null || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| \ + . : '\(.\)' 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; } + /^X\(\/\/\)[^/].*/{ s//\1/; q; } + /^X\(\/\/\)$/{ s//\1/; q; } + /^X\(\/\).*/{ s//\1/; q; } + s/.*/./; q'` + done + test ! -n "$as_dirs" || mkdir $as_dirs + fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5 +echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;} + { (exit 1); exit 1; }; }; } + + ac_builddir=. + +if test "$ac_dir" != .; then + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A "../" for each directory in $ac_dir_suffix. + ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'` +else + ac_dir_suffix= ac_top_builddir= +fi + +case $srcdir in + .) # No --srcdir option. We are building in place. + ac_srcdir=. + if test -z "$ac_top_builddir"; then + ac_top_srcdir=. + else + ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'` + fi ;; + [\\/]* | ?:[\\/]* ) # Absolute path. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir ;; + *) # Relative path. + ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_builddir$srcdir ;; +esac + +# Do not use `cd foo && pwd` to compute absolute paths, because +# the directories may not exist. +case `pwd` in +.) ac_abs_builddir="$ac_dir";; +*) + case "$ac_dir" in + .) ac_abs_builddir=`pwd`;; + [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";; + *) ac_abs_builddir=`pwd`/"$ac_dir";; + esac;; +esac +case $ac_abs_builddir in +.) ac_abs_top_builddir=${ac_top_builddir}.;; +*) + case ${ac_top_builddir}. in + .) ac_abs_top_builddir=$ac_abs_builddir;; + [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;; + *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;; + esac;; +esac +case $ac_abs_builddir in +.) ac_abs_srcdir=$ac_srcdir;; +*) + case $ac_srcdir in + .) ac_abs_srcdir=$ac_abs_builddir;; + [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;; + *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;; + esac;; +esac +case $ac_abs_builddir in +.) ac_abs_top_srcdir=$ac_top_srcdir;; +*) + case $ac_top_srcdir in + .) ac_abs_top_srcdir=$ac_abs_builddir;; + [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;; + *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;; + esac;; +esac + + + + if test x"$ac_file" != x-; then + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + rm -f "$ac_file" + fi + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + if test x"$ac_file" = x-; then + configure_input= + else + configure_input="$ac_file. " + fi + configure_input=$configure_input"Generated from `echo $ac_file_in | + sed 's,.*/,,'` by configure." + + # First look for the input files in the build tree, otherwise in the + # src tree. + ac_file_inputs=`IFS=: + for f in $ac_file_in; do + case $f in + -) echo $tmp/stdin ;; + [\\/$]*) + # Absolute (can't be DOS-style, as IFS=:) + test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 +echo "$as_me: error: cannot find input file: $f" >&2;} + { (exit 1); exit 1; }; } + echo "$f";; + *) # Relative + if test -f "$f"; then + # Build tree + echo "$f" + elif test -f "$srcdir/$f"; then + # Source tree + echo "$srcdir/$f" + else + # /dev/null tree + { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5 +echo "$as_me: error: cannot find input file: $f" >&2;} + { (exit 1); exit 1; }; } + fi;; + esac + done` || { (exit 1); exit 1; } +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF + sed "$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s,@configure_input@,$configure_input,;t t +s,@srcdir@,$ac_srcdir,;t t +s,@abs_srcdir@,$ac_abs_srcdir,;t t +s,@top_srcdir@,$ac_top_srcdir,;t t +s,@abs_top_srcdir@,$ac_abs_top_srcdir,;t t +s,@builddir@,$ac_builddir,;t t +s,@abs_builddir@,$ac_abs_builddir,;t t +s,@top_builddir@,$ac_top_builddir,;t t +s,@abs_top_builddir@,$ac_abs_top_builddir,;t t +" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out + rm -f $tmp/stdin + if test x"$ac_file" != x-; then + mv $tmp/out $ac_file + else + cat $tmp/out + rm -f $tmp/out + fi + +done +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF + +{ (exit 0); exit 0; } +_ACEOF +chmod +x $CONFIG_STATUS +ac_clean_files=$ac_clean_files_save + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || { (exit 1); exit 1; } +fi + + +# Messages +printf '#================================================================\n' +printf '# Ready to make.\n' +printf '#================================================================\n' + + + +# END OF FILE diff --git a/qdbm/configure.in b/qdbm/configure.in new file mode 100644 index 00000000..9a6f4c40 --- /dev/null +++ b/qdbm/configure.in @@ -0,0 +1,312 @@ +# Source of configuration for QDBM + + + +#================================================================ +# Generic Settings +#================================================================ + + +# Targets +AC_INIT(qdbm, 1.8.77) + +# Export variables +LIBVER=14 +LIBREV=13 +TARGETS="all" +MYDEFS="" +MYOPTS="" +MGWLIBS="" +LD="ld" +AR="ar" + +# Building paths +pathtmp="$PATH" +PATH="$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" +PATH="$PATH:/usr/ccs/bin:/usr/ucb:/usr/xpg4/bin:/usr/xpg6/bin:$pathtmp" +LIBRARY_PATH="$HOME/lib:/usr/local/lib:$LIBRARY_PATH" +LD_LIBRARY_PATH="$HOME/lib:/usr/local/lib:$LD_LIBRARY_PATH" +CPATH="$HOME/include:/usr/local/include:$CPATH" +export PATH LIBRARY_PATH LD_LIBRARY_PATH CPATH + + + +#================================================================ +# Options +#================================================================ + + +# Internal variables +enables="" +ispthread="" +iszlib="" +isiconv="" +isnowarn="" + +# Debug mode +AC_ARG_ENABLE(debug, + AC_HELP_STRING([--enable-debug], [build for debugging])) +if test "$enable_debug" = "yes" +then + TARGETS="debug" + enables="$enables (debug)" +fi + +# Developping mode +AC_ARG_ENABLE(devel, + AC_HELP_STRING([--enable-devel], [build for development])) +if test "$enable_devel" = "yes" +then + TARGETS="devel" + enables="$enables (devel)" +fi + +# Stable mode +AC_ARG_ENABLE(stable, + AC_HELP_STRING([--enable-stable], [build for stable release])) +if test "$enable_stable" = "yes" +then + TARGETS="stable" + enables="$enables (stable)" +fi + +# Enable POSIX thread +AC_ARG_ENABLE(pthread, + AC_HELP_STRING([--enable-pthread], [use POSIX thread and make APIs thread-safe])) +if test "$enable_pthread" = "yes" +then + MYDEFS="$MYDEFS -DMYPTHREAD" + enables="$enables (pthread)" + ispthread="yes" +fi + +# Disable file locking +AC_ARG_ENABLE(lock, + AC_HELP_STRING([--disable-lock], [build for environments without file locking])) +if test "$enable_lock" = "no" +then + MYDEFS="$MYDEFS -DMYNOLOCK" + enables="$enables (no-lock)" +fi + +# Disable memory mapping +AC_ARG_ENABLE(mmap, + AC_HELP_STRING([--disable-mmap], [build for environments without memory mapping])) +if test "$enable_mmap" = "no" +then + MYDEFS="$MYDEFS -DMYNOMMAP" + enables="$enables (no-mmap)" +fi + +# Enable ZLIB compression +AC_ARG_ENABLE(zlib, + AC_HELP_STRING([--enable-zlib], [feature ZLIB for B+ tree and inverted index])) +if test "$enable_zlib" = "yes" +then + MYDEFS="$MYDEFS -DMYZLIB" + MGWLIBS="-lz $MGWLIBS" + enables="$enables (zlib)" + iszlib="yes" +fi + +# Enable LZO compression +AC_ARG_ENABLE(lzo, + AC_HELP_STRING([--enable-lzo], [feature LZO for B+ tree and inverted index])) +if test "$enable_lzo" = "yes" +then + MYDEFS="$MYDEFS -DMYLZO" + MGWLIBS="-llzo2 $MGWLIBS" + enables="$enables (lzo)" + islzo="yes" +fi + +# Enable BZIP2 compression +AC_ARG_ENABLE(bzip, + AC_HELP_STRING([--enable-bzip], [feature BZIP2 for B+ tree and inverted index])) +if test "$enable_bzip" = "yes" +then + MYDEFS="$MYDEFS -DMYBZIP" + MGWLIBS="-lbz2 $MGWLIBS" + enables="$enables (bzip)" + isbzip="yes" +fi + +# Enable ICONV utilities +AC_ARG_ENABLE(iconv, + AC_HELP_STRING([--enable-iconv], [feature ICONV utilities])) +if test "$enable_iconv" = "yes" +then + MYDEFS="$MYDEFS -DMYICONV" + MGWLIBS="-liconv $MGWLIBS" + enables="$enables (iconv)" + isiconv="yes" +fi + +# No warning configuration +AC_ARG_ENABLE(warn, + AC_HELP_STRING([--disable-warn], [hide warnings in the configuration])) +if test "$enable_warn" = "no" +then + isnowarn="yes" +fi + +# Messages +printf '#================================================================\n' +printf '# Configuring QDBM version %s%s.\n' "$PACKAGE_VERSION" "$enables" +printf '#================================================================\n' + + + +#================================================================ +# Checking Commands to Build with +#================================================================ + + +# C compiler +AC_PROG_CC +if test "$GCC" != "yes" +then + if test "$isnowarn" != "yes" + then + printf '#================================================================\n' 1>&2 + printf '# WARNING: GCC is required to build this package.\n' 1>&2 + printf '#================================================================\n' 1>&2 + fi +fi +if uname | egrep -i 'Linux' > /dev/null 2>&1 && + uname -m | egrep '(x|i)(3|4|5|6|7|8|9)?86' > /dev/null 2>&1 +then + MYOPTS="-minline-all-stringops" +fi +if uname | egrep -i 'SunOS' > /dev/null 2>&1 +then + MYOPTS="-O1 -fno-omit-frame-pointer -fno-force-addr" +fi +if uname | egrep -i 'BSD' > /dev/null 2>&1 +then + MYOPTS="-O1 -fno-omit-frame-pointer -fno-force-addr" +fi +if gcc --version | egrep -i '^2\.(8|9)' > /dev/null 2>&1 +then + MYOPTS="-O1 -fno-omit-frame-pointer -fno-force-addr" +fi + +# Linker +printf 'checking for ld... ' +if which ld | grep '/ld$' > /dev/null 2>&1 +then + LD=`which ld` + printf '%s\n' "$LD" +else + printf 'no\n' + if test "$isnowarn" != "yes" + then + printf '#================================================================\n' 1>&2 + printf '# WARNING: ld is not found in PATH.\n' 1>&2 + printf '#================================================================\n' 1>&2 + fi +fi + +# Archiver +printf 'checking for ar... ' +if which ar | grep '/ar$' > /dev/null 2>&1 +then + AR=`which ar` + printf '%s\n' "$AR" +else + printf 'no\n' + if test "$isnowarn" != "yes" + then + printf '#================================================================\n' 1>&2 + printf '# WARNING: ar is not found in PATH.\n' 1>&2 + printf '#================================================================\n' 1>&2 + fi +fi + + + +#================================================================ +# Checking Libraries +#================================================================ + + +# Underlying libraries +AC_CHECK_LIB(c, main) + +# for pthread +if test "$ispthread" = "yes" +then + AC_CHECK_LIB(pthread, main) +fi + +# for zlib +if test "$iszlib" = "yes" +then + AC_CHECK_LIB(z, main) +fi + +# for lzo +if test "$islzo" = "yes" +then + AC_CHECK_LIB(lzo2, main) +fi + +# for bzip +if test "$isbzip" = "yes" +then + AC_CHECK_LIB(bz2, main) +fi + +# for iconv +if test "$isiconv" = "yes" +then + AC_CHECK_LIB(iconv, main) +fi + +# For old BSDs +if test "$ispthread" = "yes" && uname -a | grep BSD > /dev/null && + test -f /usr/lib/libc_r.a && test ! -f /usr/lib/libpthread.a +then + LIBS=`printf '%s' "$LIBS" | sed 's/-lc/-lc_r/g'` +fi + +# Duplication of QDBM for C +AC_CHECK_LIB(qdbm, main, + if test "$isnowarn" != "yes" + then + printf '#================================================================\n' 1>&2 + printf '# WARNING: The existing library was detected.\n' 1>&2 + printf '#================================================================\n' 1>&2 + fi +) + + + +#================================================================ +# Generic Settings +#================================================================ + + +# Export variables +AC_SUBST(LIBVER) +AC_SUBST(LIBREV) +AC_SUBST(TARGETS) +AC_SUBST(MYDEFS) +AC_SUBST(MYOPTS) +AC_SUBST(MGWLIBS) +AC_SUBST(LD) +AC_SUBST(AR) +AC_SUBST(CPPFLAGS) +AC_SUBST(LDFLAGS) + +# Targets +AC_OUTPUT(Makefile LTmakefile qdbm.spec qdbm.pc) + +# Messages +printf '#================================================================\n' +printf '# Ready to make.\n' +printf '#================================================================\n' + + + +# END OF FILE diff --git a/qdbm/crmgr.c b/qdbm/crmgr.c new file mode 100644 index 00000000..8d9baf34 --- /dev/null +++ b/qdbm/crmgr.c @@ -0,0 +1,956 @@ +/************************************************************************************************* + * Utility for debugging Curia and its applications + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define ALIGNSIZ 32 /* basic size of alignment */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +char *hextoobj(const char *str, int *sp); +char *dectoiobj(const char *str, int *sp); +int runcreate(int argc, char **argv); +int runput(int argc, char **argv); +int runout(int argc, char **argv); +int runget(int argc, char **argv); +int runlist(int argc, char **argv); +int runoptimize(int argc, char **argv); +int runinform(int argc, char **argv); +int runremove(int argc, char **argv); +int runrepair(int argc, char **argv); +int runexportdb(int argc, char **argv); +int runimportdb(int argc, char **argv); +int runsnaffle(int argc, char **argv); +void pdperror(const char *name); +void printobj(const char *obj, int size); +void printobjhex(const char *obj, int size); +int docreate(const char *name, int bnum, int dnum, int sparse); +int doput(const char *name, const char *kbuf, int ksiz, + const char *vbuf, int vsiz, int dmode, int lob, int align); +int doout(const char *name, const char *kbuf, int ksiz, int lob); +int doget(const char *name, int opts, const char *kbuf, int ksiz, + int start, int max, int ox, int lob, int nb); +int dolist(const char *name, int opts, int kb, int vb, int ox); +int dooptimize(const char *name, int bnum, int align); +int doinform(const char *name, int opts); +int doremove(const char *name); +int dorepair(const char *name); +int doexportdb(const char *name, const char *dir); +int doimportdb(const char *name, const char *dir, int bnum, int dnum); +int dosnaffle(const char *name, const char *kbuf, int ksiz, int ox, int nb); + + +/* main routine */ +int main(int argc, char **argv){ + char *env; + int rv; + cbstdiobin(); + progname = argv[0]; + if((env = getenv("QDBMDBGFD")) != NULL) dpdbgfd = atoi(env); + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "create")){ + rv = runcreate(argc, argv); + } else if(!strcmp(argv[1], "put")){ + rv = runput(argc, argv); + } else if(!strcmp(argv[1], "out")){ + rv = runout(argc, argv); + } else if(!strcmp(argv[1], "get")){ + rv = runget(argc, argv); + } else if(!strcmp(argv[1], "list")){ + rv = runlist(argc, argv); + } else if(!strcmp(argv[1], "optimize")){ + rv = runoptimize(argc, argv); + } else if(!strcmp(argv[1], "inform")){ + rv = runinform(argc, argv); + } else if(!strcmp(argv[1], "remove")){ + rv = runremove(argc, argv); + } else if(!strcmp(argv[1], "repair")){ + rv = runrepair(argc, argv); + } else if(!strcmp(argv[1], "exportdb")){ + rv = runexportdb(argc, argv); + } else if(!strcmp(argv[1], "importdb")){ + rv = runimportdb(argc, argv); + } else if(!strcmp(argv[1], "snaffle")){ + rv = runsnaffle(argc, argv); + } else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){ + printf("Powered by QDBM version %s on %s%s\n", + dpversion, dpsysname, dpisreentrant ? " (reentrant)" : ""); + printf("Copyright (c) 2000-2007 Mikio Hirabayashi\n"); + rv = 0; + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: administration utility for Curia\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s create [-s] [-bnum num] [-dnum num] name\n", progname); + fprintf(stderr, " %s put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat] [-lob] [-na] " + "name key val\n", progname); + fprintf(stderr, " %s out [-kx|-ki] [-lob] name key\n", progname); + fprintf(stderr, " %s get [-nl] [-kx|-ki] [-start num] [-max num] [-ox] [-lob] [-n] name key\n", + progname); + fprintf(stderr, " %s list [-nl] [-k|-v] [-ox] name\n", progname); + fprintf(stderr, " %s optimize [-bnum num] [-na] name\n", progname); + fprintf(stderr, " %s inform [-nl] name\n", progname); + fprintf(stderr, " %s remove name\n", progname); + fprintf(stderr, " %s repair name\n", progname); + fprintf(stderr, " %s exportdb name dir\n", progname); + fprintf(stderr, " %s importdb [-bnum num] [-dnum num] name dir\n", progname); + fprintf(stderr, " %s snaffle [-kx|-ki] [-ox] [-n] name key\n", progname); + fprintf(stderr, " %s version\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* create a binary object from a hexadecimal string */ +char *hextoobj(const char *str, int *sp){ + char *buf, mbuf[3]; + int len, i, j; + len = strlen(str); + if(!(buf = malloc(len + 1))) return NULL; + j = 0; + for(i = 0; i < len; i += 2){ + while(strchr(" \n\r\t\f\v", str[i])){ + i++; + } + if((mbuf[0] = str[i]) == '\0') break; + if((mbuf[1] = str[i+1]) == '\0') break; + mbuf[2] = '\0'; + buf[j++] = (char)strtol(mbuf, NULL, 16); + } + buf[j] = '\0'; + *sp = j; + return buf; +} + + +/* create a integer object from a decimal string */ +char *dectoiobj(const char *str, int *sp){ + char *buf; + int num; + num = atoi(str); + if(!(buf = malloc(sizeof(int)))) return NULL; + *(int *)buf = num; + *sp = sizeof(int); + return buf; +} + + +/* parse arguments of create command */ +int runcreate(int argc, char **argv){ + char *name; + int i, sb, bnum, dnum, rv; + name = NULL; + sb = FALSE; + bnum = -1; + dnum = -1; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-s")){ + sb = TRUE; + } else if(!strcmp(argv[i], "-bnum")){ + if(++i >= argc) usage(); + bnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-dnum")){ + if(++i >= argc) usage(); + dnum = atoi(argv[i]); + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = docreate(name, bnum, dnum, sb); + return rv; +} + + +/* parse arguments of put command */ +int runput(int argc, char **argv){ + char *name, *key, *val, *kbuf, *vbuf; + int i, kx, ki, vx, vi, vf, lob, ksiz, vsiz, align, rv; + int dmode; + name = NULL; + kx = FALSE; + ki = FALSE; + vx = FALSE; + vi = FALSE; + vf = FALSE; + lob = FALSE; + align = ALIGNSIZ; + key = NULL; + val = NULL; + dmode = CR_DOVER; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else if(!strcmp(argv[i], "-vx")){ + vx = TRUE; + } else if(!strcmp(argv[i], "-vi")){ + vi = TRUE; + } else if(!strcmp(argv[i], "-vf")){ + vf = TRUE; + } else if(!strcmp(argv[i], "-keep")){ + dmode = CR_DKEEP; + } else if(!strcmp(argv[i], "-cat")){ + dmode = CR_DCAT; + } else if(!strcmp(argv[i], "-lob")){ + lob = TRUE; + } else if(!strcmp(argv[i], "-na")){ + align = 0; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else if(!val){ + val = argv[i]; + } else { + usage(); + } + } + if(!name || !key || !val) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(vx){ + vbuf = hextoobj(val, &vsiz); + } else if(vi){ + vbuf = dectoiobj(val, &vsiz); + } else if(vf){ + vbuf = cbreadfile(val, &vsiz); + } else { + vbuf = cbmemdup(val, -1); + vsiz = -1; + } + if(kbuf && vbuf){ + rv = doput(name, kbuf, ksiz, vbuf, vsiz, dmode, lob, align); + } else { + if(vf){ + fprintf(stderr, "%s: %s: cannot read\n", progname, val); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + } + rv = 1; + } + free(kbuf); + free(vbuf); + return rv; +} + + +/* parse arguments of out command */ +int runout(int argc, char **argv){ + char *name, *key, *kbuf; + int i, kx, ki, lob, ksiz, rv; + name = NULL; + kx = FALSE; + ki = FALSE; + lob = FALSE; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else if(!strcmp(argv[i], "-lob")){ + lob = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(kbuf){ + rv = doout(name, kbuf, ksiz, lob); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* parse arguments of get command */ +int runget(int argc, char **argv){ + char *name, *key, *kbuf; + int i, opts, kx, ki, ox, lob, nb, start, max, ksiz, rv; + name = NULL; + opts = 0; + kx = FALSE; + ki = FALSE; + ox = FALSE; + lob = FALSE; + nb = FALSE; + start = 0; + max = -1; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-nl")){ + opts |= CR_ONOLCK; + } else if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else if(!strcmp(argv[i], "-lob")){ + lob = TRUE; + } else if(!strcmp(argv[i], "-n")){ + nb = TRUE; + } else if(!strcmp(argv[i], "-start")){ + if(++i >= argc) usage(); + start = atoi(argv[i]); + } else if(!strcmp(argv[i], "-max")){ + if(++i >= argc) usage(); + max = atoi(argv[i]); + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key || start < 0) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(kbuf){ + rv = doget(name, opts, kbuf, ksiz, start, max, ox, lob, nb); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* parse arguments of list command */ +int runlist(int argc, char **argv){ + char *name; + int i, opts, kb, vb, ox, rv; + name = NULL; + opts = 0; + kb = FALSE; + vb = FALSE; + ox = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-nl")){ + opts |= CR_ONOLCK; + } else if(!strcmp(argv[i], "-k")){ + kb = TRUE; + } else if(!strcmp(argv[i], "-v")){ + vb = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dolist(name, opts, kb, vb, ox); + return rv; +} + + +/* parse arguments of optimize command */ +int runoptimize(int argc, char **argv){ + char *name; + int i, bnum, align, rv; + name = NULL; + bnum = -1; + align = ALIGNSIZ; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-bnum")){ + if(++i >= argc) usage(); + bnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-na")){ + align = 0; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dooptimize(name, bnum, align); + return rv; +} + + +/* parse arguments of inform command */ +int runinform(int argc, char **argv){ + char *name; + int i, opts, rv; + name = NULL; + opts = 0; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-nl")){ + opts |= CR_ONOLCK; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doinform(name, opts); + return rv; +} + + +/* parse arguments of remove command */ +int runremove(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doremove(name); + return rv; +} + + +/* parse arguments of repair command */ +int runrepair(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dorepair(name); + return rv; +} + + +/* parse arguments of exportdb command */ +int runexportdb(int argc, char **argv){ + char *name, *dir; + int i, rv; + name = NULL; + dir = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else if(!dir){ + dir = argv[i]; + } else { + usage(); + } + } + if(!name || !dir) usage(); + rv = doexportdb(name, dir); + return rv; +} + + +/* parse arguments of importdb command */ +int runimportdb(int argc, char **argv){ + char *name, *dir; + int i, bnum, dnum, rv; + name = NULL; + dir = NULL; + bnum = -1; + dnum = -1; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-bnum")){ + if(++i >= argc) usage(); + bnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-dnum")){ + if(++i >= argc) usage(); + dnum = atoi(argv[i]); + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!dir){ + dir = argv[i]; + } else { + usage(); + } + } + if(!name || !dir) usage(); + rv = doimportdb(name, dir, bnum, dnum); + return rv; +} + + +/* parse arguments of snaffle command */ +int runsnaffle(int argc, char **argv){ + char *name, *key, *kbuf; + int i, kx, ki, ox, nb, start, max, ksiz, rv; + name = NULL; + kx = FALSE; + ki = FALSE; + ox = FALSE; + nb = FALSE; + start = 0; + max = -1; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else if(!strcmp(argv[i], "-n")){ + nb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key || start < 0) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(kbuf){ + rv = dosnaffle(name, kbuf, ksiz, ox, nb); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* print an object */ +void printobj(const char *obj, int size){ + int i; + for(i = 0; i < size; i++){ + putchar(obj[i]); + } +} + + +/* print an object as a hexadecimal string */ +void printobjhex(const char *obj, int size){ + int i; + for(i = 0; i < size; i++){ + printf("%s%02X", i > 0 ? " " : "", ((const unsigned char *)obj)[i]); + } +} + + +/* perform create command */ +int docreate(const char *name, int bnum, int dnum, int sparse){ + CURIA *curia; + int omode; + omode = CR_OWRITER | CR_OCREAT | CR_OTRUNC | (sparse ? CR_OSPARSE : 0); + if(!(curia = cropen(name, omode, bnum, dnum))){ + pdperror(name); + return 1; + } + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform put command */ +int doput(const char *name, const char *kbuf, int ksiz, + const char *vbuf, int vsiz, int dmode, int lob, int align){ + CURIA *curia; + if(!(curia = cropen(name, CR_OWRITER, -1, -1))){ + pdperror(name); + return 1; + } + if(align > 0 && !crsetalign(curia, ALIGNSIZ)){ + pdperror(name); + crclose(curia); + return 1; + } + if(lob){ + if(!crputlob(curia, kbuf, ksiz, vbuf, vsiz, dmode)){ + pdperror(name); + crclose(curia); + return 1; + } + } else { + if(!crput(curia, kbuf, ksiz, vbuf, vsiz, dmode)){ + pdperror(name); + crclose(curia); + return 1; + } + } + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform out command */ +int doout(const char *name, const char *kbuf, int ksiz, int lob){ + CURIA *curia; + if(!(curia = cropen(name, CR_OWRITER, -1, -1))){ + pdperror(name); + return 1; + } + if(lob){ + if(!croutlob(curia, kbuf, ksiz)){ + pdperror(name); + crclose(curia); + return 1; + } + } else { + if(!crout(curia, kbuf, ksiz)){ + pdperror(name); + crclose(curia); + return 1; + } + } + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform get command */ +int doget(const char *name, int opts, const char *kbuf, int ksiz, + int start, int max, int ox, int lob, int nb){ + CURIA *curia; + char *vbuf; + int vsiz; + if(!(curia = cropen(name, CR_OREADER | opts, -1, -1))){ + pdperror(name); + return 1; + } + if(lob){ + if(!(vbuf = crgetlob(curia, kbuf, ksiz, start, max, &vsiz))){ + pdperror(name); + crclose(curia); + return 1; + } + } else { + if(!(vbuf = crget(curia, kbuf, ksiz, start, max, &vsiz))){ + pdperror(name); + crclose(curia); + return 1; + } + } + if(ox){ + printobjhex(vbuf, vsiz); + } else { + printobj(vbuf, vsiz); + } + free(vbuf); + if(!nb) putchar('\n'); + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform list command */ +int dolist(const char *name, int opts, int kb, int vb, int ox){ + CURIA *curia; + char *kbuf, *vbuf; + int ksiz, vsiz; + if(!(curia = cropen(name, CR_OREADER | opts, -1, -1))){ + pdperror(name); + return 1; + } + criterinit(curia); + while((kbuf = criternext(curia, &ksiz)) != NULL){ + if(!(vbuf = crget(curia, kbuf, ksiz, 0, -1, &vsiz))){ + pdperror(name); + free(kbuf); + break; + } + if(ox){ + if(!vb) printobjhex(kbuf, ksiz); + if(!kb && !vb) putchar('\t'); + if(!kb) printobjhex(vbuf, vsiz); + } else { + if(!vb) printobj(kbuf, ksiz); + if(!kb && !vb) putchar('\t'); + if(!kb) printobj(vbuf, vsiz); + } + putchar('\n'); + free(vbuf); + free(kbuf); + } + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform optimize command */ +int dooptimize(const char *name, int bnum, int align){ + CURIA *curia; + if(!(curia = cropen(name, CR_OWRITER, -1, -1))){ + pdperror(name); + return 1; + } + if(align > 0 && !crsetalign(curia, ALIGNSIZ)){ + pdperror(name); + crclose(curia); + return 1; + } + if(!croptimize(curia, bnum)){ + pdperror(name); + crclose(curia); + return 1; + } + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform inform command */ +int doinform(const char *name, int opts){ + CURIA *curia; + if(!(curia = cropen(name, CR_OREADER | opts, -1, -1))){ + pdperror(name); + return 1; + } + printf("name: %s\n", crname(curia)); + printf("file size: %.0f\n", crfsizd(curia)); + printf("all buckets: %d\n", crbnum(curia)); + printf("used buckets: %d\n", crbusenum(curia)); + printf("records: %d\n", crrnum(curia)); + printf("inode number: %d\n", crinode(curia)); + printf("modified time: %.0f\n", (double)crmtime(curia)); + printf("LOB records: %d\n", crrnumlob(curia)); + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform remove command */ +int doremove(const char *name){ + if(!crremove(name)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform repair command */ +int dorepair(const char *name){ + if(!crrepair(name)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform exportdb command */ +int doexportdb(const char *name, const char *dir){ + CURIA *curia; + if(!(curia = cropen(name, CR_OREADER, -1, -1))){ + pdperror(name); + return 1; + } + if(!crexportdb(curia, dir)){ + pdperror(name); + crclose(curia); + return 1; + } + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform importdb command */ +int doimportdb(const char *name, const char *dir, int bnum, int dnum){ + CURIA *curia; + if(!(curia = cropen(name, CR_OWRITER | CR_OCREAT | CR_OTRUNC, bnum, dnum))){ + pdperror(name); + return 1; + } + if(!crimportdb(curia, dir)){ + pdperror(name); + crclose(curia); + return 1; + } + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform snaffle command */ +int dosnaffle(const char *name, const char *kbuf, int ksiz, int ox, int nb){ + char *vbuf; + int vsiz; + if(!(vbuf = crsnaffle(name, kbuf, ksiz, &vsiz))){ + pdperror(name); + return 1; + } + if(ox){ + printobjhex(vbuf, vsiz); + } else { + printobj(vbuf, vsiz); + } + free(vbuf); + if(!nb) putchar('\n'); + return 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/crtest.c b/qdbm/crtest.c new file mode 100644 index 00000000..6239841b --- /dev/null +++ b/qdbm/crtest.c @@ -0,0 +1,873 @@ +/************************************************************************************************* + * Test cases of Curia + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define RECBUFSIZ 32 /* buffer for records */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +int runwrite(int argc, char **argv); +int runread(int argc, char **argv); +int runrcat(int argc, char **argv); +int runcombo(int argc, char **argv); +int runwicked(int argc, char **argv); +int printfflush(const char *format, ...); +void pdperror(const char *name); +int myrand(void); +int dowrite(const char *name, int rnum, int bnum, int dnum, int sparse, int lob); +int doread(const char *name, int wb, int lob); +int dorcat(const char *name, int rnum, int bnum, int dnum, int pnum, + int align, int fbpsiz, int cb); +int docombo(const char *name); +int dowicked(const char *name, int rnum, int cb); + + +/* main routine */ +int main(int argc, char **argv){ + char *env; + int rv; + cbstdiobin(); + if((env = getenv("QDBMDBGFD")) != NULL) dpdbgfd = atoi(env); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "write")){ + rv = runwrite(argc, argv); + } else if(!strcmp(argv[1], "read")){ + rv = runread(argc, argv); + } else if(!strcmp(argv[1], "rcat")){ + rv = runrcat(argc, argv); + } else if(!strcmp(argv[1], "combo")){ + rv = runcombo(argc, argv); + } else if(!strcmp(argv[1], "wicked")){ + rv = runwicked(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: test cases for Curia\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s write [-s] [-lob] name rnum bnum dnum\n", progname); + fprintf(stderr, " %s read [-wb] [-lob] name\n", progname); + fprintf(stderr, " %s rcat [-c] name rnum bnum dnum pnum align fbpsiz\n", progname); + fprintf(stderr, " %s combo name\n", progname); + fprintf(stderr, " %s wicked [-c] name rnum\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of write command */ +int runwrite(int argc, char **argv){ + char *name, *rstr, *bstr, *dstr; + int i, rnum, bnum, dnum, sb, lob, rv; + name = NULL; + rstr = NULL; + bstr = NULL; + dstr = NULL; + rnum = 0; + bnum = 0; + dnum = 0; + sb = FALSE; + lob = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-s")){ + sb = TRUE; + } else if(!strcmp(argv[i], "-lob")){ + lob = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else if(!bstr){ + bstr = argv[i]; + } else if(!dstr){ + dstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr || !bstr || !dstr) usage(); + rnum = atoi(rstr); + bnum = atoi(bstr); + dnum = atoi(dstr); + if(rnum < 1 || bnum < 1 || dnum < 1) usage(); + rv = dowrite(name, rnum, bnum, dnum, sb, lob); + return rv; +} + + +/* parse arguments of read command */ +int runread(int argc, char **argv){ + char *name; + int i, wb, lob, rv; + name = NULL; + wb = FALSE; + lob = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-wb")){ + wb = TRUE; + } else if(!strcmp(argv[i], "-lob")){ + lob = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doread(name, wb, lob); + return rv; +} + + +/* parse arguments of rcat command */ +int runrcat(int argc, char **argv){ + char *name, *rstr, *bstr, *dstr, *pstr, *astr, *fstr; + int i, rnum, bnum, dnum, pnum, align, fbpsiz, cb, rv; + name = NULL; + rstr = NULL; + bstr = NULL; + dstr = NULL; + pstr = NULL; + astr = NULL; + fstr = NULL; + rnum = 0; + bnum = 0; + pnum = 0; + align = 0; + fbpsiz = 0; + cb = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-c")){ + cb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else if(!bstr){ + bstr = argv[i]; + } else if(!dstr){ + dstr = argv[i]; + } else if(!pstr){ + pstr = argv[i]; + } else if(!astr){ + astr = argv[i]; + } else if(!fstr){ + fstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr || !bstr || !dstr || !pstr || !astr || !fstr) usage(); + rnum = atoi(rstr); + bnum = atoi(bstr); + dnum = atoi(dstr); + pnum = atoi(pstr); + align = atoi(astr); + fbpsiz = atoi(fstr); + if(rnum < 1 || bnum < 1 || dnum < 1 || pnum < 1 || fbpsiz < 0) usage(); + rv = dorcat(name, rnum, bnum, dnum, pnum, align, fbpsiz, cb); + return rv; +} + + +/* parse arguments of combo command */ +int runcombo(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = docombo(name); + return rv; +} + + +/* parse arguments of wicked command */ +int runwicked(int argc, char **argv){ + char *name, *rstr; + int i, rnum, cb, rv; + name = NULL; + rstr = NULL; + rnum = 0; + cb = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-c")){ + cb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = dowicked(name, rnum, cb); + return rv; +} + + +/* print formatted string and flush the buffer */ +int printfflush(const char *format, ...){ + va_list ap; + int rv; + va_start(ap, format); + rv = vprintf(format, ap); + if(fflush(stdout) == EOF) rv = -1; + va_end(ap); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* pseudo random number generator */ +int myrand(void){ + static int cnt = 0; + if(cnt == 0) srand(time(NULL)); + return (rand() * rand() + (rand() >> (sizeof(int) * 4)) + (cnt++)) & INT_MAX; +} + + +/* perform write command */ +int dowrite(const char *name, int rnum, int bnum, int dnum, int sparse, int lob){ + CURIA *curia; + int i, omode, err, len; + char buf[RECBUFSIZ]; + printfflush("\n name=%s rnum=%d bnum=%d dnum=%d s=%d lob=%d\n\n", + name, rnum, bnum, dnum, sparse, lob); + /* open a database */ + omode = CR_OWRITER | CR_OCREAT | CR_OTRUNC | (sparse ? CR_OSPARSE : 0); + if(!(curia = cropen(name, omode, bnum, dnum))){ + pdperror(name); + return 1; + } + err = FALSE; + /* loop for each record */ + for(i = 1; i <= rnum; i++){ + /* store a record */ + len = sprintf(buf, "%08d", i); + if(lob){ + if(!crputlob(curia, buf, len, buf, len, CR_DOVER)){ + pdperror(name); + err = TRUE; + break; + } + } else { + if(!crput(curia, buf, len, buf, len, CR_DOVER)){ + pdperror(name); + err = TRUE; + break; + } + } + /* print progression */ + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + if(!crclose(curia)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform read command */ +int doread(const char *name, int wb, int lob){ + CURIA *curia; + int i, rnum, err, len; + char buf[RECBUFSIZ], vbuf[RECBUFSIZ], *val; + printfflush("\n name=%s wb=%d lob=%d\n\n", name, wb, lob); + /* open a database */ + if(!(curia = cropen(name, CR_OREADER, -1, -1))){ + pdperror(name); + return 1; + } + /* get the number of records */ + if(lob){ + rnum = crrnumlob(curia); + } else { + rnum = crrnum(curia); + } + err = FALSE; + /* loop for each record */ + for(i = 1; i <= rnum; i++){ + /* retrieve a record */ + len = sprintf(buf, "%08d", i); + if(lob){ + if(!(val = crgetlob(curia, buf, len, 0, -1, NULL))){ + pdperror(name); + err = TRUE; + break; + } + free(val); + } else if(wb){ + if(crgetwb(curia, buf, len, 0, RECBUFSIZ, vbuf) == -1){ + pdperror(name); + err = TRUE; + break; + } + } else { + if(!(val = crget(curia, buf, len, 0, -1, NULL))){ + pdperror(name); + err = TRUE; + break; + } + free(val); + } + /* print progression */ + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + if(!crclose(curia)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform rcat command */ +int dorcat(const char *name, int rnum, int bnum, int dnum, int pnum, + int align, int fbpsiz, int cb){ + CURIA *curia; + CBMAP *map; + int i, err, len, ksiz, vsiz, rsiz; + const char *kbuf, *vbuf; + char buf[RECBUFSIZ], *rbuf; + printfflush("\n name=%s rnum=%d bnum=%d dnum=%d pnum=%d" + " align=%d fbpsiz=%d c=%d\n\n", name, rnum, bnum, dnum, pnum, align, fbpsiz, cb); + if(!(curia = cropen(name, CR_OWRITER | CR_OCREAT | CR_OTRUNC, bnum, dnum))){ + pdperror(name); + return 1; + } + if(!crsetalign(curia, align) || !crsetfbpsiz(curia, fbpsiz)){ + pdperror(name); + crclose(curia); + return 1; + } + map = NULL; + if(cb) map = cbmapopen(); + err = FALSE; + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", myrand() % pnum + 1); + if(!crput(curia, buf, len, buf, len, CR_DCAT)){ + pdperror(name); + err = TRUE; + break; + } + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d: fsiz=%d rnum=%d)\n", i, crfsiz(curia), crrnum(curia)); + } + } + } + if(map){ + printfflush("Matching records ... "); + cbmapiterinit(map); + while((kbuf = cbmapiternext(map, &ksiz)) != NULL){ + vbuf = cbmapget(map, kbuf, ksiz, &vsiz); + if(!(rbuf = crget(curia, kbuf, ksiz, 0, -1, &rsiz))){ + pdperror(name); + err = TRUE; + break; + } + if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){ + fprintf(stderr, "%s: %s: unmatched record\n", progname, name); + free(rbuf); + err = TRUE; + break; + } + free(rbuf); + } + cbmapclose(map); + if(!err) printfflush("ok\n"); + } + if(!crclose(curia)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform combo command */ +int docombo(const char *name){ + CURIA *curia; + char buf[RECBUFSIZ], wbuf[RECBUFSIZ], *vbuf; + int i, len, wlen, vsiz; + printfflush("\n name=%s\n\n", name); + printfflush("Creating a database with bnum 3 ... "); + if(!(curia = cropen(name, CR_OWRITER | CR_OCREAT | CR_OTRUNC, 3, 3))){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Setting alignment as 16 ... "); + if(!crsetalign(curia, 16)){ + pdperror(name); + crclose(curia); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 20 records ... "); + for(i = 1; i <= 20; i++){ + len = sprintf(buf, "%08d", i); + if(!crput(curia, buf, len, buf, len, CR_DOVER)){ + pdperror(name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking records ... "); + for(i = 1; i <= 20; i++){ + len = sprintf(buf, "%08d", i); + if(!(vbuf = crget(curia, buf, len, 0, -1, &vsiz))){ + pdperror(name); + crclose(curia); + return 1; + } + free(vbuf); + if(vsiz != crvsiz(curia, buf, len)){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Overwriting top 10 records without moving rooms ... "); + for(i = 1; i <= 10; i++){ + len = sprintf(buf, "%08d", i); + if(!crput(curia, buf, len, buf, len, CR_DOVER)){ + pdperror(name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Overwriting top 5 records with moving rooms ... "); + for(i = 1; i <= 5; i++){ + len = sprintf(buf, "%08d", i); + wlen = sprintf(wbuf, "%024d", i); + if(!crput(curia, buf, len, wbuf, wlen, CR_DOVER)){ + pdperror(name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Overwriting top 15 records in concatenation with moving rooms ... "); + for(i = 1; i <= 15; i++){ + len = sprintf(buf, "%08d", i); + wlen = sprintf(wbuf, "========================"); + if(!crput(curia, buf, len, wbuf, wlen, CR_DCAT)){ + pdperror(name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking records ... "); + for(i = 1; i <= 20; i++){ + len = sprintf(buf, "%08d", i); + if(!(vbuf = crget(curia, buf, len, 0, -1, &vsiz))){ + pdperror(name); + crclose(curia); + return 1; + } + free(vbuf); + if(vsiz != crvsiz(curia, buf, len)){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Deleting top 10 records ... "); + for(i = 1; i <= 10; i++){ + len = sprintf(buf, "%08d", i); + if(!crout(curia, buf, len)){ + pdperror(name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking deleted records ... "); + for(i = 1; i <= 10; i++){ + len = sprintf(buf, "%08d", i); + vbuf = crget(curia, buf, len, 0, -1, &vsiz); + free(vbuf); + if(vbuf || dpecode != DP_ENOITEM){ + fprintf(stderr, "%s: %s: deleting failed\n", progname, name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Overwriting top 15 records in concatenation with moving rooms ... "); + for(i = 1; i <= 15; i++){ + len = sprintf(buf, "%08d", i); + wlen = sprintf(wbuf, "========================"); + if(!crput(curia, buf, len, wbuf, wlen, CR_DCAT)){ + pdperror(name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking records ... "); + for(i = 1; i <= 20; i++){ + len = sprintf(buf, "%08d", i); + if(!(vbuf = crget(curia, buf, len, 0, -1, &vsiz))){ + pdperror(name); + crclose(curia); + return 1; + } + free(vbuf); + if(vsiz != crvsiz(curia, buf, len)){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Optimizing the database ... "); + if(!croptimize(curia, -1)){ + pdperror(name); + crclose(curia); + return 1; + } + printfflush("ok\n"); + printfflush("Checking records ... "); + for(i = 1; i <= 20; i++){ + len = sprintf(buf, "%08d", i); + if(!(vbuf = crget(curia, buf, len, 0, -1, &vsiz))){ + pdperror(name); + crclose(curia); + return 1; + } + free(vbuf); + if(vsiz != crvsiz(curia, buf, len)){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Closing database ... "); + if(!crclose(curia)){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Creating a database with bnum 1000000 ... "); + if(!(curia = cropen(name, DP_OWRITER | DP_OCREAT | DP_OTRUNC, 1000000, -1))){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 1000 records ... "); + for(i = 1; i <= 1000; i++){ + len = sprintf(buf, "%08d", i); + if(!crput(curia, buf, len, buf, len, DP_DOVER)){ + pdperror(name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Adding 64 records ... "); + for(i = 1; i <= 64; i++){ + len = sprintf(buf, "%o", i); + if(!crput(curia, buf, len, buf, len, DP_DOVER)){ + pdperror(name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Syncing the database ... "); + if(!crsync(curia)){ + pdperror(name); + crclose(curia); + return 1; + } + printfflush("ok\n"); + printfflush("Retrieving records directly ... "); + for(i = 1; i <= 64; i++){ + len = sprintf(buf, "%o", i); + if(!(vbuf = crsnaffle(name, buf, len, &vsiz))){ + pdperror(name); + crclose(curia); + return 1; + } + if(strcmp(vbuf, buf)){ + fprintf(stderr, "%s: %s: invalid content\n", progname, name); + free(vbuf); + crclose(curia); + return 1; + } + free(vbuf); + if(vsiz != crvsiz(curia, buf, len)){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + crclose(curia); + return 1; + } + } + printfflush("ok\n"); + printfflush("Optimizing the database ... "); + if(!croptimize(curia, -1)){ + pdperror(name); + crclose(curia); + return 1; + } + printfflush("ok\n"); + printfflush("Closing the database ... "); + if(!crclose(curia)){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("all ok\n\n"); + return 0; +} + + +/* perform wicked command */ +int dowicked(const char *name, int rnum, int cb){ + CURIA *curia; + CBMAP *map; + int i, len, err, align, mksiz, mvsiz, rsiz; + const char *mkbuf, *mvbuf; + char buf[RECBUFSIZ], vbuf[RECBUFSIZ], *val; + printfflush("\n name=%s rnum=%d\n\n", name, rnum); + err = FALSE; + if(!(curia = cropen(name, CR_OWRITER | CR_OCREAT | CR_OTRUNC, rnum / 10, 5))){ + pdperror(name); + return 1; + } + if(!crsetalign(curia, 16) || !crsetfbpsiz(curia, 256)){ + pdperror(name); + err = TRUE; + } + map = NULL; + if(cb) map = cbmapopen(); + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", myrand() % rnum + 1); + switch(myrand() % 16){ + case 0: + putchar('O'); + if(!crput(curia, buf, len, buf, len, CR_DOVER)) err = TRUE; + if(map) cbmapput(map, buf, len, buf, len, TRUE); + break; + case 1: + putchar('K'); + if(!crput(curia, buf, len, buf, len, CR_DKEEP) && dpecode != DP_EKEEP) err = TRUE; + if(map) cbmapput(map, buf, len, buf, len, FALSE); + break; + case 2: + putchar('D'); + if(!crout(curia, buf, len) && dpecode != DP_ENOITEM) err = TRUE; + if(map) cbmapout(map, buf, len); + break; + case 3: + putchar('G'); + if(crgetwb(curia, buf, len, 2, RECBUFSIZ, vbuf) == -1 && dpecode != DP_ENOITEM) err = TRUE; + break; + case 4: + putchar('V'); + if(crvsiz(curia, buf, len) == -1 && dpecode != DP_ENOITEM) err = TRUE; + break; + default: + putchar('C'); + if(!crput(curia, buf, len, buf, len, CR_DCAT)) err = TRUE; + if(map) cbmapputcat(map, buf, len, buf, len); + break; + } + if(i % 50 == 0) printfflush(" (%08d)\n", i); + if(!err && rnum > 100 && myrand() % (rnum / 100) == 0){ + if(myrand() % 10 == 0){ + align = (myrand() % 4 + 1) * -1; + } else { + align = myrand() % 32; + } + if(!crsetalign(curia, align)) err = TRUE; + } + if(err){ + pdperror(name); + break; + } + } + if(!croptimize(curia, -1)){ + pdperror(name); + err = TRUE; + } + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", i); + if(!crput(curia, buf, len, ":", -1, CR_DCAT)){ + pdperror(name); + err = TRUE; + break; + } + if(map) cbmapputcat(map, buf, len, ":", -1); + putchar(':'); + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + if(!croptimize(curia, -1)){ + pdperror(name); + err = TRUE; + } + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", i); + if(!(val = crget(curia, buf, len, 0, -1, NULL))){ + pdperror(name); + err = TRUE; + break; + } + free(val); + putchar('='); + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + if(!criterinit(curia)){ + pdperror(name); + err = TRUE; + } + for(i = 1; i <= rnum; i++){ + if(!(val = criternext(curia, NULL))){ + pdperror(name); + err = TRUE; + break; + } + free(val); + putchar('@'); + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + if(map){ + printfflush("Matching records ... "); + cbmapiterinit(map); + while((mkbuf = cbmapiternext(map, &mksiz)) != NULL){ + mvbuf = cbmapget(map, mkbuf, mksiz, &mvsiz); + if(!(val = crget(curia, mkbuf, mksiz, 0, -1, &rsiz))){ + pdperror(name); + err = TRUE; + break; + } + if(rsiz != mvsiz || memcmp(val, mvbuf, rsiz)){ + fprintf(stderr, "%s: %s: unmatched record\n", progname, name); + free(val); + err = TRUE; + break; + } + free(val); + } + cbmapclose(map); + if(!err) printfflush("ok\n"); + } + if(!crclose(curia)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/crtsv.c b/qdbm/crtsv.c new file mode 100644 index 00000000..5b52488d --- /dev/null +++ b/qdbm/crtsv.c @@ -0,0 +1,266 @@ +/************************************************************************************************* + * Mutual converter between a database of Curia and a TSV text + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +int runimport(int argc, char **argv); +int runexport(int argc, char **argv); +void pdperror(const char *name); +char *getl(void); +int doimport(const char *name, int bnum, int dnum, int bin); +int doexport(const char *name, int bin); + + +/* main routine */ +int main(int argc, char **argv){ + int rv; + cbstdiobin(); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "import")){ + rv = runimport(argc, argv); + } else if(!strcmp(argv[1], "export")){ + rv = runexport(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: mutual converter between TSV and Curia database\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s import [-bnum num] [-dnum num] [-bin] name\n", progname); + fprintf(stderr, " %s export [-bin] name\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of import command */ +int runimport(int argc, char **argv){ + char *name; + int i, bnum, dnum, bin, rv; + name = NULL; + bnum = -1; + dnum = -1; + bin = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-bnum")){ + if(++i >= argc) usage(); + bnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-dnum")){ + if(++i >= argc) usage(); + dnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-bin")){ + bin = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doimport(name, bnum, dnum, bin); + return rv; +} + + +/* parse arguments of export command */ +int runexport(int argc, char **argv){ + char *name; + int i, bin, rv; + name = NULL; + bin = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-bin")){ + bin = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doexport(name, bin); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* read a line */ +char *getl(void){ + char *buf; + int c, len, blen; + buf = NULL; + len = 0; + blen = 256; + while((c = getchar()) != EOF){ + if(blen <= len) blen *= 2; + buf = cbrealloc(buf, blen + 1); + if(c == '\n') c = '\0'; + buf[len++] = c; + if(c == '\0') break; + } + if(!buf) return NULL; + buf[len] = '\0'; + return buf; +} + + +/* perform import command */ +int doimport(const char *name, int bnum, int dnum, int bin){ + CURIA *curia; + char *buf, *kbuf, *vbuf, *ktmp, *vtmp; + int i, err, ktsiz, vtsiz; + /* open a database */ + if(!(curia = cropen(name, CR_OWRITER | CR_OCREAT, bnum, dnum))){ + pdperror(name); + return 1; + } + /* loop for each line */ + err = FALSE; + for(i = 1; (buf = getl()) != NULL; i++){ + kbuf = buf; + if((vbuf = strchr(buf, '\t')) != NULL){ + *vbuf = '\0'; + vbuf++; + /* store a record */ + if(bin){ + ktmp = cbbasedecode(kbuf, &ktsiz); + vtmp = cbbasedecode(vbuf, &vtsiz); + if(!crput(curia, ktmp, ktsiz, vtmp, vtsiz, CR_DOVER)){ + pdperror(name); + err = TRUE; + } + free(vtmp); + free(ktmp); + } else { + if(!crput(curia, kbuf, -1, vbuf, -1, CR_DOVER)){ + pdperror(name); + err = TRUE; + } + } + } else { + fprintf(stderr, "%s: %s: invalid format in line %d\n", progname, name, i); + } + free(buf); + if(err) break; + } + /* close the database */ + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return err ? 1 : 0; +} + + +/* perform export command */ +int doexport(const char *name, int bin){ + CURIA *curia; + char *kbuf, *vbuf, *tmp; + int err, ksiz, vsiz; + /* open a database */ + if(!(curia = cropen(name, CR_OREADER, -1, -1))){ + pdperror(name); + return 1; + } + /* initialize the iterator */ + criterinit(curia); + /* loop for each key */ + err = FALSE; + while((kbuf = criternext(curia, &ksiz)) != NULL){ + /* retrieve a value with a key */ + if(!(vbuf = crget(curia, kbuf, ksiz, 0, -1, &vsiz))){ + pdperror(name); + free(kbuf); + err = TRUE; + break; + } + /* output data */ + if(bin){ + tmp = cbbaseencode(kbuf, ksiz); + printf("%s\t", tmp); + free(tmp); + tmp = cbbaseencode(vbuf, vsiz); + printf("%s\n", tmp); + free(tmp); + } else { + printf("%s\t%s\n", kbuf, vbuf); + } + /* free resources */ + free(vbuf); + free(kbuf); + } + /* check whether all records were retrieved */ + if(dpecode != DP_ENOITEM){ + pdperror(name); + err = TRUE; + } + /* close the database */ + if(!crclose(curia)){ + pdperror(name); + return 1; + } + return err ? 1 : 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/curia.c b/qdbm/curia.c new file mode 100644 index 00000000..100529d0 --- /dev/null +++ b/qdbm/curia.c @@ -0,0 +1,1192 @@ +/************************************************************************************************* + * Implementation of Curia + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#define QDBM_INTERNAL 1 + +#include "curia.h" +#include "myconf.h" + +#define CR_NAMEMAX 512 /* max size of a database name */ +#define CR_DPMAX 512 /* max number of division of a database */ +#define CR_DIRMODE 00755 /* permission of a creating directory */ +#define CR_FILEMODE 00644 /* permission of a creating file */ +#define CR_PATHBUFSIZ 1024 /* size of a path buffer */ +#define CR_DEFDNUM 5 /* default number of division of a database */ +#define CR_ATTRBNUM 16 /* bucket number of attrubute database */ +#define CR_DPNAME "depot" /* name of each sub database */ +#define CR_KEYDNUM "dnum" /* key of division number */ +#define CR_KEYLRNUM "lrnum" /* key of the number of large objects */ +#define CR_TMPFSUF MYEXTSTR "crtmp" /* suffix of a temporary directory */ +#define CR_LOBDIR "lob" /* name of the directory of large objects */ +#define CR_LOBDDEPTH 2 /* depth of the directories of large objects */ +#define CR_NUMBUFSIZ 32 /* size of a buffer for a number */ +#define CR_IOBUFSIZ 8192 /* size of an I/O buffer */ + + +/* private function prototypes */ +static char *crstrdup(const char *str); +static int crdpgetnum(DEPOT *depot, const char *kbuf, int ksiz); +static char *crgetlobpath(CURIA *curia, const char *kbuf, int ksiz); +static int crmklobdir(const char *path); +static int crrmlobdir(const char *path); +static int crcplobdir(CURIA *curia, const char *path); +static int crwrite(int fd, const void *buf, int size); +static int crread(int fd, void *buf, int size); + + + +/************************************************************************************************* + * public objects + *************************************************************************************************/ + + +/* Get a database handle. */ +CURIA *cropen(const char *name, int omode, int bnum, int dnum){ + DEPOT *attr, **depots; + char path[CR_PATHBUFSIZ], *tname; + int i, j, dpomode, inode, lrnum; + struct stat sbuf; + CURIA *curia; + assert(name); + if(dnum < 1) dnum = CR_DEFDNUM; + if(dnum > CR_DPMAX) dnum = CR_DPMAX; + if(strlen(name) > CR_NAMEMAX){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return NULL; + } + dpomode = DP_OREADER; + if(omode & CR_OWRITER){ + dpomode = DP_OWRITER; + if(omode & CR_OCREAT) dpomode |= DP_OCREAT; + if(omode & CR_OTRUNC) dpomode |= DP_OTRUNC; + if(omode & CR_OSPARSE) dpomode |= DP_OSPARSE; + } + if(omode & CR_ONOLCK) dpomode |= DP_ONOLCK; + if(omode & CR_OLCKNB) dpomode |= DP_OLCKNB; + attr = NULL; + lrnum = 0; + if((omode & CR_OWRITER) && (omode & CR_OCREAT)){ + if(mkdir(name, CR_DIRMODE) == -1 && errno != EEXIST){ + dpecodeset(DP_EMKDIR, __FILE__, __LINE__); + return NULL; + } + sprintf(path, "%s%c%s", name, MYPATHCHR, CR_DPNAME); + if(!(attr = dpopen(path, dpomode, CR_ATTRBNUM))) return NULL; + if(dprnum(attr) > 0){ + if((dnum = crdpgetnum(attr, CR_KEYDNUM, -1)) < 1 || + (lrnum = crdpgetnum(attr, CR_KEYLRNUM, -1)) < 0){ + dpclose(attr); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + } else { + if(!dpput(attr, CR_KEYDNUM, -1, (char *)&dnum, sizeof(int), DP_DOVER) || + !dpput(attr, CR_KEYLRNUM, -1, (char *)&lrnum, sizeof(int), DP_DOVER)){ + dpclose(attr); + return NULL; + } + for(i = 0; i < dnum; i++){ + sprintf(path, "%s%c%04d", name, MYPATHCHR, i + 1); + if(mkdir(path, CR_DIRMODE) == -1 && errno != EEXIST){ + dpclose(attr); + dpecodeset(DP_EMKDIR, __FILE__, __LINE__); + return NULL; + } + } + } + } + if(!attr){ + sprintf(path, "%s%c%s", name, MYPATHCHR, CR_DPNAME); + if(!(attr = dpopen(path, dpomode, 1))) return NULL; + if(!(omode & CR_OTRUNC)){ + if((dnum = crdpgetnum(attr, CR_KEYDNUM, -1)) < 1 || + (lrnum = crdpgetnum(attr, CR_KEYLRNUM, -1)) < 0){ + dpclose(attr); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + } + } + if(omode & CR_OTRUNC){ + for(i = 0; i < CR_DPMAX; i++){ + sprintf(path, "%s%c%04d%c%s", name, MYPATHCHR, i + 1, MYPATHCHR, CR_DPNAME); + if(unlink(path) == -1 && errno != ENOENT){ + dpclose(attr); + dpecodeset(DP_EUNLINK, __FILE__, __LINE__); + return NULL; + } + sprintf(path, "%s%c%04d%c%s", name, MYPATHCHR, i + 1, MYPATHCHR, CR_LOBDIR); + if(!crrmlobdir(path)){ + dpclose(attr); + return NULL; + } + if(i >= dnum){ + sprintf(path, "%s%c%04d", name, MYPATHCHR, i + 1); + if(rmdir(path) == -1 && errno != ENOENT){ + dpclose(attr); + dpecodeset(DP_ERMDIR, __FILE__, __LINE__); + return NULL; + } + } + } + errno = 0; + } + if(lstat(name, &sbuf) == -1){ + dpclose(attr); + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + return NULL; + } + inode = sbuf.st_ino; + if(!(depots = malloc(dnum * sizeof(DEPOT *)))){ + dpclose(attr); + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return NULL; + } + for(i = 0; i < dnum; i++){ + sprintf(path, "%s%c%04d%c%s", name, MYPATHCHR, i + 1, MYPATHCHR, CR_DPNAME); + if(!(depots[i] = dpopen(path, dpomode, bnum))){ + for(j = 0; j < i; j++){ + dpclose(depots[j]); + } + free(depots); + dpclose(attr); + return NULL; + } + } + curia = malloc(sizeof(CURIA)); + tname = crstrdup(name); + if(!curia || !tname){ + free(curia); + free(tname); + for(i = 0; i < dnum; i++){ + dpclose(depots[i]); + } + free(depots); + dpclose(attr); + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return NULL; + } + curia->name = tname; + curia->wmode = (omode & CR_OWRITER); + curia->inode = inode; + curia->attr = attr; + curia->depots = depots; + curia->dnum = dnum; + curia->inum = 0; + curia->lrnum = lrnum; + return curia; +} + + +/* Close a database handle. */ +int crclose(CURIA *curia){ + int i, err; + assert(curia); + err = FALSE; + for(i = 0; i < curia->dnum; i++){ + if(!dpclose(curia->depots[i])) err = TRUE; + } + free(curia->depots); + if(curia->wmode){ + if(!dpput(curia->attr, CR_KEYLRNUM, -1, (char *)&(curia->lrnum), sizeof(int), DP_DOVER)) + err = TRUE; + } + if(!dpclose(curia->attr)) err = TRUE; + free(curia->name); + free(curia); + return err ? FALSE : TRUE; +} + + +/* Store a record. */ +int crput(CURIA *curia, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode){ + int dpdmode; + int tnum; + assert(curia && kbuf && vbuf); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(ksiz < 0) ksiz = strlen(kbuf); + switch(dmode){ + case CR_DKEEP: dpdmode = DP_DKEEP; break; + case CR_DCAT: dpdmode = DP_DCAT; break; + default: dpdmode = DP_DOVER; break; + } + tnum = dpouterhash(kbuf, ksiz) % curia->dnum; + return dpput(curia->depots[tnum], kbuf, ksiz, vbuf, vsiz, dpdmode); +} + + +/* Delete a record. */ +int crout(CURIA *curia, const char *kbuf, int ksiz){ + int tnum; + assert(curia && kbuf); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(ksiz < 0) ksiz = strlen(kbuf); + tnum = dpouterhash(kbuf, ksiz) % curia->dnum; + return dpout(curia->depots[tnum], kbuf, ksiz); +} + + +/* Retrieve a record. */ +char *crget(CURIA *curia, const char *kbuf, int ksiz, int start, int max, int *sp){ + int tnum; + assert(curia && kbuf && start >= 0); + if(ksiz < 0) ksiz = strlen(kbuf); + tnum = dpouterhash(kbuf, ksiz) % curia->dnum; + return dpget(curia->depots[tnum], kbuf, ksiz, start, max, sp); +} + + +/* Retrieve a record and write the value into a buffer. */ +int crgetwb(CURIA *curia, const char *kbuf, int ksiz, int start, int max, char *vbuf){ + int tnum; + assert(curia && kbuf && start >= 0 && max >= 0 && vbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + tnum = dpouterhash(kbuf, ksiz) % curia->dnum; + return dpgetwb(curia->depots[tnum], kbuf, ksiz, start, max, vbuf); +} + + +/* Get the size of the value of a record. */ +int crvsiz(CURIA *curia, const char *kbuf, int ksiz){ + int tnum; + assert(curia && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + tnum = dpouterhash(kbuf, ksiz) % curia->dnum; + return dpvsiz(curia->depots[tnum], kbuf, ksiz); +} + + +/* Initialize the iterator of a database handle. */ +int criterinit(CURIA *curia){ + int i, err; + assert(curia); + err = FALSE; + for(i = 0; i < curia->dnum; i++){ + if(!dpiterinit(curia->depots[i])){ + err = TRUE; + break; + } + } + curia->inum = 0; + return err ? FALSE : TRUE; +} + + +/* Get the next key of the iterator. */ +char *criternext(CURIA *curia, int *sp){ + char *kbuf; + assert(curia); + kbuf = NULL; + while(curia->inum < curia->dnum && !(kbuf = dpiternext(curia->depots[curia->inum], sp))){ + if(dpecode != DP_ENOITEM) return NULL; + (curia->inum)++; + } + return kbuf; +} + + +/* Set alignment of a database handle. */ +int crsetalign(CURIA *curia, int align){ + int i, err; + assert(curia); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + for(i = 0; i < curia->dnum; i++){ + if(!dpsetalign(curia->depots[i], align)){ + err = TRUE; + break; + } + } + return err ? FALSE : TRUE; +} + + +/* Set the size of the free block pool of a database handle. */ +int crsetfbpsiz(CURIA *curia, int size){ + int i, err; + assert(curia && size >= 0); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + for(i = 0; i < curia->dnum; i++){ + if(!dpsetfbpsiz(curia->depots[i], size)){ + err = TRUE; + break; + } + } + return err ? FALSE : TRUE; +} + + +/* Synchronize contents of updating a database with the files and the devices. */ +int crsync(CURIA *curia){ + int i, err; + assert(curia); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + if(!dpput(curia->attr, CR_KEYLRNUM, -1, (char *)&(curia->lrnum), sizeof(int), DP_DOVER) || + !dpsync(curia->attr)) err = TRUE; + for(i = 0; i < curia->dnum; i++){ + if(!dpsync(curia->depots[i])){ + err = TRUE; + break; + } + } + return err ? FALSE : TRUE; +} + + +/* Optimize a database. */ +int croptimize(CURIA *curia, int bnum){ + int i, err; + assert(curia); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + for(i = 0; i < curia->dnum; i++){ + if(!dpoptimize(curia->depots[i], bnum)){ + err = TRUE; + break; + } + } + curia->inum = 0; + return err ? FALSE : TRUE; +} + + +/* Get the name of a database. */ +char *crname(CURIA *curia){ + char *name; + assert(curia); + if(!(name = crstrdup(curia->name))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return NULL; + } + return name; +} + + +/* Get the total size of database files. */ +int crfsiz(CURIA *curia){ + int i, sum, rv; + assert(curia); + if((sum = dpfsiz(curia->attr)) == -1) return -1; + for(i = 0; i < curia->dnum; i++){ + if((rv = dpfsiz(curia->depots[i])) == -1) return -1; + sum += rv; + } + return sum; +} + + +/* Get the total size of database files as double-precision value. */ +double crfsizd(CURIA *curia){ + double sum; + int i, rv; + assert(curia); + sum = 0.0; + if((sum = dpfsiz(curia->attr)) < 0) return -1.0; + for(i = 0; i < curia->dnum; i++){ + if((rv = dpfsiz(curia->depots[i])) == -1) return -1.0; + sum += rv; + } + return sum; +} + + +/* Get the total number of the elements of each bucket array. */ +int crbnum(CURIA *curia){ + int i, sum, rv; + assert(curia); + sum = 0; + for(i = 0; i < curia->dnum; i++){ + rv = dpbnum(curia->depots[i]); + if(rv == -1) return -1; + sum += rv; + } + return sum; +} + + +/* Get the total number of the used elements of each bucket array. */ +int crbusenum(CURIA *curia){ + int i, sum, rv; + assert(curia); + sum = 0; + for(i = 0; i < curia->dnum; i++){ + rv = dpbusenum(curia->depots[i]); + if(rv == -1) return -1; + sum += rv; + } + return sum; +} + + +/* Get the number of the records stored in a database. */ +int crrnum(CURIA *curia){ + int i, sum, rv; + assert(curia); + sum = 0; + for(i = 0; i < curia->dnum; i++){ + rv = dprnum(curia->depots[i]); + if(rv == -1) return -1; + sum += rv; + } + return sum; +} + + +/* Check whether a database handle is a writer or not. */ +int crwritable(CURIA *curia){ + assert(curia); + return curia->wmode; +} + + +/* Check whether a database has a fatal error or not. */ +int crfatalerror(CURIA *curia){ + int i; + assert(curia); + if(dpfatalerror(curia->attr)) return TRUE; + for(i = 0; i < curia->dnum; i++){ + if(dpfatalerror(curia->depots[i])) return TRUE; + } + return FALSE; +} + + +/* Get the inode number of a database directory. */ +int crinode(CURIA *curia){ + assert(curia); + return curia->inode; +} + + +/* Get the last modified time of a database. */ +time_t crmtime(CURIA *curia){ + assert(curia); + return dpmtime(curia->attr); +} + + +/* Remove a database directory. */ +int crremove(const char *name){ + struct stat sbuf; + CURIA *curia; + char path[CR_PATHBUFSIZ]; + assert(name); + if(lstat(name, &sbuf) == -1){ + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + return FALSE; + } + if((curia = cropen(name, CR_OWRITER | CR_OTRUNC, 1, 1)) != NULL) crclose(curia); + sprintf(path, "%s%c0001%c%s", name, MYPATHCHR, MYPATHCHR, CR_DPNAME); + dpremove(path); + sprintf(path, "%s%c0001", name, MYPATHCHR); + if(rmdir(path) == -1){ + dpecodeset(DP_ERMDIR, __FILE__, __LINE__); + return FALSE; + } + sprintf(path, "%s%c%s", name, MYPATHCHR, CR_DPNAME); + if(!dpremove(path)) return FALSE; + if(rmdir(name) == -1){ + dpecodeset(DP_ERMDIR, __FILE__, __LINE__); + return FALSE; + } + return TRUE; +} + + +/* Repair a broken database directory. */ +int crrepair(const char *name){ + CURIA *tcuria; + DEPOT *tdepot; + char path[CR_PATHBUFSIZ], *kbuf, *vbuf; + struct stat sbuf; + int i, j, err, flags, bnum, dnum, ksiz, vsiz; + assert(name); + err = FALSE; + flags = 0; + bnum = 0; + dnum = 0; + sprintf(path, "%s%c%s", name, MYPATHCHR, CR_DPNAME); + if(lstat(path, &sbuf) != -1){ + if((tdepot = dpopen(path, DP_OREADER, -1)) != NULL){ + flags = dpgetflags(tdepot); + dpclose(tdepot); + } + } + for(i = 1; i <= CR_DPMAX; i++){ + sprintf(path, "%s%c%04d%c%s", name, MYPATHCHR, i, MYPATHCHR, CR_DPNAME); + if(lstat(path, &sbuf) != -1){ + dnum++; + if(!dprepair(path)) err = TRUE; + if((tdepot = dpopen(path, DP_OREADER, -1)) != NULL){ + bnum += dpbnum(tdepot); + dpclose(tdepot); + } + } + } + if(dnum < CR_DEFDNUM) dnum = CR_DEFDNUM; + bnum /= dnum; + sprintf(path, "%s%s", name, CR_TMPFSUF); + if((tcuria = cropen(path, CR_OWRITER | CR_OCREAT | CR_OTRUNC, bnum, dnum)) != NULL){ + if(!crsetflags(tcuria, flags)) err = TRUE; + for(i = 1; i <= CR_DPMAX; i++){ + sprintf(path, "%s%c%04d%c%s", name, MYPATHCHR, i, MYPATHCHR, CR_DPNAME); + if(lstat(path, &sbuf) != -1){ + if((tdepot = dpopen(path, DP_OREADER, -1)) != NULL){ + if(!dpiterinit(tdepot)) err = TRUE; + while((kbuf = dpiternext(tdepot, &ksiz)) != NULL){ + if((vbuf = dpget(tdepot, kbuf, ksiz, 0, -1, &vsiz)) != NULL){ + if(!crput(tcuria, kbuf, ksiz, vbuf, vsiz, CR_DKEEP)) err = TRUE; + free(vbuf); + } + free(kbuf); + } + dpclose(tdepot); + } else { + err = TRUE; + } + } + for(j = 0; j <= CR_DPMAX; j++){ + sprintf(path, "%s%c%04d%c%s", name, MYPATHCHR, j, MYPATHCHR, CR_LOBDIR); + if(lstat(path, &sbuf) != -1){ + if(!crcplobdir(tcuria, path)) err = TRUE; + } + } + } + if(!crclose(tcuria)) err = TRUE; + if(!crremove(name)) err = TRUE; + sprintf(path, "%s%s", name, CR_TMPFSUF); + if(rename(path, name) == -1){ + if(!err) dpecodeset(DP_EMISC, __FILE__, __LINE__); + err = TRUE; + } + } else { + err = TRUE; + } + return err ? FALSE : TRUE; +} + + +/* Dump all records as endian independent data. */ +int crexportdb(CURIA *curia, const char *name){ + char path[CR_PATHBUFSIZ], *kbuf, *vbuf, *pbuf; + int i, err, *fds, ksiz, vsiz, psiz; + assert(curia && name); + if(!(criterinit(curia))) return FALSE; + if(mkdir(name, CR_DIRMODE) == -1 && errno != EEXIST){ + dpecodeset(DP_EMKDIR, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + fds = malloc(sizeof(int) * curia->dnum); + for(i = 0; i < curia->dnum; i++){ + sprintf(path, "%s%c%04d", name, MYPATHCHR, i + 1); + if((fds[i] = open(path, O_RDWR | O_CREAT | O_TRUNC, CR_FILEMODE)) == -1){ + if(!err) dpecodeset(DP_EOPEN, __FILE__, __LINE__); + err = TRUE; + break; + } + } + while(!err && (kbuf = criternext(curia, &ksiz)) != NULL){ + if((vbuf = crget(curia, kbuf, ksiz, 0, -1, &vsiz)) != NULL){ + if((pbuf = malloc(ksiz + vsiz + CR_NUMBUFSIZ * 2)) != NULL){ + psiz = 0; + psiz += sprintf(pbuf + psiz, "%X\n%X\n", ksiz, vsiz); + memcpy(pbuf + psiz, kbuf, ksiz); + psiz += ksiz; + pbuf[psiz++] = '\n'; + memcpy(pbuf + psiz, vbuf, vsiz); + psiz += vsiz; + pbuf[psiz++] = '\n'; + if(!crwrite(fds[curia->inum], pbuf, psiz)){ + dpecodeset(DP_EWRITE, __FILE__, __LINE__); + err = TRUE; + } + free(pbuf); + } else { + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + err = TRUE; + } + free(vbuf); + } else { + err = TRUE; + } + free(kbuf); + } + for(i = 0; i < curia->dnum; i++){ + if(fds[i] != -1 && close(fds[i]) == -1){ + if(!err) dpecodeset(DP_ECLOSE, __FILE__, __LINE__); + err = TRUE; + } + } + free(fds); + return !err && !crfatalerror(curia); +} + + +/* Load all records from endian independent data. */ +int crimportdb(CURIA *curia, const char *name){ + DEPOT *depot; + char ipath[CR_PATHBUFSIZ], opath[CR_PATHBUFSIZ], *kbuf, *vbuf; + int i, err, ksiz, vsiz; + struct stat sbuf; + assert(curia && name); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(crrnum(curia) > 0){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + for(i = 0; !err && i < CR_DPMAX; i++){ + sprintf(ipath, "%s%c%04d", name, MYPATHCHR, i + 1); + if(lstat(ipath, &sbuf) == -1 || !S_ISREG(sbuf.st_mode)) break; + sprintf(opath, "%s%c%04d%s", curia->name, MYPATHCHR, i + 1, CR_TMPFSUF); + if((depot = dpopen(opath, DP_OWRITER | DP_OCREAT | DP_OTRUNC, -1)) != NULL){ + if(dpimportdb(depot, ipath)){ + dpiterinit(depot); + while((kbuf = dpiternext(depot, &ksiz)) != NULL){ + if((vbuf = dpget(depot, kbuf, ksiz, 0, -1, &vsiz)) != NULL){ + if(!crput(curia, kbuf, ksiz, vbuf, vsiz, CR_DKEEP)) err = TRUE; + free(vbuf); + } else { + err = TRUE; + } + free(kbuf); + } + } else { + err = TRUE; + } + if(!dpclose(depot)) err = TRUE; + if(!dpremove(opath)) err = TRUE; + } else { + err = TRUE; + } + } + return !err && !crfatalerror(curia); +} + + +/* Retrieve a record directly from a database directory. */ +char *crsnaffle(const char *name, const char *kbuf, int ksiz, int *sp){ + char path[CR_PATHBUFSIZ], *vbuf; + int dnum, vsiz, tnum; + assert(name && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + sprintf(path, "%s%c%s", name, MYPATHCHR, CR_DPNAME); + if(!(vbuf = dpsnaffle(path, CR_KEYDNUM, -1, &vsiz)) || vsiz != sizeof(int) || + (dnum = *(int *)vbuf) < 1){ + free(vbuf); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + free(vbuf); + tnum = dpouterhash(kbuf, ksiz) % dnum; + sprintf(path, "%s%c%04d%c%s", name, MYPATHCHR, tnum + 1, MYPATHCHR, CR_DPNAME); + return dpsnaffle(path, kbuf, ksiz, sp); +} + + +/* Store a large object. */ +int crputlob(CURIA *curia, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode){ + char *path; + int mode, fd, err, be; + struct stat sbuf; + assert(curia && kbuf && vbuf); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(ksiz < 0) ksiz = strlen(kbuf); + if(vsiz < 0) vsiz = strlen(vbuf); + if(!(path = crgetlobpath(curia, kbuf, ksiz))) return FALSE; + if(!crmklobdir(path)){ + free(path); + return FALSE; + } + be = lstat(path, &sbuf) != -1 && S_ISREG(sbuf.st_mode); + mode = O_RDWR | O_CREAT; + if(dmode & CR_DKEEP) mode |= O_EXCL; + if(dmode & CR_DCAT){ + mode |= O_APPEND; + } else { + mode |= O_TRUNC; + } + if((fd = open(path, mode, CR_FILEMODE)) == -1){ + free(path); + dpecodeset(DP_EOPEN, __FILE__, __LINE__); + if(dmode == CR_DKEEP) dpecodeset(DP_EKEEP, __FILE__, __LINE__); + return FALSE; + } + free(path); + err = FALSE; + if(crwrite(fd, vbuf, vsiz) == -1){ + err = TRUE; + dpecodeset(DP_EWRITE, __FILE__, __LINE__); + } + if(close(fd) == -1){ + err = TRUE; + dpecodeset(DP_ECLOSE, __FILE__, __LINE__); + } + if(!err && !be) (curia->lrnum)++; + return err ? FALSE : TRUE; +} + + +/* Delete a large object. */ +int croutlob(CURIA *curia, const char *kbuf, int ksiz){ + char *path; + int err, be; + struct stat sbuf; + assert(curia && kbuf); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(ksiz < 0) ksiz = strlen(kbuf); + if(!(path = crgetlobpath(curia, kbuf, ksiz))) return FALSE; + be = lstat(path, &sbuf) != -1 && S_ISREG(sbuf.st_mode); + err = FALSE; + if(unlink(path) == -1){ + err = TRUE; + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + } + free(path); + if(!err && be) (curia->lrnum)--; + return err ? FALSE : TRUE; +} + + +/* Retrieve a large object. */ +char *crgetlob(CURIA *curia, const char *kbuf, int ksiz, int start, int max, int *sp){ + char *path, *buf; + struct stat sbuf; + int fd, size; + assert(curia && kbuf && start >= 0); + if(ksiz < 0) ksiz = strlen(kbuf); + if(!(path = crgetlobpath(curia, kbuf, ksiz))) return NULL; + if((fd = open(path, O_RDONLY, CR_FILEMODE)) == -1){ + free(path); + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return NULL; + } + free(path); + if(fstat(fd, &sbuf) == -1){ + close(fd); + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + return NULL; + } + if(start > sbuf.st_size){ + close(fd); + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return NULL; + } + if(lseek(fd, start, SEEK_SET) == -1){ + close(fd); + dpecodeset(DP_ESEEK, __FILE__, __LINE__); + return NULL; + } + if(max < 0) max = sbuf.st_size; + if(!(buf = malloc(max + 1))){ + close(fd); + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return NULL; + } + size = crread(fd, buf, max); + close(fd); + if(size == -1){ + free(buf); + dpecodeset(DP_EREAD, __FILE__, __LINE__); + return NULL; + } + buf[size] = '\0'; + if(sp) *sp = size; + return buf; +} + + +/* Get the file descriptor of a large object. */ +int crgetlobfd(CURIA *curia, const char *kbuf, int ksiz){ + char *path; + int fd; + assert(curia && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if(!(path = crgetlobpath(curia, kbuf, ksiz))) return -1; + if((fd = open(path, curia->wmode ? O_RDWR: O_RDONLY, CR_FILEMODE)) == -1){ + free(path); + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return -1; + } + free(path); + return fd; +} + + +/* Get the size of the value of a large object. */ +int crvsizlob(CURIA *curia, const char *kbuf, int ksiz){ + char *path; + struct stat sbuf; + assert(curia && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if(!(path = crgetlobpath(curia, kbuf, ksiz))) return -1; + if(lstat(path, &sbuf) == -1){ + free(path); + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return -1; + } + free(path); + return sbuf.st_size; +} + + +/* Get the number of the large objects stored in a database. */ +int crrnumlob(CURIA *curia){ + assert(curia); + return curia->lrnum; +} + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Synchronize updating contents on memory. */ +int crmemsync(CURIA *curia){ + int i, err; + assert(curia); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + if(!dpput(curia->attr, CR_KEYLRNUM, -1, (char *)&(curia->lrnum), sizeof(int), DP_DOVER) || + !dpmemsync(curia->attr)) err = TRUE; + for(i = 0; i < curia->dnum; i++){ + if(!dpmemsync(curia->depots[i])){ + err = TRUE; + break; + } + } + return err ? FALSE : TRUE; +} + + +/* Synchronize updating contents on memory, not physically. */ +int crmemflush(CURIA *curia){ + int i, err; + assert(curia); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + if(!dpput(curia->attr, CR_KEYLRNUM, -1, (char *)&(curia->lrnum), sizeof(int), DP_DOVER) || + !dpmemsync(curia->attr)) err = TRUE; + for(i = 0; i < curia->dnum; i++){ + if(!dpmemflush(curia->depots[i])){ + err = TRUE; + break; + } + } + return err ? FALSE : TRUE; +} + + +/* Get flags of a database. */ +int crgetflags(CURIA *curia){ + assert(curia); + return dpgetflags(curia->attr); +} + + +/* Set flags of a database. */ +int crsetflags(CURIA *curia, int flags){ + assert(curia); + if(!curia->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + return dpsetflags(curia->attr, flags); +} + + + +/************************************************************************************************* + * private objects + *************************************************************************************************/ + + +/* Get a copied string. + `str' specifies an original string. + The return value is a copied string whose region is allocated by `malloc'. */ +static char *crstrdup(const char *str){ + int len; + char *buf; + assert(str); + len = strlen(str); + if(!(buf = malloc(len + 1))) return NULL; + memcpy(buf, str, len + 1); + return buf; +} + + +/* Get an integer from a database. + `depot' specifies an inner database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the key. + The return value is the integer of the corresponding record. */ +static int crdpgetnum(DEPOT *depot, const char *kbuf, int ksiz){ + char *vbuf; + int vsiz, rv; + if(!(vbuf = dpget(depot, kbuf, ksiz, 0, -1, &vsiz)) || vsiz != sizeof(int)){ + free(vbuf); + return INT_MIN; + } + rv = *(int *)vbuf; + free(vbuf); + return rv; +} + + +/* Get the path of a large object. + `curia' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the key. + The return value is a path string whose region is allocated by `malloc'. */ +static char *crgetlobpath(CURIA *curia, const char *kbuf, int ksiz){ + char prefix[CR_PATHBUFSIZ], *wp, *path; + int i, hash; + assert(curia && kbuf && ksiz >= 0); + wp = prefix; + wp += sprintf(wp, "%s%c%04d%c%s%c", + curia->name, MYPATHCHR, dpouterhash(kbuf, ksiz) % curia->dnum + 1, + MYPATHCHR, CR_LOBDIR, MYPATHCHR); + hash = dpinnerhash(kbuf, ksiz); + for(i = 0; i < CR_LOBDDEPTH; i++){ + wp += sprintf(wp, "%02X%c", hash % 0x100, MYPATHCHR); + hash /= 0x100; + } + if(!(path = malloc(strlen(prefix) + ksiz * 2 + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return NULL; + } + wp = path; + wp += sprintf(path, "%s", prefix); + for(i = 0; i < ksiz; i++){ + wp += sprintf(wp, "%02X", ((unsigned char *)kbuf)[i]); + } + return path; +} + + +/* Create directories included in a path. + `path' specifies a path. + The return value is true if successful, else, it is false. */ +static int crmklobdir(const char *path){ + char elem[CR_PATHBUFSIZ], *wp; + const char *dp; + int err, len; + wp = elem; + err = FALSE; + while(*path != '\0' && (dp = strchr(path, MYPATHCHR)) != NULL){ + len = dp - path; + if((wp != elem || dp == path)) wp += sprintf(wp, "%c", MYPATHCHR); + memcpy(wp, path, len); + wp[len] = '\0'; + wp += len; + if(mkdir(elem, CR_DIRMODE) == -1 && errno != EEXIST) err = TRUE; + path = dp + 1; + } + if(err) dpecodeset(DP_EMKDIR, __FILE__, __LINE__); + return err ? FALSE : TRUE; +} + + +/* Remove file and directories under a directory. + `path' specifies a path. + The return value is true if successful, else, it is false. */ +static int crrmlobdir(const char *path){ + char elem[CR_PATHBUFSIZ]; + DIR *DD; + struct dirent *dp; + assert(path); + if(unlink(path) != -1){ + return TRUE; + } else { + if(errno == ENOENT) return TRUE; + if(!(DD = opendir(path))){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + while((dp = readdir(DD)) != NULL){ + if(!strcmp(dp->d_name, MYCDIRSTR) || !strcmp(dp->d_name, MYPDIRSTR)) continue; + sprintf(elem, "%s%c%s", path, MYPATHCHR, dp->d_name); + if(!crrmlobdir(elem)){ + closedir(DD); + return FALSE; + } + } + } + if(closedir(DD) == -1){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + if(rmdir(path) == -1){ + dpecodeset(DP_ERMDIR, __FILE__, __LINE__); + return FALSE; + } + return TRUE; +} + + +/* Copy file and directories under a directory for repairing. + `path' specifies a path. + The return value is true if successful, else, it is false. */ +static int crcplobdir(CURIA *curia, const char *path){ + char elem[CR_PATHBUFSIZ], numbuf[3], *rp, *kbuf, *vbuf; + DIR *DD; + struct dirent *dp; + struct stat sbuf; + int i, ksiz, vsiz, fd; + assert(curia && path); + if(lstat(path, &sbuf) == -1){ + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + return FALSE; + } + if(S_ISREG(sbuf.st_mode)){ + rp = strrchr(path, MYPATHCHR) + 1; + for(i = 0; rp[i] != '\0'; i += 2){ + numbuf[0] = rp[i]; + numbuf[1] = rp[i+1]; + numbuf[2] = '\0'; + elem[i/2] = (int)strtol(numbuf, NULL, 16); + } + kbuf = elem; + ksiz = i / 2; + vsiz = sbuf.st_size; + if(!(vbuf = malloc(vsiz + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return FALSE; + } + if((fd = open(path, O_RDONLY, CR_FILEMODE)) == -1){ + free(vbuf); + dpecodeset(DP_EOPEN, __FILE__, __LINE__); + return FALSE; + } + if(crread(fd, vbuf, vsiz) == -1){ + close(fd); + free(vbuf); + dpecodeset(DP_EOPEN, __FILE__, __LINE__); + return FALSE; + } + if(!crputlob(curia, kbuf, ksiz, vbuf, vsiz, DP_DOVER)){ + close(fd); + free(vbuf); + return FALSE; + } + close(fd); + free(vbuf); + return TRUE; + } + if(!(DD = opendir(path))){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + while((dp = readdir(DD)) != NULL){ + if(!strcmp(dp->d_name, MYCDIRSTR) || !strcmp(dp->d_name, MYPDIRSTR)) continue; + sprintf(elem, "%s%c%s", path, MYPATHCHR, dp->d_name); + if(!crcplobdir(curia, elem)){ + closedir(DD); + return FALSE; + } + } + if(closedir(DD) == -1){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + return TRUE; +} + + +/* Write into a file. + `fd' specifies a file descriptor. + `buf' specifies a buffer to write. + `size' specifies the size of the buffer. + The return value is the size of the written buffer, or, -1 on failure. */ +static int crwrite(int fd, const void *buf, int size){ + char *lbuf; + int rv, wb; + assert(fd >= 0 && buf && size >= 0); + lbuf = (char *)buf; + rv = 0; + do { + wb = write(fd, lbuf, size); + switch(wb){ + case -1: if(errno != EINTR) return -1; + case 0: break; + default: + lbuf += wb; + size -= wb; + rv += wb; + break; + } + } while(size > 0); + return rv; +} + + +/* Read from a file and store the data into a buffer. + `fd' specifies a file descriptor. + `buffer' specifies a buffer to store into. + `size' specifies the size to read with. + The return value is the size read with, or, -1 on failure. */ +static int crread(int fd, void *buf, int size){ + char *lbuf; + int i, bs; + assert(fd >= 0 && buf && size >= 0); + lbuf = buf; + for(i = 0; i < size && (bs = read(fd, lbuf + i, size - i)) != 0; i += bs){ + if(bs == -1 && errno != EINTR) return -1; + } + return i; +} + + + +/* END OF FILE */ diff --git a/qdbm/curia.h b/qdbm/curia.h new file mode 100644 index 00000000..24ce23f3 --- /dev/null +++ b/qdbm/curia.h @@ -0,0 +1,474 @@ +/************************************************************************************************* + * The extended API of QDBM + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#ifndef _CURIA_H /* duplication check */ +#define _CURIA_H + +#if defined(__cplusplus) /* export for C++ */ +extern "C" { +#endif + + +#include +#include +#include + + +#if defined(_MSC_VER) && !defined(QDBM_INTERNAL) && !defined(QDBM_STATIC) +#define MYEXTERN extern __declspec(dllimport) +#else +#define MYEXTERN extern +#endif + + + +/************************************************************************************************* + * API + *************************************************************************************************/ + + +typedef struct { /* type of structure for the database handle */ + char *name; /* name of the database directory */ + int wmode; /* whether to be writable */ + int inode; /* inode of the database directory */ + DEPOT *attr; /* database handle for attributes */ + DEPOT **depots; /* handles of the record database */ + int dnum; /* number of record database handles */ + int inum; /* number of the database of the using iterator */ + int lrnum; /* number of large objects */ +} CURIA; + +enum { /* enumeration for open modes */ + CR_OREADER = 1 << 0, /* open as a reader */ + CR_OWRITER = 1 << 1, /* open as a writer */ + CR_OCREAT = 1 << 2, /* a writer creating */ + CR_OTRUNC = 1 << 3, /* a writer truncating */ + CR_ONOLCK = 1 << 4, /* open without locking */ + CR_OLCKNB = 1 << 5, /* lock without blocking */ + CR_OSPARSE = 1 << 6 /* create as sparse files */ +}; + +enum { /* enumeration for write modes */ + CR_DOVER, /* overwrite an existing value */ + CR_DKEEP, /* keep an existing value */ + CR_DCAT /* concatenate values */ +}; + + +/* Get a database handle. + `name' specifies the name of a database directory. + `omode' specifies the connection mode: `CR_OWRITER' as a writer, `CR_OREADER' as a reader. + If the mode is `CR_OWRITER', the following may be added by bitwise or: `CR_OCREAT', which + means it creates a new database if not exist, `CR_OTRUNC', which means it creates a new + database regardless if one exists. Both of `CR_OREADER' and `CR_OWRITER' can be added to by + bitwise or: `CR_ONOLCK', which means it opens a database directory without file locking, or + `CR_OLCKNB', which means locking is performed without blocking. `CR_OCREAT' can be added to + by bitwise or: `CR_OSPARSE', which means it creates database files as sparse files. + `bnum' specifies the number of elements of each bucket array. If it is not more than 0, + the default value is specified. The size of each bucket array is determined on creating, + and can not be changed except for by optimization of the database. Suggested size of each + bucket array is about from 0.5 to 4 times of the number of all records to store. + `dnum' specifies the number of division of the database. If it is not more than 0, the + default value is specified. The number of division can not be changed from the initial value. + The max number of division is 512. + The return value is the database handle or `NULL' if it is not successful. + While connecting as a writer, an exclusive lock is invoked to the database directory. + While connecting as a reader, a shared lock is invoked to the database directory. + The thread blocks until the lock is achieved. If `CR_ONOLCK' is used, the application is + responsible for exclusion control. */ +CURIA *cropen(const char *name, int omode, int bnum, int dnum); + + +/* Close a database handle. + `curia' specifies a database handle. + If successful, the return value is true, else, it is false. + Because the region of a closed handle is released, it becomes impossible to use the handle. + Updating a database is assured to be written when the handle is closed. If a writer opens + a database but does not close it appropriately, the database will be broken. */ +int crclose(CURIA *curia); + + +/* Store a record. + `curia' specifies a database handle connected as a writer. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region of the value. If it is negative, the size is + assigned with `strlen(vbuf)'. + `dmode' specifies behavior when the key overlaps, by the following values: `CR_DOVER', + which means the specified value overwrites the existing one, `CR_DKEEP', which means the + existing value is kept, `CR_DCAT', which means the specified value is concatenated at the + end of the existing value. + If successful, the return value is true, else, it is false. */ +int crput(CURIA *curia, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode); + + +/* Delete a record. + `curia' specifies a database handle connected as a writer. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is true, else, it is false. False is returned when no + record corresponds to the specified key. */ +int crout(CURIA *curia, const char *kbuf, int ksiz); + + +/* Retrieve a record. + `curia' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `start' specifies the offset address of the beginning of the region of the value to be read. + `max' specifies the max size to be read. If it is negative, the size to read is unlimited. + `sp' specifies the pointer to a variable to which the size of the region of the return value + is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to + the specified key or the size of the value of the corresponding record is less than `start'. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. */ +char *crget(CURIA *curia, const char *kbuf, int ksiz, int start, int max, int *sp); + + +/* Retrieve a record and write the value into a buffer. + `curia' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `start' specifies the offset address of the beginning of the region of the value to be read. + `max' specifies the max size to be read. It shuld be equal to or less than the size of the + writing buffer. + `vbuf' specifies the pointer to a buffer into which the value of the corresponding record is + written. + If successful, the return value is the size of the written data, else, it is -1. -1 is + returned when no record corresponds to the specified key or the size of the value of the + corresponding record is less than `start'. + Note that no additional zero code is appended at the end of the region of the writing buffer. */ +int crgetwb(CURIA *curia, const char *kbuf, int ksiz, int start, int max, char *vbuf); + + +/* Get the size of the value of a record. + `curia' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is the size of the value of the corresponding record, else, + it is -1. + Because this function does not read the entity of a record, it is faster than `crget'. */ +int crvsiz(CURIA *curia, const char *kbuf, int ksiz); + + +/* Initialize the iterator of a database handle. + `curia' specifies a database handle. + If successful, the return value is true, else, it is false. + The iterator is used in order to access the key of every record stored in a database. */ +int criterinit(CURIA *curia); + + +/* Get the next key of the iterator. + `curia' specifies a database handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the next key, else, it is + `NULL'. `NULL' is returned when no record is to be get out of the iterator. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. It is possible to access every record by iteration of calling this + function. However, it is not assured if updating the database is occurred while the + iteration. Besides, the order of this traversal access method is arbitrary, so it is not + assured that the order of storing matches the one of the traversal access. */ +char *criternext(CURIA *curia, int *sp); + + +/* Set alignment of a database handle. + `curia' specifies a database handle connected as a writer. + `align' specifies the size of alignment. + If successful, the return value is true, else, it is false. + If alignment is set to a database, the efficiency of overwriting values is improved. + The size of alignment is suggested to be average size of the values of the records to be + stored. If alignment is positive, padding whose size is multiple number of the alignment + is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding + is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not + saved in a database, you should specify alignment every opening a database. */ +int crsetalign(CURIA *curia, int align); + + +/* Set the size of the free block pool of a database handle. + `curia' specifies a database handle connected as a writer. + `size' specifies the size of the free block pool of a database. + If successful, the return value is true, else, it is false. + The default size of the free block pool is 16. If the size is greater, the space efficiency + of overwriting values is improved with the time efficiency sacrificed. */ +int crsetfbpsiz(CURIA *curia, int size); + + +/* Synchronize updating contents with the files and the devices. + `curia' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. + This function is useful when another process uses the connected database directory. */ +int crsync(CURIA *curia); + + +/* Optimize a database. + `curia' specifies a database handle connected as a writer. + `bnum' specifies the number of the elements of each bucket array. If it is not more than 0, + the default value is specified. + If successful, the return value is true, else, it is false. + In an alternating succession of deleting and storing with overwrite or concatenate, + dispensable regions accumulate. This function is useful to do away with them. */ +int croptimize(CURIA *curia, int bnum); + +/* Get the name of a database. + `curia' specifies a database handle. + If successful, the return value is the pointer to the region of the name of the database, + else, it is `NULL'. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *crname(CURIA *curia); + + +/* Get the total size of database files. + `curia' specifies a database handle. + If successful, the return value is the total size of the database files, else, it is -1. + If the total size is more than 2GB, the return value overflows. */ +int crfsiz(CURIA *curia); + + +/* Get the total size of database files as double-precision floating-point number. + `curia' specifies a database handle. + If successful, the return value is the total size of the database files, else, it is -1.0. */ +double crfsizd(CURIA *curia); + + +/* Get the total number of the elements of each bucket array. + `curia' specifies a database handle. + If successful, the return value is the total number of the elements of each bucket array, + else, it is -1. */ +int crbnum(CURIA *curia); + + +/* Get the total number of the used elements of each bucket array. + `curia' specifies a database handle. + If successful, the return value is the total number of the used elements of each bucket + array, else, it is -1. + This function is inefficient because it accesses all elements of each bucket array. */ +int crbusenum(CURIA *curia); + + +/* Get the number of the records stored in a database. + `curia' specifies a database handle. + If successful, the return value is the number of the records stored in the database, else, + it is -1. */ +int crrnum(CURIA *curia); + + +/* Check whether a database handle is a writer or not. + `curia' specifies a database handle. + The return value is true if the handle is a writer, false if not. */ +int crwritable(CURIA *curia); + + +/* Check whether a database has a fatal error or not. + `curia' specifies a database handle. + The return value is true if the database has a fatal error, false if not. */ +int crfatalerror(CURIA *curia); + + +/* Get the inode number of a database directory. + `curia' specifies a database handle. + The return value is the inode number of the database directory. */ +int crinode(CURIA *curia); + + +/* Get the last modified time of a database. + `curia' specifies a database handle. + The return value is the last modified time of the database. */ +time_t crmtime(CURIA *curia); + + +/* Remove a database directory. + `name' specifies the name of a database directory. + If successful, the return value is true, else, it is false. */ +int crremove(const char *name); + + +/* Repair a broken database directory. + `name' specifies the name of a database directory. + If successful, the return value is true, else, it is false. + There is no guarantee that all records in a repaired database directory correspond to the + original or expected state. */ +int crrepair(const char *name); + + +/* Dump all records as endian independent data. + `curia' specifies a database handle. + `name' specifies the name of an output directory. + If successful, the return value is true, else, it is false. + Note that large objects are ignored. */ +int crexportdb(CURIA *curia, const char *name); + + +/* Load all records from endian independent data. + `curia' specifies a database handle connected as a writer. The database of the handle must + be empty. + `name' specifies the name of an input directory. + If successful, the return value is true, else, it is false. + Note that large objects are ignored. */ +int crimportdb(CURIA *curia, const char *name); + + +/* Retrieve a record directly from a database directory. + `name' specifies the name of a database directory. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to + the specified key. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. Although this function can be used even while the database directory is + locked by another process, it is not assured that recent updated is reflected. */ +char *crsnaffle(const char *name, const char *kbuf, int ksiz, int *sp); + + +/* Store a large object. + `curia' specifies a database handle connected as a writer. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region of the value. If it is negative, the size is + assigned with `strlen(vbuf)'. + `dmode' specifies behavior when the key overlaps, by the following values: `CR_DOVER', + which means the specified value overwrites the existing one, `CR_DKEEP', which means the + existing value is kept, `CR_DCAT', which means the specified value is concatenated at the + end of the existing value. + If successful, the return value is true, else, it is false. */ +int crputlob(CURIA *curia, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode); + + +/* Delete a large object. + `curia' specifies a database handle connected as a writer. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is true, else, it is false. false is returned when no large + object corresponds to the specified key. */ +int croutlob(CURIA *curia, const char *kbuf, int ksiz); + + +/* Retrieve a large object. + `curia' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `start' specifies the offset address of the beginning of the region of the value to be read. + `max' specifies the max size to be read. If it is negative, the size to read is unlimited. + `sp' specifies the pointer to a variable to which the size of the region of the return value + is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding large object, else, it is `NULL'. `NULL' is returned when no large object + corresponds to the specified key or the size of the value of the corresponding large object + is less than `start'. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. */ +char *crgetlob(CURIA *curia, const char *kbuf, int ksiz, int start, int max, int *sp); + + +/* Get the file descriptor of a large object. + `curia' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is the file descriptor of the corresponding large object, + else, it is -1. -1 is returned when no large object corresponds to the specified key. The + returned file descriptor is opened with the `open' call. If the database handle was opened + as a writer, the descriptor is writable (O_RDWR), else, it is not writable (O_RDONLY). The + descriptor should be closed with the `close' call if it is no longer in use. */ +int crgetlobfd(CURIA *curia, const char *kbuf, int ksiz); + + +/* Get the size of the value of a large object. + `curia' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is the size of the value of the corresponding large object, + else, it is -1. + Because this function does not read the entity of a large object, it is faster than + `crgetlob'. */ +int crvsizlob(CURIA *curia, const char *kbuf, int ksiz); + + +/* Get the number of the large objects stored in a database. + `curia' specifies a database handle. + If successful, the return value is the number of the large objects stored in the database, + else, it is -1. */ +int crrnumlob(CURIA *curia); + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Synchronize updating contents on memory. + `curia' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. */ +int crmemsync(CURIA *curia); + + +/* Synchronize updating contents on memory, not physically. + `curia' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. */ +int crmemflush(CURIA *curia); + + +/* Get flags of a database. + `curia' specifies a database handle. + The return value is the flags of a database. */ +int crgetflags(CURIA *curia); + + +/* Set flags of a database. + `curia' specifies a database handle connected as a writer. + `flags' specifies flags to set. Least ten bits are reserved for internal use. + If successful, the return value is true, else, it is false. */ +int crsetflags(CURIA *curia, int flags); + + + +#undef MYEXTERN + +#if defined(__cplusplus) /* export for C++ */ +} +#endif + +#endif /* duplication check */ + + +/* END OF FILE */ diff --git a/qdbm/depot.c b/qdbm/depot.c new file mode 100644 index 00000000..717335b8 --- /dev/null +++ b/qdbm/depot.c @@ -0,0 +1,2219 @@ +/************************************************************************************************* + * Implementation of Depot + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#define QDBM_INTERNAL 1 + +#include "depot.h" +#include "myconf.h" + +#define DP_FILEMODE 00644 /* permission of a creating file */ +#define DP_MAGICNUMB "[DEPOT]\n\f" /* magic number on environments of big endian */ +#define DP_MAGICNUML "[depot]\n\f" /* magic number on environments of little endian */ +#define DP_HEADSIZ 48 /* size of the reagion of the header */ +#define DP_LIBVEROFF 12 /* offset of the region for the library version */ +#define DP_FLAGSOFF 16 /* offset of the region for flags */ +#define DP_FSIZOFF 24 /* offset of the region for the file size */ +#define DP_BNUMOFF 32 /* offset of the region for the bucket number */ +#define DP_RNUMOFF 40 /* offset of the region for the record number */ +#define DP_DEFBNUM 8191 /* default bucket number */ +#define DP_FBPOOLSIZ 16 /* size of free block pool */ +#define DP_ENTBUFSIZ 128 /* size of the entity buffer */ +#define DP_STKBUFSIZ 256 /* size of the stack key buffer */ +#define DP_WRTBUFSIZ 8192 /* size of the writing buffer */ +#define DP_FSBLKSIZ 4096 /* size of a block of the file system */ +#define DP_TMPFSUF MYEXTSTR "dptmp" /* suffix of a temporary file */ +#define DP_OPTBLOAD 0.25 /* ratio of bucket loading at optimization */ +#define DP_OPTRUNIT 256 /* number of records in a process of optimization */ +#define DP_NUMBUFSIZ 32 /* size of a buffer for a number */ +#define DP_IOBUFSIZ 8192 /* size of an I/O buffer */ + +/* get the first hash value */ +#define DP_FIRSTHASH(DP_res, DP_kbuf, DP_ksiz) \ + do { \ + const unsigned char *_DP_p; \ + int _DP_ksiz; \ + _DP_p = (const unsigned char *)(DP_kbuf); \ + _DP_ksiz = DP_ksiz; \ + if((_DP_ksiz) == sizeof(int)){ \ + memcpy(&(DP_res), (DP_kbuf), sizeof(int)); \ + } else { \ + (DP_res) = 751; \ + } \ + while(_DP_ksiz--){ \ + (DP_res) = (DP_res) * 31 + *(_DP_p)++; \ + } \ + (DP_res) = ((DP_res) * 87767623) & INT_MAX; \ + } while(FALSE) + +/* get the second hash value */ +#define DP_SECONDHASH(DP_res, DP_kbuf, DP_ksiz) \ + do { \ + const unsigned char *_DP_p; \ + int _DP_ksiz; \ + _DP_p = (const unsigned char *)(DP_kbuf) + DP_ksiz - 1; \ + _DP_ksiz = DP_ksiz; \ + for((DP_res) = 19780211; _DP_ksiz--;){ \ + (DP_res) = (DP_res) * 37 + *(_DP_p)--; \ + } \ + (DP_res) = ((DP_res) * 43321879) & INT_MAX; \ + } while(FALSE) + +/* get the third hash value */ +#define DP_THIRDHASH(DP_res, DP_kbuf, DP_ksiz) \ + do { \ + int _DP_i; \ + (DP_res) = 774831917; \ + for(_DP_i = (DP_ksiz) - 1; _DP_i >= 0; _DP_i--){ \ + (DP_res) = (DP_res) * 29 + ((const unsigned char *)(DP_kbuf))[_DP_i]; \ + } \ + (DP_res) = ((DP_res) * 5157883) & INT_MAX; \ + } while(FALSE) + +enum { /* enumeration for a record header */ + DP_RHIFLAGS, /* offset of flags */ + DP_RHIHASH, /* offset of value of the second hash function */ + DP_RHIKSIZ, /* offset of the size of the key */ + DP_RHIVSIZ, /* offset of the size of the value */ + DP_RHIPSIZ, /* offset of the size of the padding bytes */ + DP_RHILEFT, /* offset of the offset of the left child */ + DP_RHIRIGHT, /* offset of the offset of the right child */ + DP_RHNUM /* number of elements of a header */ +}; + +enum { /* enumeration for the flag of a record */ + DP_RECFDEL = 1 << 0, /* deleted */ + DP_RECFREUSE = 1 << 1 /* reusable */ +}; + + +/* private function prototypes */ +static int dpbigendian(void); +static char *dpstrdup(const char *str); +static int dplock(int fd, int ex, int nb); +static int dpwrite(int fd, const void *buf, int size); +static int dpseekwrite(int fd, int off, const void *buf, int size); +static int dpseekwritenum(int fd, int off, int num); +static int dpread(int fd, void *buf, int size); +static int dpseekread(int fd, int off, void *buf, int size); +static int dpfcopy(int destfd, int destoff, int srcfd, int srcoff); +static int dpgetprime(int num); +static int dppadsize(DEPOT *depot, int ksiz, int vsiz); +static int dprecsize(int *head); +static int dprechead(DEPOT *depot, int off, int *head, char *ebuf, int *eep); +static char *dpreckey(DEPOT *depot, int off, int *head); +static char *dprecval(DEPOT *depot, int off, int *head, int start, int max); +static int dprecvalwb(DEPOT *depot, int off, int *head, int start, int max, char *vbuf); +static int dpkeycmp(const char *abuf, int asiz, const char *bbuf, int bsiz); +static int dprecsearch(DEPOT *depot, const char *kbuf, int ksiz, int hash, int *bip, int *offp, + int *entp, int *head, char *ebuf, int *eep, int delhit); +static int dprecrewrite(DEPOT *depot, int off, int rsiz, const char *kbuf, int ksiz, + const char *vbuf, int vsiz, int hash, int left, int right); +static int dprecappend(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, + int hash, int left, int right); +static int dprecover(DEPOT *depot, int off, int *head, const char *vbuf, int vsiz, int cat); +static int dprecdelete(DEPOT *depot, int off, int *head, int reusable); +static void dpfbpoolcoal(DEPOT *depot); +static int dpfbpoolcmp(const void *a, const void *b); + + + +/************************************************************************************************* + * public objects + *************************************************************************************************/ + + +/* String containing the version information. */ +const char *dpversion = _QDBM_VERSION; + + +/* Get a message string corresponding to an error code. */ +const char *dperrmsg(int ecode){ + switch(ecode){ + case DP_ENOERR: return "no error"; + case DP_EFATAL: return "with fatal error"; + case DP_EMODE: return "invalid mode"; + case DP_EBROKEN: return "broken database file"; + case DP_EKEEP: return "existing record"; + case DP_ENOITEM: return "no item found"; + case DP_EALLOC: return "memory allocation error"; + case DP_EMAP: return "memory mapping error"; + case DP_EOPEN: return "open error"; + case DP_ECLOSE: return "close error"; + case DP_ETRUNC: return "trunc error"; + case DP_ESYNC: return "sync error"; + case DP_ESTAT: return "stat error"; + case DP_ESEEK: return "seek error"; + case DP_EREAD: return "read error"; + case DP_EWRITE: return "write error"; + case DP_ELOCK: return "lock error"; + case DP_EUNLINK: return "unlink error"; + case DP_EMKDIR: return "mkdir error"; + case DP_ERMDIR: return "rmdir error"; + case DP_EMISC: return "miscellaneous error"; + } + return "(invalid ecode)"; +} + + +/* Get a database handle. */ +DEPOT *dpopen(const char *name, int omode, int bnum){ + char hbuf[DP_HEADSIZ], *map, c, *tname; + int i, mode, fd, inode, fsiz, rnum, msiz, *fbpool; + struct stat sbuf; + time_t mtime; + DEPOT *depot; + assert(name); + mode = O_RDONLY; + if(omode & DP_OWRITER){ + mode = O_RDWR; + if(omode & DP_OCREAT) mode |= O_CREAT; + } + if((fd = open(name, mode, DP_FILEMODE)) == -1){ + dpecodeset(DP_EOPEN, __FILE__, __LINE__); + return NULL; + } + if(!(omode & DP_ONOLCK)){ + if(!dplock(fd, omode & DP_OWRITER, omode & DP_OLCKNB)){ + close(fd); + return NULL; + } + } + if((omode & DP_OWRITER) && (omode & DP_OTRUNC)){ + if(ftruncate(fd, 0) == -1){ + close(fd); + dpecodeset(DP_ETRUNC, __FILE__, __LINE__); + return NULL; + } + } + if(fstat(fd, &sbuf) == -1 || !S_ISREG(sbuf.st_mode) || + (sbuf.st_ino == 0 && lstat(name, &sbuf) == -1)){ + close(fd); + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + return NULL; + } + inode = sbuf.st_ino; + mtime = sbuf.st_mtime; + fsiz = sbuf.st_size; + if((omode & DP_OWRITER) && fsiz == 0){ + memset(hbuf, 0, DP_HEADSIZ); + if(dpbigendian()){ + memcpy(hbuf, DP_MAGICNUMB, strlen(DP_MAGICNUMB)); + } else { + memcpy(hbuf, DP_MAGICNUML, strlen(DP_MAGICNUML)); + } + sprintf(hbuf + DP_LIBVEROFF, "%d", _QDBM_LIBVER / 100); + bnum = bnum < 1 ? DP_DEFBNUM : bnum; + bnum = dpgetprime(bnum); + memcpy(hbuf + DP_BNUMOFF, &bnum, sizeof(int)); + rnum = 0; + memcpy(hbuf + DP_RNUMOFF, &rnum, sizeof(int)); + fsiz = DP_HEADSIZ + bnum * sizeof(int); + memcpy(hbuf + DP_FSIZOFF, &fsiz, sizeof(int)); + if(!dpseekwrite(fd, 0, hbuf, DP_HEADSIZ)){ + close(fd); + return NULL; + } + if(omode & DP_OSPARSE){ + c = 0; + if(!dpseekwrite(fd, fsiz - 1, &c, 1)){ + close(fd); + return NULL; + } + } else { + if(!(map = malloc(bnum * sizeof(int)))){ + close(fd); + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return NULL; + } + memset(map, 0, bnum * sizeof(int)); + if(!dpseekwrite(fd, DP_HEADSIZ, map, bnum * sizeof(int))){ + free(map); + close(fd); + return NULL; + } + free(map); + } + } + if(!dpseekread(fd, 0, hbuf, DP_HEADSIZ)){ + close(fd); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + if(!(omode & DP_ONOLCK) && + ((dpbigendian() ? memcmp(hbuf, DP_MAGICNUMB, strlen(DP_MAGICNUMB)) != 0 : + memcmp(hbuf, DP_MAGICNUML, strlen(DP_MAGICNUML)) != 0) || + *((int *)(hbuf + DP_FSIZOFF)) != fsiz)){ + close(fd); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + bnum = *((int *)(hbuf + DP_BNUMOFF)); + rnum = *((int *)(hbuf + DP_RNUMOFF)); + if(bnum < 1 || rnum < 0 || fsiz < DP_HEADSIZ + bnum * sizeof(int)){ + close(fd); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + msiz = DP_HEADSIZ + bnum * sizeof(int); + map = mmap(0, msiz, PROT_READ | ((mode & DP_OWRITER) ? PROT_WRITE : 0), MAP_SHARED, fd, 0); + if(map == MAP_FAILED){ + close(fd); + dpecodeset(DP_EMAP, __FILE__, __LINE__); + return NULL; + } + tname = NULL; + fbpool = NULL; + if(!(depot = malloc(sizeof(DEPOT))) || !(tname = dpstrdup(name)) || + !(fbpool = malloc(DP_FBPOOLSIZ * 2 * sizeof(int)))){ + free(fbpool); + free(tname); + free(depot); + munmap(map, msiz); + close(fd); + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return NULL; + } + depot->name = tname; + depot->wmode = (mode & DP_OWRITER); + depot->inode = inode; + depot->mtime = mtime; + depot->fd = fd; + depot->fsiz = fsiz; + depot->map = map; + depot->msiz = msiz; + depot->buckets = (int *)(map + DP_HEADSIZ); + depot->bnum = bnum; + depot->rnum = rnum; + depot->fatal = FALSE; + depot->ioff = 0; + depot->fbpool = fbpool; + for(i = 0; i < DP_FBPOOLSIZ * 2; i += 2){ + depot->fbpool[i] = -1; + depot->fbpool[i+1] = -1; + } + depot->fbpsiz = DP_FBPOOLSIZ * 2; + depot->fbpinc = 0; + depot->align = 0; + return depot; +} + + +/* Close a database handle. */ +int dpclose(DEPOT *depot){ + int fatal, err; + assert(depot); + fatal = depot->fatal; + err = FALSE; + if(depot->wmode){ + *((int *)(depot->map + DP_FSIZOFF)) = depot->fsiz; + *((int *)(depot->map + DP_RNUMOFF)) = depot->rnum; + } + if(depot->map != MAP_FAILED){ + if(munmap(depot->map, depot->msiz) == -1){ + err = TRUE; + dpecodeset(DP_EMAP, __FILE__, __LINE__); + } + } + if(close(depot->fd) == -1){ + err = TRUE; + dpecodeset(DP_ECLOSE, __FILE__, __LINE__); + } + free(depot->fbpool); + free(depot->name); + free(depot); + if(fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + return err ? FALSE : TRUE; +} + + +/* Store a record. */ +int dpput(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode){ + int head[DP_RHNUM], next[DP_RHNUM]; + int i, hash, bi, off, entoff, ee, newoff, rsiz, nsiz, fdel, mroff, mrsiz, mi, min; + char ebuf[DP_ENTBUFSIZ], *tval, *swap; + assert(depot && kbuf && vbuf); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!depot->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(ksiz < 0) ksiz = strlen(kbuf); + if(vsiz < 0) vsiz = strlen(vbuf); + newoff = -1; + DP_SECONDHASH(hash, kbuf, ksiz); + switch(dprecsearch(depot, kbuf, ksiz, hash, &bi, &off, &entoff, head, ebuf, &ee, TRUE)){ + case -1: + depot->fatal = TRUE; + return FALSE; + case 0: + fdel = head[DP_RHIFLAGS] & DP_RECFDEL; + if(dmode == DP_DKEEP && !fdel){ + dpecodeset(DP_EKEEP, __FILE__, __LINE__); + return FALSE; + } + if(fdel){ + head[DP_RHIPSIZ] += head[DP_RHIVSIZ]; + head[DP_RHIVSIZ] = 0; + } + rsiz = dprecsize(head); + nsiz = DP_RHNUM * sizeof(int) + ksiz + vsiz; + if(dmode == DP_DCAT) nsiz += head[DP_RHIVSIZ]; + if(off + rsiz >= depot->fsiz){ + if(rsiz < nsiz){ + head[DP_RHIPSIZ] += nsiz - rsiz; + rsiz = nsiz; + depot->fsiz = off + rsiz; + } + } else { + while(nsiz > rsiz && off + rsiz < depot->fsiz){ + if(!dprechead(depot, off + rsiz, next, NULL, NULL)) return FALSE; + if(!(next[DP_RHIFLAGS] & DP_RECFREUSE)) break; + head[DP_RHIPSIZ] += dprecsize(next); + rsiz += dprecsize(next); + } + for(i = 0; i < depot->fbpsiz; i += 2){ + if(depot->fbpool[i] >= off && depot->fbpool[i] < off + rsiz){ + depot->fbpool[i] = -1; + depot->fbpool[i+1] = -1; + } + } + } + if(nsiz <= rsiz){ + if(!dprecover(depot, off, head, vbuf, vsiz, dmode == DP_DCAT)){ + depot->fatal = TRUE; + return FALSE; + } + } else { + tval = NULL; + if(dmode == DP_DCAT){ + if(ee && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] <= DP_ENTBUFSIZ){ + if(!(tval = malloc(head[DP_RHIVSIZ] + vsiz + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + depot->fatal = TRUE; + return FALSE; + } + memcpy(tval, ebuf + (DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ]), head[DP_RHIVSIZ]); + } else { + if(!(tval = dprecval(depot, off, head, 0, -1))){ + depot->fatal = TRUE; + return FALSE; + } + if(!(swap = realloc(tval, head[DP_RHIVSIZ] + vsiz + 1))){ + free(tval); + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + depot->fatal = TRUE; + return FALSE; + } + tval = swap; + } + memcpy(tval + head[DP_RHIVSIZ], vbuf, vsiz); + vsiz += head[DP_RHIVSIZ]; + vbuf = tval; + } + mi = -1; + min = -1; + for(i = 0; i < depot->fbpsiz; i += 2){ + if(depot->fbpool[i+1] < nsiz) continue; + if(mi == -1 || depot->fbpool[i+1] < min){ + mi = i; + min = depot->fbpool[i+1]; + } + } + if(mi >= 0){ + mroff = depot->fbpool[mi]; + mrsiz = depot->fbpool[mi+1]; + depot->fbpool[mi] = -1; + depot->fbpool[mi+1] = -1; + } else { + mroff = -1; + mrsiz = -1; + } + if(!dprecdelete(depot, off, head, TRUE)){ + free(tval); + depot->fatal = TRUE; + return FALSE; + } + if(mroff > 0 && nsiz <= mrsiz){ + if(!dprecrewrite(depot, mroff, mrsiz, kbuf, ksiz, vbuf, vsiz, + hash, head[DP_RHILEFT], head[DP_RHIRIGHT])){ + free(tval); + depot->fatal = TRUE; + return FALSE; + } + newoff = mroff; + } else { + if((newoff = dprecappend(depot, kbuf, ksiz, vbuf, vsiz, + hash, head[DP_RHILEFT], head[DP_RHIRIGHT])) == -1){ + free(tval); + depot->fatal = TRUE; + return FALSE; + } + } + free(tval); + } + if(fdel) depot->rnum++; + break; + default: + if((newoff = dprecappend(depot, kbuf, ksiz, vbuf, vsiz, hash, 0, 0)) == -1){ + depot->fatal = TRUE; + return FALSE; + } + depot->rnum++; + break; + } + if(newoff > 0){ + if(entoff > 0){ + if(!dpseekwritenum(depot->fd, entoff, newoff)){ + depot->fatal = TRUE; + return FALSE; + } + } else { + depot->buckets[bi] = newoff; + } + } + return TRUE; +} + + +/* Delete a record. */ +int dpout(DEPOT *depot, const char *kbuf, int ksiz){ + int head[DP_RHNUM], hash, bi, off, entoff, ee; + char ebuf[DP_ENTBUFSIZ]; + assert(depot && kbuf); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!depot->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(ksiz < 0) ksiz = strlen(kbuf); + DP_SECONDHASH(hash, kbuf, ksiz); + switch(dprecsearch(depot, kbuf, ksiz, hash, &bi, &off, &entoff, head, ebuf, &ee, FALSE)){ + case -1: + depot->fatal = TRUE; + return FALSE; + case 0: + break; + default: + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!dprecdelete(depot, off, head, FALSE)){ + depot->fatal = TRUE; + return FALSE; + } + depot->rnum--; + return TRUE; +} + + +/* Retrieve a record. */ +char *dpget(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, int *sp){ + int head[DP_RHNUM], hash, bi, off, entoff, ee, vsiz; + char ebuf[DP_ENTBUFSIZ], *vbuf; + assert(depot && kbuf && start >= 0); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return NULL; + } + if(ksiz < 0) ksiz = strlen(kbuf); + DP_SECONDHASH(hash, kbuf, ksiz); + switch(dprecsearch(depot, kbuf, ksiz, hash, &bi, &off, &entoff, head, ebuf, &ee, FALSE)){ + case -1: + depot->fatal = TRUE; + return NULL; + case 0: + break; + default: + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return NULL; + } + if(start > head[DP_RHIVSIZ]){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return NULL; + } + if(ee && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] <= DP_ENTBUFSIZ){ + head[DP_RHIVSIZ] -= start; + if(max < 0){ + vsiz = head[DP_RHIVSIZ]; + } else { + vsiz = max < head[DP_RHIVSIZ] ? max : head[DP_RHIVSIZ]; + } + if(!(vbuf = malloc(vsiz + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + depot->fatal = TRUE; + return NULL; + } + memcpy(vbuf, ebuf + (DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + start), vsiz); + vbuf[vsiz] = '\0'; + } else { + if(!(vbuf = dprecval(depot, off, head, start, max))){ + depot->fatal = TRUE; + return NULL; + } + } + if(sp){ + if(max < 0){ + *sp = head[DP_RHIVSIZ]; + } else { + *sp = max < head[DP_RHIVSIZ] ? max : head[DP_RHIVSIZ]; + } + } + return vbuf; +} + + +/* Retrieve a record and write the value into a buffer. */ +int dpgetwb(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, char *vbuf){ + int head[DP_RHNUM], hash, bi, off, entoff, ee, vsiz; + char ebuf[DP_ENTBUFSIZ]; + assert(depot && kbuf && start >= 0 && max >= 0 && vbuf); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + if(ksiz < 0) ksiz = strlen(kbuf); + DP_SECONDHASH(hash, kbuf, ksiz); + switch(dprecsearch(depot, kbuf, ksiz, hash, &bi, &off, &entoff, head, ebuf, &ee, FALSE)){ + case -1: + depot->fatal = TRUE; + return -1; + case 0: + break; + default: + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return -1; + } + if(start > head[DP_RHIVSIZ]){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return -1; + } + if(ee && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] <= DP_ENTBUFSIZ){ + head[DP_RHIVSIZ] -= start; + vsiz = max < head[DP_RHIVSIZ] ? max : head[DP_RHIVSIZ]; + memcpy(vbuf, ebuf + (DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + start), vsiz); + } else { + if((vsiz = dprecvalwb(depot, off, head, start, max, vbuf)) == -1){ + depot->fatal = TRUE; + return -1; + } + } + return vsiz; +} + + +/* Get the size of the value of a record. */ +int dpvsiz(DEPOT *depot, const char *kbuf, int ksiz){ + int head[DP_RHNUM], hash, bi, off, entoff, ee; + char ebuf[DP_ENTBUFSIZ]; + assert(depot && kbuf); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + if(ksiz < 0) ksiz = strlen(kbuf); + DP_SECONDHASH(hash, kbuf, ksiz); + switch(dprecsearch(depot, kbuf, ksiz, hash, &bi, &off, &entoff, head, ebuf, &ee, FALSE)){ + case -1: + depot->fatal = TRUE; + return -1; + case 0: + break; + default: + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return -1; + } + return head[DP_RHIVSIZ]; +} + + +/* Initialize the iterator of a database handle. */ +int dpiterinit(DEPOT *depot){ + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + depot->ioff = 0; + return TRUE; +} + + +/* Get the next key of the iterator. */ +char *dpiternext(DEPOT *depot, int *sp){ + int off, head[DP_RHNUM], ee; + char ebuf[DP_ENTBUFSIZ], *kbuf; + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return NULL; + } + off = DP_HEADSIZ + depot->bnum * sizeof(int); + off = off > depot->ioff ? off : depot->ioff; + while(off < depot->fsiz){ + if(!dprechead(depot, off, head, ebuf, &ee)){ + depot->fatal = TRUE; + return NULL; + } + if(head[DP_RHIFLAGS] & DP_RECFDEL){ + off += dprecsize(head); + } else { + if(ee && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] <= DP_ENTBUFSIZ){ + if(!(kbuf = malloc(head[DP_RHIKSIZ] + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + depot->fatal = TRUE; + return NULL; + } + memcpy(kbuf, ebuf + (DP_RHNUM * sizeof(int)), head[DP_RHIKSIZ]); + kbuf[head[DP_RHIKSIZ]] = '\0'; + } else { + if(!(kbuf = dpreckey(depot, off, head))){ + depot->fatal = TRUE; + return NULL; + } + } + depot->ioff = off + dprecsize(head); + if(sp) *sp = head[DP_RHIKSIZ]; + return kbuf; + } + } + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return NULL; +} + + +/* Set alignment of a database handle. */ +int dpsetalign(DEPOT *depot, int align){ + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!depot->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + depot->align = align; + return TRUE; +} + + +/* Set the size of the free block pool of a database handle. */ +int dpsetfbpsiz(DEPOT *depot, int size){ + int *fbpool; + int i; + assert(depot && size >= 0); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!depot->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + size *= 2; + if(!(fbpool = realloc(depot->fbpool, size * sizeof(int) + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return FALSE; + } + for(i = 0; i < size; i += 2){ + fbpool[i] = -1; + fbpool[i+1] = -1; + } + depot->fbpool = fbpool; + depot->fbpsiz = size; + return TRUE; +} + + + +/* Synchronize contents of updating a database with the file and the device. */ +int dpsync(DEPOT *depot){ + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!depot->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + *((int *)(depot->map + DP_FSIZOFF)) = depot->fsiz; + *((int *)(depot->map + DP_RNUMOFF)) = depot->rnum; + if(msync(depot->map, depot->msiz, MS_SYNC) == -1){ + dpecodeset(DP_EMAP, __FILE__, __LINE__); + depot->fatal = TRUE; + return FALSE; + } + if(fsync(depot->fd) == -1){ + dpecodeset(DP_ESYNC, __FILE__, __LINE__); + depot->fatal = TRUE; + return FALSE; + } + return TRUE; +} + + +/* Optimize a database. */ +int dpoptimize(DEPOT *depot, int bnum){ + DEPOT *tdepot; + char *name; + int i, err, off, head[DP_RHNUM], ee, ksizs[DP_OPTRUNIT], vsizs[DP_OPTRUNIT], unum; + char ebuf[DP_ENTBUFSIZ], *kbufs[DP_OPTRUNIT], *vbufs[DP_OPTRUNIT]; + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!depot->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(!(name = malloc(strlen(depot->name) + strlen(DP_TMPFSUF) + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + depot->fatal = FALSE; + return FALSE; + } + sprintf(name, "%s%s", depot->name, DP_TMPFSUF); + if(bnum < 0){ + bnum = (int)(depot->rnum * (1.0 / DP_OPTBLOAD)) + 1; + if(bnum < DP_DEFBNUM / 2) bnum = DP_DEFBNUM / 2; + } + if(!(tdepot = dpopen(name, DP_OWRITER | DP_OCREAT | DP_OTRUNC, bnum))){ + free(name); + depot->fatal = TRUE; + return FALSE; + } + free(name); + if(!dpsetflags(tdepot, dpgetflags(depot))){ + dpclose(tdepot); + depot->fatal = TRUE; + return FALSE; + } + tdepot->align = depot->align; + err = FALSE; + off = DP_HEADSIZ + depot->bnum * sizeof(int); + unum = 0; + while(off < depot->fsiz){ + if(!dprechead(depot, off, head, ebuf, &ee)){ + err = TRUE; + break; + } + if(!(head[DP_RHIFLAGS] & DP_RECFDEL)){ + if(ee && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] <= DP_ENTBUFSIZ){ + if(!(kbufs[unum] = malloc(head[DP_RHIKSIZ] + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + err = TRUE; + break; + } + memcpy(kbufs[unum], ebuf + (DP_RHNUM * sizeof(int)), head[DP_RHIKSIZ]); + if(DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] <= DP_ENTBUFSIZ){ + if(!(vbufs[unum] = malloc(head[DP_RHIVSIZ] + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + err = TRUE; + break; + } + memcpy(vbufs[unum], ebuf + (DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ]), + head[DP_RHIVSIZ]); + } else { + vbufs[unum] = dprecval(depot, off, head, 0, -1); + } + } else { + kbufs[unum] = dpreckey(depot, off, head); + vbufs[unum] = dprecval(depot, off, head, 0, -1); + } + ksizs[unum] = head[DP_RHIKSIZ]; + vsizs[unum] = head[DP_RHIVSIZ]; + unum++; + if(unum >= DP_OPTRUNIT){ + for(i = 0; i < unum; i++){ + if(kbufs[i] && vbufs[i]){ + if(!dpput(tdepot, kbufs[i], ksizs[i], vbufs[i], vsizs[i], DP_DKEEP)) err = TRUE; + } else { + err = TRUE; + } + free(kbufs[i]); + free(vbufs[i]); + if(err) break; + } + unum = 0; + } + } + off += dprecsize(head); + if(err) break; + } + for(i = 0; i < unum; i++){ + if(kbufs[i] && vbufs[i]){ + if(!dpput(tdepot, kbufs[i], ksizs[i], vbufs[i], vsizs[i], DP_DKEEP)) err = TRUE; + } else { + err = TRUE; + } + free(kbufs[i]); + free(vbufs[i]); + if(err) break; + } + if(!dpsync(tdepot)) err = TRUE; + if(err){ + unlink(tdepot->name); + dpclose(tdepot); + depot->fatal = TRUE; + return FALSE; + } + if(munmap(depot->map, depot->msiz) == -1){ + dpclose(tdepot); + dpecodeset(DP_EMAP, __FILE__, __LINE__); + depot->fatal = TRUE; + return FALSE; + } + depot->map = MAP_FAILED; + if(ftruncate(depot->fd, 0) == -1){ + dpclose(tdepot); + unlink(tdepot->name); + dpecodeset(DP_ETRUNC, __FILE__, __LINE__); + depot->fatal = TRUE; + return FALSE; + } + if(dpfcopy(depot->fd, 0, tdepot->fd, 0) == -1){ + dpclose(tdepot); + unlink(tdepot->name); + depot->fatal = TRUE; + return FALSE; + } + depot->fsiz = tdepot->fsiz; + depot->bnum = tdepot->bnum; + depot->ioff = 0; + for(i = 0; i < depot->fbpsiz; i += 2){ + depot->fbpool[i] = -1; + depot->fbpool[i+1] = -1; + } + depot->msiz = tdepot->msiz; + depot->map = mmap(0, depot->msiz, PROT_READ | PROT_WRITE, MAP_SHARED, depot->fd, 0); + if(depot->map == MAP_FAILED){ + dpecodeset(DP_EMAP, __FILE__, __LINE__); + depot->fatal = TRUE; + return FALSE; + } + depot->buckets = (int *)(depot->map + DP_HEADSIZ); + if(!(name = dpname(tdepot))){ + dpclose(tdepot); + unlink(tdepot->name); + depot->fatal = TRUE; + return FALSE; + } + if(!dpclose(tdepot)){ + free(name); + unlink(tdepot->name); + depot->fatal = TRUE; + return FALSE; + } + if(unlink(name) == -1){ + free(name); + dpecodeset(DP_EUNLINK, __FILE__, __LINE__); + depot->fatal = TRUE; + return FALSE; + } + free(name); + return TRUE; +} + + +/* Get the name of a database. */ +char *dpname(DEPOT *depot){ + char *name; + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return NULL; + } + if(!(name = dpstrdup(depot->name))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + depot->fatal = TRUE; + return NULL; + } + return name; +} + + +/* Get the size of a database file. */ +int dpfsiz(DEPOT *depot){ + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + return depot->fsiz; +} + + +/* Get the number of the elements of the bucket array. */ +int dpbnum(DEPOT *depot){ + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + return depot->bnum; +} + + +/* Get the number of the used elements of the bucket array. */ +int dpbusenum(DEPOT *depot){ + int i, hits; + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + hits = 0; + for(i = 0; i < depot->bnum; i++){ + if(depot->buckets[i]) hits++; + } + return hits; +} + + +/* Get the number of the records stored in a database. */ +int dprnum(DEPOT *depot){ + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + return depot->rnum; +} + + +/* Check whether a database handle is a writer or not. */ +int dpwritable(DEPOT *depot){ + assert(depot); + return depot->wmode; +} + + +/* Check whether a database has a fatal error or not. */ +int dpfatalerror(DEPOT *depot){ + assert(depot); + return depot->fatal; +} + + +/* Get the inode number of a database file. */ +int dpinode(DEPOT *depot){ + assert(depot); + return depot->inode; +} + + +/* Get the last modified time of a database. */ +time_t dpmtime(DEPOT *depot){ + assert(depot); + return depot->mtime; +} + + +/* Get the file descriptor of a database file. */ +int dpfdesc(DEPOT *depot){ + assert(depot); + return depot->fd; +} + + +/* Remove a database file. */ +int dpremove(const char *name){ + struct stat sbuf; + DEPOT *depot; + assert(name); + if(lstat(name, &sbuf) == -1){ + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + return FALSE; + } + if((depot = dpopen(name, DP_OWRITER | DP_OTRUNC, -1)) != NULL) dpclose(depot); + if(unlink(name) == -1){ + dpecodeset(DP_EUNLINK, __FILE__, __LINE__); + return FALSE; + } + return TRUE; +} + + +/* Repair a broken database file. */ +int dprepair(const char *name){ + DEPOT *tdepot; + char dbhead[DP_HEADSIZ], *tname, *kbuf, *vbuf; + int fd, fsiz, flags, bnum, tbnum, err, head[DP_RHNUM], off, rsiz, ksiz, vsiz; + struct stat sbuf; + assert(name); + if(lstat(name, &sbuf) == -1){ + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + return FALSE; + } + fsiz = sbuf.st_size; + if((fd = open(name, O_RDWR, DP_FILEMODE)) == -1){ + dpecodeset(DP_EOPEN, __FILE__, __LINE__); + return FALSE; + } + if(!dpseekread(fd, 0, dbhead, DP_HEADSIZ)){ + close(fd); + return FALSE; + } + flags = *(int *)(dbhead + DP_FLAGSOFF); + bnum = *(int *)(dbhead + DP_BNUMOFF); + tbnum = *(int *)(dbhead + DP_RNUMOFF) * 2; + if(tbnum < DP_DEFBNUM) tbnum = DP_DEFBNUM; + if(!(tname = malloc(strlen(name) + strlen(DP_TMPFSUF) + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return FALSE; + } + sprintf(tname, "%s%s", name, DP_TMPFSUF); + if(!(tdepot = dpopen(tname, DP_OWRITER | DP_OCREAT | DP_OTRUNC, tbnum))){ + free(tname); + close(fd); + return FALSE; + } + err = FALSE; + off = DP_HEADSIZ + bnum * sizeof(int); + while(off < fsiz){ + if(!dpseekread(fd, off, head, DP_RHNUM * sizeof(int))) break; + if(head[DP_RHIFLAGS] & DP_RECFDEL){ + if((rsiz = dprecsize(head)) < 0) break; + off += rsiz; + continue; + } + ksiz = head[DP_RHIKSIZ]; + vsiz = head[DP_RHIVSIZ]; + if(ksiz >= 0 && vsiz >= 0){ + kbuf = malloc(ksiz + 1); + vbuf = malloc(vsiz + 1); + if(kbuf && vbuf){ + if(dpseekread(fd, off + DP_RHNUM * sizeof(int), kbuf, ksiz) && + dpseekread(fd, off + DP_RHNUM * sizeof(int) + ksiz, vbuf, vsiz)){ + if(!dpput(tdepot, kbuf, ksiz, vbuf, vsiz, DP_DKEEP)) err = TRUE; + } else { + err = TRUE; + } + } else { + if(!err) dpecodeset(DP_EALLOC, __FILE__, __LINE__); + err = TRUE; + } + free(vbuf); + free(kbuf); + } else { + if(!err) dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + err = TRUE; + } + if((rsiz = dprecsize(head)) < 0) break; + off += rsiz; + } + if(!dpsetflags(tdepot, flags)) err = TRUE; + if(!dpsync(tdepot)) err = TRUE; + if(ftruncate(fd, 0) == -1){ + if(!err) dpecodeset(DP_ETRUNC, __FILE__, __LINE__); + err = TRUE; + } + if(dpfcopy(fd, 0, tdepot->fd, 0) == -1) err = TRUE; + if(!dpclose(tdepot)) err = TRUE; + if(close(fd) == -1){ + if(!err) dpecodeset(DP_ECLOSE, __FILE__, __LINE__); + err = TRUE; + } + if(unlink(tname) == -1){ + if(!err) dpecodeset(DP_EUNLINK, __FILE__, __LINE__); + err = TRUE; + } + free(tname); + return err ? FALSE : TRUE; +} + + +/* Dump all records as endian independent data. */ +int dpexportdb(DEPOT *depot, const char *name){ + char *kbuf, *vbuf, *pbuf; + int fd, err, ksiz, vsiz, psiz; + assert(depot && name); + if(!(dpiterinit(depot))) return FALSE; + if((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, DP_FILEMODE)) == -1){ + dpecodeset(DP_EOPEN, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + while(!err && (kbuf = dpiternext(depot, &ksiz)) != NULL){ + if((vbuf = dpget(depot, kbuf, ksiz, 0, -1, &vsiz)) != NULL){ + if((pbuf = malloc(ksiz + vsiz + DP_NUMBUFSIZ * 2)) != NULL){ + psiz = 0; + psiz += sprintf(pbuf + psiz, "%X\n%X\n", ksiz, vsiz); + memcpy(pbuf + psiz, kbuf, ksiz); + psiz += ksiz; + pbuf[psiz++] = '\n'; + memcpy(pbuf + psiz, vbuf, vsiz); + psiz += vsiz; + pbuf[psiz++] = '\n'; + if(!dpwrite(fd, pbuf, psiz)){ + dpecodeset(DP_EWRITE, __FILE__, __LINE__); + err = TRUE; + } + free(pbuf); + } else { + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + err = TRUE; + } + free(vbuf); + } else { + err = TRUE; + } + free(kbuf); + } + if(close(fd) == -1){ + if(!err) dpecodeset(DP_ECLOSE, __FILE__, __LINE__); + return FALSE; + } + return !err && !dpfatalerror(depot); +} + + +/* Load all records from endian independent data. */ +int dpimportdb(DEPOT *depot, const char *name){ + char mbuf[DP_IOBUFSIZ], *rbuf; + int i, j, fd, err, fsiz, off, msiz, ksiz, vsiz, hlen; + struct stat sbuf; + assert(depot && name); + if(!depot->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(dprnum(depot) > 0){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + if((fd = open(name, O_RDONLY, DP_FILEMODE)) == -1){ + dpecodeset(DP_EOPEN, __FILE__, __LINE__); + return FALSE; + } + if(fstat(fd, &sbuf) == -1 || !S_ISREG(sbuf.st_mode)){ + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + close(fd); + return FALSE; + } + err = FALSE; + fsiz = sbuf.st_size; + off = 0; + while(!err && off < fsiz){ + msiz = fsiz - off; + if(msiz > DP_IOBUFSIZ) msiz = DP_IOBUFSIZ; + if(!dpseekread(fd, off, mbuf, msiz)){ + err = TRUE; + break; + } + hlen = 0; + ksiz = -1; + vsiz = -1; + for(i = 0; i < msiz; i++){ + if(mbuf[i] == '\n'){ + mbuf[i] = '\0'; + ksiz = strtol(mbuf, NULL, 16); + for(j = i + 1; j < msiz; j++){ + if(mbuf[j] == '\n'){ + mbuf[j] = '\0'; + vsiz = strtol(mbuf + i + 1, NULL, 16); + hlen = j + 1; + break; + } + } + break; + } + } + if(ksiz < 0 || vsiz < 0 || hlen < 4){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + err = TRUE; + break; + } + if(hlen + ksiz + vsiz + 2 < DP_IOBUFSIZ){ + if(!dpput(depot, mbuf + hlen, ksiz, mbuf + hlen + ksiz + 1, vsiz, DP_DKEEP)) err = TRUE; + } else { + if((rbuf = malloc(ksiz + vsiz + 2)) != NULL){ + if(dpseekread(fd, off + hlen, rbuf, ksiz + vsiz + 2)){ + if(!dpput(depot, rbuf, ksiz, rbuf + ksiz + 1, vsiz, DP_DKEEP)) err = TRUE; + } else { + err = TRUE; + } + free(rbuf); + } else { + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + err = TRUE; + } + } + off += hlen + ksiz + vsiz + 2; + } + if(close(fd) == -1){ + if(!err) dpecodeset(DP_ECLOSE, __FILE__, __LINE__); + return FALSE; + } + return !err && !dpfatalerror(depot); +} + + +/* Retrieve a record directly from a database file. */ +char *dpsnaffle(const char *name, const char* kbuf, int ksiz, int *sp){ + char hbuf[DP_HEADSIZ], *map, *vbuf, *tkbuf; + int fd, fsiz, bnum, msiz, *buckets, hash, thash, head[DP_RHNUM], err, off, vsiz, tksiz, kcmp; + struct stat sbuf; + assert(name && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if((fd = open(name, O_RDONLY, DP_FILEMODE)) == -1){ + dpecodeset(DP_EOPEN, __FILE__, __LINE__); + return NULL; + } + if(fstat(fd, &sbuf) == -1 || !S_ISREG(sbuf.st_mode)){ + close(fd); + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + return NULL; + } + fsiz = sbuf.st_size; + if(!dpseekread(fd, 0, hbuf, DP_HEADSIZ)){ + close(fd); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + if(dpbigendian() ? memcmp(hbuf, DP_MAGICNUMB, strlen(DP_MAGICNUMB)) != 0 : + memcmp(hbuf, DP_MAGICNUML, strlen(DP_MAGICNUML)) != 0){ + close(fd); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + bnum = *((int *)(hbuf + DP_BNUMOFF)); + if(bnum < 1 || fsiz < DP_HEADSIZ + bnum * sizeof(int)){ + close(fd); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + msiz = DP_HEADSIZ + bnum * sizeof(int); + map = mmap(0, msiz, PROT_READ, MAP_SHARED, fd, 0); + if(map == MAP_FAILED){ + close(fd); + dpecodeset(DP_EMAP, __FILE__, __LINE__); + return NULL; + } + buckets = (int *)(map + DP_HEADSIZ); + err = FALSE; + vbuf = NULL; + vsiz = 0; + DP_SECONDHASH(hash, kbuf, ksiz); + DP_FIRSTHASH(thash, kbuf, ksiz); + off = buckets[thash%bnum]; + while(off != 0){ + if(!dpseekread(fd, off, head, DP_RHNUM * sizeof(int))){ + err = TRUE; + break; + } + if(head[DP_RHIKSIZ] < 0 || head[DP_RHIVSIZ] < 0 || head[DP_RHIPSIZ] < 0 || + head[DP_RHILEFT] < 0 || head[DP_RHIRIGHT] < 0){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + err = TRUE; + break; + } + thash = head[DP_RHIHASH]; + if(hash > thash){ + off = head[DP_RHILEFT]; + } else if(hash < thash){ + off = head[DP_RHIRIGHT]; + } else { + tksiz = head[DP_RHIKSIZ]; + if(!(tkbuf = malloc(tksiz + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + err = TRUE; + break; + } + if(!dpseekread(fd, off + DP_RHNUM * sizeof(int), tkbuf, tksiz)){ + free(tkbuf); + err = TRUE; + break; + } + tkbuf[tksiz] = '\0'; + kcmp = dpkeycmp(kbuf, ksiz, tkbuf, tksiz); + free(tkbuf); + if(kcmp > 0){ + off = head[DP_RHILEFT]; + } else if(kcmp < 0){ + off = head[DP_RHIRIGHT]; + } else if(head[DP_RHIFLAGS] & DP_RECFDEL){ + break; + } else { + vsiz = head[DP_RHIVSIZ]; + if(!(vbuf = malloc(vsiz + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + err = TRUE; + break; + } + if(!dpseekread(fd, off + DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ], vbuf, vsiz)){ + free(vbuf); + vbuf = NULL; + err = TRUE; + break; + } + vbuf[vsiz] = '\0'; + break; + } + } + } + if(vbuf){ + if(sp) *sp = vsiz; + } else if(!err){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + } + munmap(map, msiz); + close(fd); + return vbuf; +} + + +/* Hash function used inside Depot. */ +int dpinnerhash(const char *kbuf, int ksiz){ + int res; + assert(kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + DP_FIRSTHASH(res, kbuf, ksiz); + return res; +} + + +/* Hash function which is independent from the hash functions used inside Depot. */ +int dpouterhash(const char *kbuf, int ksiz){ + int res; + assert(kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + DP_THIRDHASH(res, kbuf, ksiz); + return res; +} + + +/* Get a natural prime number not less than a number. */ +int dpprimenum(int num){ + assert(num > 0); + return dpgetprime(num); +} + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Name of the operating system. */ +const char *dpsysname = _QDBM_SYSNAME; + + +/* File descriptor for debugging output. */ +int dpdbgfd = -1; + + +/* Whether this build is reentrant. */ +const int dpisreentrant = _qdbm_ptsafe; + + +/* Set the last happened error code. */ +void dpecodeset(int ecode, const char *file, int line){ + char iobuf[DP_IOBUFSIZ]; + assert(ecode >= DP_ENOERR && file && line >= 0); + dpecode = ecode; + if(dpdbgfd >= 0){ + fflush(stdout); + fflush(stderr); + sprintf(iobuf, "* dpecodeset: %s:%d: [%d] %s\n", file, line, ecode, dperrmsg(ecode)); + dpwrite(dpdbgfd, iobuf, strlen(iobuf)); + } +} + + +/* Get the pointer of the variable of the last happened error code. */ +int *dpecodeptr(void){ + static int defdpecode = DP_ENOERR; + void *ptr; + if(_qdbm_ptsafe){ + if(!(ptr = _qdbm_settsd(&defdpecode, sizeof(int), &defdpecode))){ + defdpecode = DP_EMISC; + return &defdpecode; + } + return (int *)ptr; + } + return &defdpecode; +} + + +/* Synchronize updating contents on memory. */ +int dpmemsync(DEPOT *depot){ + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!depot->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + *((int *)(depot->map + DP_FSIZOFF)) = depot->fsiz; + *((int *)(depot->map + DP_RNUMOFF)) = depot->rnum; + if(msync(depot->map, depot->msiz, MS_SYNC) == -1){ + dpecodeset(DP_EMAP, __FILE__, __LINE__); + depot->fatal = TRUE; + return FALSE; + } + return TRUE; +} + + +/* Synchronize updating contents on memory, not physically. */ +int dpmemflush(DEPOT *depot){ + assert(depot); + if(depot->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!depot->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + *((int *)(depot->map + DP_FSIZOFF)) = depot->fsiz; + *((int *)(depot->map + DP_RNUMOFF)) = depot->rnum; + if(mflush(depot->map, depot->msiz, MS_SYNC) == -1){ + dpecodeset(DP_EMAP, __FILE__, __LINE__); + depot->fatal = TRUE; + return FALSE; + } + return TRUE; +} + + +/* Get flags of a database. */ +int dpgetflags(DEPOT *depot){ + int flags; + assert(depot); + memcpy(&flags, depot->map + DP_FLAGSOFF, sizeof(int)); + return flags; +} + + +/* Set flags of a database. */ +int dpsetflags(DEPOT *depot, int flags){ + assert(depot); + if(!depot->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + memcpy(depot->map + DP_FLAGSOFF, &flags, sizeof(int)); + return TRUE; +} + + + +/************************************************************************************************* + * private objects + *************************************************************************************************/ + + +/* Check whether the byte order of the platform is big endian or not. + The return value is true if bigendian, else, it is false. */ +static int dpbigendian(void){ + char buf[sizeof(int)]; + *(int *)buf = 1; + return !buf[0]; +} + + +/* Get a copied string. + `str' specifies an original string. + The return value is a copied string whose region is allocated by `malloc'. */ +static char *dpstrdup(const char *str){ + int len; + char *buf; + assert(str); + len = strlen(str); + if(!(buf = malloc(len + 1))) return NULL; + memcpy(buf, str, len + 1); + return buf; +} + + +/* Lock a file descriptor. + `fd' specifies a file descriptor. + `ex' specifies whether an exclusive lock or a shared lock is performed. + `nb' specifies whether to request with non-blocking. + The return value is true if successful, else, it is false. */ +static int dplock(int fd, int ex, int nb){ + struct flock lock; + assert(fd >= 0); + memset(&lock, 0, sizeof(struct flock)); + lock.l_type = ex ? F_WRLCK : F_RDLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 0; + lock.l_pid = 0; + while(fcntl(fd, nb ? F_SETLK : F_SETLKW, &lock) == -1){ + if(errno != EINTR){ + dpecodeset(DP_ELOCK, __FILE__, __LINE__); + return FALSE; + } + } + return TRUE; +} + + +/* Write into a file. + `fd' specifies a file descriptor. + `buf' specifies a buffer to write. + `size' specifies the size of the buffer. + The return value is the size of the written buffer, or, -1 on failure. */ +static int dpwrite(int fd, const void *buf, int size){ + const char *lbuf; + int rv, wb; + assert(fd >= 0 && buf && size >= 0); + lbuf = buf; + rv = 0; + do { + wb = write(fd, lbuf, size); + switch(wb){ + case -1: if(errno != EINTR) return -1; + case 0: break; + default: + lbuf += wb; + size -= wb; + rv += wb; + break; + } + } while(size > 0); + return rv; +} + + +/* Write into a file at an offset. + `fd' specifies a file descriptor. + `off' specifies an offset of the file. + `buf' specifies a buffer to write. + `size' specifies the size of the buffer. + The return value is true if successful, else, it is false. */ +static int dpseekwrite(int fd, int off, const void *buf, int size){ + assert(fd >= 0 && buf && size >= 0); + if(size < 1) return TRUE; + if(off < 0){ + if(lseek(fd, 0, SEEK_END) == -1){ + dpecodeset(DP_ESEEK, __FILE__, __LINE__); + return FALSE; + } + } else { + if(lseek(fd, off, SEEK_SET) != off){ + dpecodeset(DP_ESEEK, __FILE__, __LINE__); + return FALSE; + } + } + if(dpwrite(fd, buf, size) != size){ + dpecodeset(DP_EWRITE, __FILE__, __LINE__); + return FALSE; + } + return TRUE; +} + + +/* Write an integer into a file at an offset. + `fd' specifies a file descriptor. + `off' specifies an offset of the file. + `num' specifies an integer. + The return value is true if successful, else, it is false. */ +static int dpseekwritenum(int fd, int off, int num){ + assert(fd >= 0); + return dpseekwrite(fd, off, &num, sizeof(int)); +} + + +/* Read from a file and store the data into a buffer. + `fd' specifies a file descriptor. + `buffer' specifies a buffer to store into. + `size' specifies the size to read with. + The return value is the size read with, or, -1 on failure. */ +static int dpread(int fd, void *buf, int size){ + char *lbuf; + int i, bs; + assert(fd >= 0 && buf && size >= 0); + lbuf = buf; + for(i = 0; i < size && (bs = read(fd, lbuf + i, size - i)) != 0; i += bs){ + if(bs == -1 && errno != EINTR) return -1; + } + return i; +} + + +/* Read from a file at an offset and store the data into a buffer. + `fd' specifies a file descriptor. + `off' specifies an offset of the file. + `buffer' specifies a buffer to store into. + `size' specifies the size to read with. + The return value is true if successful, else, it is false. */ +static int dpseekread(int fd, int off, void *buf, int size){ + char *lbuf; + assert(fd >= 0 && off >= 0 && buf && size >= 0); + lbuf = (char *)buf; + if(lseek(fd, off, SEEK_SET) != off){ + dpecodeset(DP_ESEEK, __FILE__, __LINE__); + return FALSE; + } + if(dpread(fd, lbuf, size) != size){ + dpecodeset(DP_EREAD, __FILE__, __LINE__); + return FALSE; + } + return TRUE; +} + + +/* Copy data between files. + `destfd' specifies a file descriptor of a destination file. + `destoff' specifies an offset of the destination file. + `srcfd' specifies a file descriptor of a source file. + `srcoff' specifies an offset of the source file. + The return value is the size copied with, or, -1 on failure. */ +static int dpfcopy(int destfd, int destoff, int srcfd, int srcoff){ + char iobuf[DP_IOBUFSIZ]; + int sum, iosiz; + if(lseek(srcfd, srcoff, SEEK_SET) == -1 || lseek(destfd, destoff, SEEK_SET) == -1){ + dpecodeset(DP_ESEEK, __FILE__, __LINE__); + return -1; + } + sum = 0; + while((iosiz = dpread(srcfd, iobuf, DP_IOBUFSIZ)) > 0){ + if(dpwrite(destfd, iobuf, iosiz) == -1){ + dpecodeset(DP_EWRITE, __FILE__, __LINE__); + return -1; + } + sum += iosiz; + } + if(iosiz < 0){ + dpecodeset(DP_EREAD, __FILE__, __LINE__); + return -1; + } + return sum; +} + + +/* Get a natural prime number not less than a number. + `num' specified a natural number. + The return value is a prime number not less than the specified number. */ +static int dpgetprime(int num){ + int primes[] = { + 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 43, 47, 53, 59, 61, 71, 79, 83, + 89, 103, 109, 113, 127, 139, 157, 173, 191, 199, 223, 239, 251, 283, 317, 349, + 383, 409, 443, 479, 509, 571, 631, 701, 761, 829, 887, 953, 1021, 1151, 1279, + 1399, 1531, 1663, 1789, 1913, 2039, 2297, 2557, 2803, 3067, 3323, 3583, 3833, + 4093, 4603, 5119, 5623, 6143, 6653, 7159, 7673, 8191, 9209, 10223, 11261, + 12281, 13309, 14327, 15359, 16381, 18427, 20479, 22511, 24571, 26597, 28669, + 30713, 32749, 36857, 40949, 45053, 49139, 53239, 57331, 61417, 65521, 73727, + 81919, 90107, 98299, 106487, 114679, 122869, 131071, 147451, 163819, 180221, + 196597, 212987, 229373, 245759, 262139, 294911, 327673, 360439, 393209, 425977, + 458747, 491503, 524287, 589811, 655357, 720887, 786431, 851957, 917503, 982981, + 1048573, 1179641, 1310719, 1441771, 1572853, 1703903, 1835003, 1966079, + 2097143, 2359267, 2621431, 2883577, 3145721, 3407857, 3670013, 3932153, + 4194301, 4718579, 5242877, 5767129, 6291449, 6815741, 7340009, 7864301, + 8388593, 9437179, 10485751, 11534329, 12582893, 13631477, 14680063, 15728611, + 16777213, 18874367, 20971507, 23068667, 25165813, 27262931, 29360087, 31457269, + 33554393, 37748717, 41943023, 46137319, 50331599, 54525917, 58720253, 62914549, + 67108859, 75497467, 83886053, 92274671, 100663291, 109051903, 117440509, + 125829103, 134217689, 150994939, 167772107, 184549373, 201326557, 218103799, + 234881011, 251658227, 268435399, 301989881, 335544301, 369098707, 402653171, + 436207613, 469762043, 503316469, 536870909, 603979769, 671088637, 738197503, + 805306357, 872415211, 939524087, 1006632947, 1073741789, 1207959503, + 1342177237, 1476394991, 1610612711, 1744830457, 1879048183, 2013265907, -1 + }; + int i; + assert(num > 0); + for(i = 0; primes[i] > 0; i++){ + if(num <= primes[i]) return primes[i]; + } + return primes[i-1]; +} + + +/* Get the padding size of a record. + `vsiz' specifies the size of the value of a record. + The return value is the padding size of a record. */ +static int dppadsize(DEPOT *depot, int ksiz, int vsiz){ + int pad; + assert(depot && vsiz >= 0); + if(depot->align > 0){ + return depot->align - (depot->fsiz + DP_RHNUM * sizeof(int) + ksiz + vsiz) % depot->align; + } else if(depot->align < 0){ + pad = (int)(vsiz * (2.0 / (1 << -(depot->align)))); + if(vsiz + pad >= DP_FSBLKSIZ){ + if(vsiz <= DP_FSBLKSIZ) pad = 0; + if(depot->fsiz % DP_FSBLKSIZ == 0){ + return (pad / DP_FSBLKSIZ) * DP_FSBLKSIZ + DP_FSBLKSIZ - + (depot->fsiz + DP_RHNUM * sizeof(int) + ksiz + vsiz) % DP_FSBLKSIZ; + } else { + return (pad / (DP_FSBLKSIZ / 2)) * (DP_FSBLKSIZ / 2) + (DP_FSBLKSIZ / 2) - + (depot->fsiz + DP_RHNUM * sizeof(int) + ksiz + vsiz) % (DP_FSBLKSIZ / 2); + } + } else { + return pad >= DP_RHNUM * sizeof(int) ? pad : DP_RHNUM * sizeof(int); + } + } + return 0; +} + + +/* Get the size of a record in a database file. + `head' specifies the header of a record. + The return value is the size of a record in a database file. */ +static int dprecsize(int *head){ + assert(head); + return DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] + head[DP_RHIPSIZ]; +} + + +/* Read the header of a record. + `depot' specifies a database handle. + `off' specifies an offset of the database file. + `head' specifies a buffer for the header. + `ebuf' specifies the pointer to the entity buffer. + `eep' specifies the pointer to a variable to which whether ebuf was used is assigned. + The return value is true if successful, else, it is false. */ +static int dprechead(DEPOT *depot, int off, int *head, char *ebuf, int *eep){ + assert(depot && off >= 0 && head); + if(off > depot->fsiz){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return FALSE; + } + if(ebuf){ + *eep = FALSE; + if(off < depot->fsiz - DP_ENTBUFSIZ){ + *eep = TRUE; + if(!dpseekread(depot->fd, off, ebuf, DP_ENTBUFSIZ)) return FALSE; + memcpy(head, ebuf, DP_RHNUM * sizeof(int)); + if(head[DP_RHIKSIZ] < 0 || head[DP_RHIVSIZ] < 0 || head[DP_RHIPSIZ] < 0 || + head[DP_RHILEFT] < 0 || head[DP_RHIRIGHT] < 0){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return FALSE; + } + return TRUE; + } + } + if(!dpseekread(depot->fd, off, head, DP_RHNUM * sizeof(int))) return FALSE; + if(head[DP_RHIKSIZ] < 0 || head[DP_RHIVSIZ] < 0 || head[DP_RHIPSIZ] < 0 || + head[DP_RHILEFT] < 0 || head[DP_RHIRIGHT] < 0){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return FALSE; + } + return TRUE; +} + + +/* Read the entitiy of the key of a record. + `depot' specifies a database handle. + `off' specifies an offset of the database file. + `head' specifies the header of a record. + The return value is a key data whose region is allocated by `malloc', or NULL on failure. */ +static char *dpreckey(DEPOT *depot, int off, int *head){ + char *kbuf; + int ksiz; + assert(depot && off >= 0); + ksiz = head[DP_RHIKSIZ]; + if(!(kbuf = malloc(ksiz + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return NULL; + } + if(!dpseekread(depot->fd, off + DP_RHNUM * sizeof(int), kbuf, ksiz)){ + free(kbuf); + return NULL; + } + kbuf[ksiz] = '\0'; + return kbuf; +} + + +/* Read the entitiy of the value of a record. + `depot' specifies a database handle. + `off' specifies an offset of the database file. + `head' specifies the header of a record. + `start' specifies the offset address of the beginning of the region of the value to be read. + `max' specifies the max size to be read. If it is negative, the size to read is unlimited. + The return value is a value data whose region is allocated by `malloc', or NULL on failure. */ +static char *dprecval(DEPOT *depot, int off, int *head, int start, int max){ + char *vbuf; + int vsiz; + assert(depot && off >= 0 && start >= 0); + head[DP_RHIVSIZ] -= start; + if(max < 0){ + vsiz = head[DP_RHIVSIZ]; + } else { + vsiz = max < head[DP_RHIVSIZ] ? max : head[DP_RHIVSIZ]; + } + if(!(vbuf = malloc(vsiz + 1))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return NULL; + } + if(!dpseekread(depot->fd, off + DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + start, vbuf, vsiz)){ + free(vbuf); + return NULL; + } + vbuf[vsiz] = '\0'; + return vbuf; +} + + +/* Read the entitiy of the value of a record and write it into a given buffer. + `depot' specifies a database handle. + `off' specifies an offset of the database file. + `head' specifies the header of a record. + `start' specifies the offset address of the beginning of the region of the value to be read. + `max' specifies the max size to be read. It shuld be less than the size of the writing buffer. + If successful, the return value is the size of the written data, else, it is -1. */ +static int dprecvalwb(DEPOT *depot, int off, int *head, int start, int max, char *vbuf){ + int vsiz; + assert(depot && off >= 0 && start >= 0 && max >= 0 && vbuf); + head[DP_RHIVSIZ] -= start; + vsiz = max < head[DP_RHIVSIZ] ? max : head[DP_RHIVSIZ]; + if(!dpseekread(depot->fd, off + DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + start, vbuf, vsiz)) + return -1; + return vsiz; +} + + +/* Compare two keys. + `abuf' specifies the pointer to the region of the former. + `asiz' specifies the size of the region. + `bbuf' specifies the pointer to the region of the latter. + `bsiz' specifies the size of the region. + The return value is 0 if two equals, positive if the formar is big, else, negative. */ +static int dpkeycmp(const char *abuf, int asiz, const char *bbuf, int bsiz){ + assert(abuf && asiz >= 0 && bbuf && bsiz >= 0); + if(asiz > bsiz) return 1; + if(asiz < bsiz) return -1; + return memcmp(abuf, bbuf, asiz); +} + + +/* Search for a record. + `depot' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region. + `hash' specifies the second hash value of the key. + `bip' specifies the pointer to the region to assign the index of the corresponding record. + `offp' specifies the pointer to the region to assign the last visited node in the hash chain, + or, -1 if the hash chain is empty. + `entp' specifies the offset of the last used joint, or, -1 if the hash chain is empty. + `head' specifies the pointer to the region to store the header of the last visited record in. + `ebuf' specifies the pointer to the entity buffer. + `eep' specifies the pointer to a variable to which whether ebuf was used is assigned. + `delhit' specifies whether a deleted record corresponds or not. + The return value is 0 if successful, 1 if there is no corresponding record, -1 on error. */ +static int dprecsearch(DEPOT *depot, const char *kbuf, int ksiz, int hash, int *bip, int *offp, + int *entp, int *head, char *ebuf, int *eep, int delhit){ + int off, entoff, thash, kcmp; + char stkey[DP_STKBUFSIZ], *tkey; + assert(depot && kbuf && ksiz >= 0 && hash >= 0 && bip && offp && entp && head && ebuf && eep); + DP_FIRSTHASH(thash, kbuf, ksiz); + *bip = thash % depot->bnum; + off = depot->buckets[*bip]; + *offp = -1; + *entp = -1; + entoff = -1; + *eep = FALSE; + while(off != 0){ + if(!dprechead(depot, off, head, ebuf, eep)) return -1; + thash = head[DP_RHIHASH]; + if(hash > thash){ + entoff = off + DP_RHILEFT * sizeof(int); + off = head[DP_RHILEFT]; + } else if(hash < thash){ + entoff = off + DP_RHIRIGHT * sizeof(int); + off = head[DP_RHIRIGHT]; + } else { + if(*eep && DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] <= DP_ENTBUFSIZ){ + kcmp = dpkeycmp(kbuf, ksiz, ebuf + (DP_RHNUM * sizeof(int)), head[DP_RHIKSIZ]); + } else if(head[DP_RHIKSIZ] > DP_STKBUFSIZ){ + if(!(tkey = dpreckey(depot, off, head))) return -1; + kcmp = dpkeycmp(kbuf, ksiz, tkey, head[DP_RHIKSIZ]); + free(tkey); + } else { + if(!dpseekread(depot->fd, off + DP_RHNUM * sizeof(int), stkey, head[DP_RHIKSIZ])) + return -1; + kcmp = dpkeycmp(kbuf, ksiz, stkey, head[DP_RHIKSIZ]); + } + if(kcmp > 0){ + entoff = off + DP_RHILEFT * sizeof(int); + off = head[DP_RHILEFT]; + } else if(kcmp < 0){ + entoff = off + DP_RHIRIGHT * sizeof(int); + off = head[DP_RHIRIGHT]; + } else { + if(!delhit && (head[DP_RHIFLAGS] & DP_RECFDEL)){ + entoff = off + DP_RHILEFT * sizeof(int); + off = head[DP_RHILEFT]; + } else { + *offp = off; + *entp = entoff; + return 0; + } + } + } + } + *offp = off; + *entp = entoff; + return 1; +} + + +/* Overwrite a record. + `depot' specifies a database handle. + `off' specifies the offset of the database file. + `rsiz' specifies the size of the existing record. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region. + `hash' specifies the second hash value of the key. + `left' specifies the offset of the left child. + `right' specifies the offset of the right child. + The return value is true if successful, or, false on failure. */ +static int dprecrewrite(DEPOT *depot, int off, int rsiz, const char *kbuf, int ksiz, + const char *vbuf, int vsiz, int hash, int left, int right){ + char ebuf[DP_WRTBUFSIZ]; + int i, head[DP_RHNUM], asiz, hoff, koff, voff, mi, min, size; + assert(depot && off >= 1 && rsiz > 0 && kbuf && ksiz >= 0 && vbuf && vsiz >= 0); + head[DP_RHIFLAGS] = 0; + head[DP_RHIHASH] = hash; + head[DP_RHIKSIZ] = ksiz; + head[DP_RHIVSIZ] = vsiz; + head[DP_RHIPSIZ] = rsiz - sizeof(head) - ksiz - vsiz; + head[DP_RHILEFT] = left; + head[DP_RHIRIGHT] = right; + asiz = sizeof(head) + ksiz + vsiz; + if(depot->fbpsiz > DP_FBPOOLSIZ * 4 && head[DP_RHIPSIZ] > asiz){ + rsiz = (head[DP_RHIPSIZ] - asiz) / 2 + asiz; + head[DP_RHIPSIZ] -= rsiz; + } else { + rsiz = 0; + } + if(asiz <= DP_WRTBUFSIZ){ + memcpy(ebuf, head, sizeof(head)); + memcpy(ebuf + sizeof(head), kbuf, ksiz); + memcpy(ebuf + sizeof(head) + ksiz, vbuf, vsiz); + if(!dpseekwrite(depot->fd, off, ebuf, asiz)) return FALSE; + } else { + hoff = off; + koff = hoff + sizeof(head); + voff = koff + ksiz; + if(!dpseekwrite(depot->fd, hoff, head, sizeof(head)) || + !dpseekwrite(depot->fd, koff, kbuf, ksiz) || !dpseekwrite(depot->fd, voff, vbuf, vsiz)) + return FALSE; + } + if(rsiz > 0){ + off += sizeof(head) + ksiz + vsiz + head[DP_RHIPSIZ]; + head[DP_RHIFLAGS] = DP_RECFDEL | DP_RECFREUSE; + head[DP_RHIHASH] = hash; + head[DP_RHIKSIZ] = ksiz; + head[DP_RHIVSIZ] = vsiz; + head[DP_RHIPSIZ] = rsiz - sizeof(head) - ksiz - vsiz; + head[DP_RHILEFT] = 0; + head[DP_RHIRIGHT] = 0; + if(!dpseekwrite(depot->fd, off, head, sizeof(head))) return FALSE; + size = dprecsize(head); + mi = -1; + min = -1; + for(i = 0; i < depot->fbpsiz; i += 2){ + if(depot->fbpool[i] == -1){ + depot->fbpool[i] = off; + depot->fbpool[i+1] = size; + dpfbpoolcoal(depot); + mi = -1; + break; + } + if(mi == -1 || depot->fbpool[i+1] < min){ + mi = i; + min = depot->fbpool[i+1]; + } + } + if(mi >= 0 && size > min){ + depot->fbpool[mi] = off; + depot->fbpool[mi+1] = size; + dpfbpoolcoal(depot); + } + } + return TRUE; +} + + +/* Write a record at the end of a database file. + `depot' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region. + `hash' specifies the second hash value of the key. + `left' specifies the offset of the left child. + `right' specifies the offset of the right child. + The return value is the offset of the record, or, -1 on failure. */ +static int dprecappend(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, + int hash, int left, int right){ + char ebuf[DP_WRTBUFSIZ], *hbuf; + int head[DP_RHNUM], asiz, psiz, off; + assert(depot && kbuf && ksiz >= 0 && vbuf && vsiz >= 0); + psiz = dppadsize(depot, ksiz, vsiz); + head[DP_RHIFLAGS] = 0; + head[DP_RHIHASH] = hash; + head[DP_RHIKSIZ] = ksiz; + head[DP_RHIVSIZ] = vsiz; + head[DP_RHIPSIZ] = psiz; + head[DP_RHILEFT] = left; + head[DP_RHIRIGHT] = right; + asiz = sizeof(head) + ksiz + vsiz + psiz; + off = depot->fsiz; + if(asiz <= DP_WRTBUFSIZ){ + memcpy(ebuf, head, sizeof(head)); + memcpy(ebuf + sizeof(head), kbuf, ksiz); + memcpy(ebuf + sizeof(head) + ksiz, vbuf, vsiz); + memset(ebuf + sizeof(head) + ksiz + vsiz, 0, psiz); + if(!dpseekwrite(depot->fd, off, ebuf, asiz)) return -1; + } else { + if(!(hbuf = malloc(asiz))){ + dpecodeset(DP_EALLOC, __FILE__, __LINE__); + return -1; + } + memcpy(hbuf, head, sizeof(head)); + memcpy(hbuf + sizeof(head), kbuf, ksiz); + memcpy(hbuf + sizeof(head) + ksiz, vbuf, vsiz); + memset(hbuf + sizeof(head) + ksiz + vsiz, 0, psiz); + if(!dpseekwrite(depot->fd, off, hbuf, asiz)){ + free(hbuf); + return -1; + } + free(hbuf); + } + depot->fsiz += asiz; + return off; +} + + +/* Overwrite the value of a record. + `depot' specifies a database handle. + `off' specifies the offset of the database file. + `head' specifies the header of the record. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region. + `cat' specifies whether it is concatenate mode or not. + The return value is true if successful, or, false on failure. */ +static int dprecover(DEPOT *depot, int off, int *head, const char *vbuf, int vsiz, int cat){ + int i, hsiz, hoff, voff; + assert(depot && off >= 0 && head && vbuf && vsiz >= 0); + for(i = 0; i < depot->fbpsiz; i += 2){ + if(depot->fbpool[i] == off){ + depot->fbpool[i] = -1; + depot->fbpool[i+1] = -1; + break; + } + } + if(cat){ + head[DP_RHIFLAGS] = 0; + head[DP_RHIPSIZ] -= vsiz; + head[DP_RHIVSIZ] += vsiz; + hsiz = DP_RHNUM * sizeof(int); + hoff = off; + voff = hoff + DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ] + head[DP_RHIVSIZ] - vsiz; + } else { + head[DP_RHIFLAGS] = 0; + head[DP_RHIPSIZ] += head[DP_RHIVSIZ] - vsiz; + head[DP_RHIVSIZ] = vsiz; + hsiz = DP_RHNUM * sizeof(int); + hoff = off; + voff = hoff + DP_RHNUM * sizeof(int) + head[DP_RHIKSIZ]; + } + if(!dpseekwrite(depot->fd, hoff, head, hsiz) || + !dpseekwrite(depot->fd, voff, vbuf, vsiz)) return FALSE; + return TRUE; +} + + +/* Delete a record. + `depot' specifies a database handle. + `off' specifies the offset of the database file. + `head' specifies the header of the record. + `reusable' specifies whether the region is reusable or not. + The return value is true if successful, or, false on failure. */ +static int dprecdelete(DEPOT *depot, int off, int *head, int reusable){ + int i, mi, min, size; + assert(depot && off >= 0 && head); + if(reusable){ + size = dprecsize(head); + mi = -1; + min = -1; + for(i = 0; i < depot->fbpsiz; i += 2){ + if(depot->fbpool[i] == -1){ + depot->fbpool[i] = off; + depot->fbpool[i+1] = size; + dpfbpoolcoal(depot); + mi = -1; + break; + } + if(mi == -1 || depot->fbpool[i+1] < min){ + mi = i; + min = depot->fbpool[i+1]; + } + } + if(mi >= 0 && size > min){ + depot->fbpool[mi] = off; + depot->fbpool[mi+1] = size; + dpfbpoolcoal(depot); + } + } + return dpseekwritenum(depot->fd, off + DP_RHIFLAGS * sizeof(int), + DP_RECFDEL | (reusable ? DP_RECFREUSE : 0)); +} + + +/* Make contiguous records of the free block pool coalesce. + `depot' specifies a database handle. */ +static void dpfbpoolcoal(DEPOT *depot){ + int i; + assert(depot); + if(depot->fbpinc++ <= depot->fbpsiz / 4) return; + depot->fbpinc = 0; + qsort(depot->fbpool, depot->fbpsiz / 2, sizeof(int) * 2, dpfbpoolcmp); + for(i = 2; i < depot->fbpsiz; i += 2){ + if(depot->fbpool[i-2] > 0 && + depot->fbpool[i-2] + depot->fbpool[i-1] - depot->fbpool[i] == 0){ + depot->fbpool[i] = depot->fbpool[i-2]; + depot->fbpool[i+1] += depot->fbpool[i-1]; + depot->fbpool[i-2] = -1; + depot->fbpool[i-1] = -1; + } + } +} + + +/* Compare two records of the free block pool. + `a' specifies the pointer to one record. + `b' specifies the pointer to the other record. + The return value is 0 if two equals, positive if the formar is big, else, negative. */ +static int dpfbpoolcmp(const void *a, const void *b){ + assert(a && b); + return *(int *)a - *(int *)b; +} + + + +/* END OF FILE */ diff --git a/qdbm/depot.h b/qdbm/depot.h new file mode 100644 index 00000000..36c0814d --- /dev/null +++ b/qdbm/depot.h @@ -0,0 +1,492 @@ +/************************************************************************************************* + * The basic API of QDBM + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#ifndef _DEPOT_H /* duplication check */ +#define _DEPOT_H + +#if defined(__cplusplus) /* export for C++ */ +extern "C" { +#endif + + +#include +#include + + +#if defined(_MSC_VER) && !defined(QDBM_INTERNAL) && !defined(QDBM_STATIC) +#define MYEXTERN extern __declspec(dllimport) +#else +#define MYEXTERN extern +#endif + + + +/************************************************************************************************* + * API + *************************************************************************************************/ + + +typedef struct { /* type of structure for a database handle */ + char *name; /* name of the database file */ + int wmode; /* whether to be writable */ + int inode; /* inode of the database file */ + time_t mtime; /* last modified time of the database */ + int fd; /* file descriptor of the database file */ + int fsiz; /* size of the database file */ + char *map; /* pointer to the mapped memory */ + int msiz; /* size of the mapped memory */ + int *buckets; /* pointer to the bucket array */ + int bnum; /* number of the bucket array */ + int rnum; /* number of records */ + int fatal; /* whether a fatal error occured */ + int ioff; /* offset of the iterator */ + int *fbpool; /* free block pool */ + int fbpsiz; /* size of the free block pool */ + int fbpinc; /* incrementor of update of the free block pool */ + int align; /* basic size of alignment */ +} DEPOT; + +enum { /* enumeration for error codes */ + DP_ENOERR, /* no error */ + DP_EFATAL, /* with fatal error */ + DP_EMODE, /* invalid mode */ + DP_EBROKEN, /* broken database file */ + DP_EKEEP, /* existing record */ + DP_ENOITEM, /* no item found */ + DP_EALLOC, /* memory allocation error */ + DP_EMAP, /* memory mapping error */ + DP_EOPEN, /* open error */ + DP_ECLOSE, /* close error */ + DP_ETRUNC, /* trunc error */ + DP_ESYNC, /* sync error */ + DP_ESTAT, /* stat error */ + DP_ESEEK, /* seek error */ + DP_EREAD, /* read error */ + DP_EWRITE, /* write error */ + DP_ELOCK, /* lock error */ + DP_EUNLINK, /* unlink error */ + DP_EMKDIR, /* mkdir error */ + DP_ERMDIR, /* rmdir error */ + DP_EMISC /* miscellaneous error */ +}; + +enum { /* enumeration for open modes */ + DP_OREADER = 1 << 0, /* open as a reader */ + DP_OWRITER = 1 << 1, /* open as a writer */ + DP_OCREAT = 1 << 2, /* a writer creating */ + DP_OTRUNC = 1 << 3, /* a writer truncating */ + DP_ONOLCK = 1 << 4, /* open without locking */ + DP_OLCKNB = 1 << 5, /* lock without blocking */ + DP_OSPARSE = 1 << 6 /* create as a sparse file */ +}; + +enum { /* enumeration for write modes */ + DP_DOVER, /* overwrite an existing value */ + DP_DKEEP, /* keep an existing value */ + DP_DCAT /* concatenate values */ +}; + + +/* String containing the version information. */ +MYEXTERN const char *dpversion; + + +/* Last happened error code. */ +#define dpecode (*dpecodeptr()) + + +/* Get a message string corresponding to an error code. + `ecode' specifies an error code. + The return value is the message string of the error code. The region of the return value + is not writable. */ +const char *dperrmsg(int ecode); + + +/* Get a database handle. + `name' specifies the name of a database file. + `omode' specifies the connection mode: `DP_OWRITER' as a writer, `DP_OREADER' as a reader. + If the mode is `DP_OWRITER', the following may be added by bitwise or: `DP_OCREAT', which + means it creates a new database if not exist, `DP_OTRUNC', which means it creates a new + database regardless if one exists. Both of `DP_OREADER' and `DP_OWRITER' can be added to by + bitwise or: `DP_ONOLCK', which means it opens a database file without file locking, or + `DP_OLCKNB', which means locking is performed without blocking. `DP_OCREAT' can be added to + by bitwise or: `DP_OSPARSE', which means it creates a database file as a sparse file. + `bnum' specifies the number of elements of the bucket array. If it is not more than 0, + the default value is specified. The size of a bucket array is determined on creating, + and can not be changed except for by optimization of the database. Suggested size of a + bucket array is about from 0.5 to 4 times of the number of all records to store. + The return value is the database handle or `NULL' if it is not successful. + While connecting as a writer, an exclusive lock is invoked to the database file. + While connecting as a reader, a shared lock is invoked to the database file. The thread + blocks until the lock is achieved. If `DP_ONOLCK' is used, the application is responsible + for exclusion control. */ +DEPOT *dpopen(const char *name, int omode, int bnum); + + +/* Close a database handle. + `depot' specifies a database handle. + If successful, the return value is true, else, it is false. + Because the region of a closed handle is released, it becomes impossible to use the handle. + Updating a database is assured to be written when the handle is closed. If a writer opens + a database but does not close it appropriately, the database will be broken. */ +int dpclose(DEPOT *depot); + + +/* Store a record. + `depot' specifies a database handle connected as a writer. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region of the value. If it is negative, the size is + assigned with `strlen(vbuf)'. + `dmode' specifies behavior when the key overlaps, by the following values: `DP_DOVER', + which means the specified value overwrites the existing one, `DP_DKEEP', which means the + existing value is kept, `DP_DCAT', which means the specified value is concatenated at the + end of the existing value. + If successful, the return value is true, else, it is false. */ +int dpput(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode); + + +/* Delete a record. + `depot' specifies a database handle connected as a writer. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is true, else, it is false. False is returned when no + record corresponds to the specified key. */ +int dpout(DEPOT *depot, const char *kbuf, int ksiz); + + +/* Retrieve a record. + `depot' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `start' specifies the offset address of the beginning of the region of the value to be read. + `max' specifies the max size to be read. If it is negative, the size to read is unlimited. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to + the specified key or the size of the value of the corresponding record is less than `start'. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. */ +char *dpget(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, int *sp); + + +/* Retrieve a record and write the value into a buffer. + `depot' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `start' specifies the offset address of the beginning of the region of the value to be read. + `max' specifies the max size to be read. It shuld be equal to or less than the size of the + writing buffer. + `vbuf' specifies the pointer to a buffer into which the value of the corresponding record is + written. + If successful, the return value is the size of the written data, else, it is -1. -1 is + returned when no record corresponds to the specified key or the size of the value of the + corresponding record is less than `start'. + Note that no additional zero code is appended at the end of the region of the writing buffer. */ +int dpgetwb(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, char *vbuf); + + +/* Get the size of the value of a record. + `depot' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is the size of the value of the corresponding record, else, + it is -1. + Because this function does not read the entity of a record, it is faster than `dpget'. */ +int dpvsiz(DEPOT *depot, const char *kbuf, int ksiz); + + +/* Initialize the iterator of a database handle. + `depot' specifies a database handle. + If successful, the return value is true, else, it is false. + The iterator is used in order to access the key of every record stored in a database. */ +int dpiterinit(DEPOT *depot); + + +/* Get the next key of the iterator. + `depot' specifies a database handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the next key, else, it is + `NULL'. `NULL' is returned when no record is to be get out of the iterator. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if + it is no longer in use. It is possible to access every record by iteration of calling + this function. However, it is not assured if updating the database is occurred while the + iteration. Besides, the order of this traversal access method is arbitrary, so it is not + assured that the order of storing matches the one of the traversal access. */ +char *dpiternext(DEPOT *depot, int *sp); + + +/* Set alignment of a database handle. + `depot' specifies a database handle connected as a writer. + `align' specifies the size of alignment. + If successful, the return value is true, else, it is false. + If alignment is set to a database, the efficiency of overwriting values is improved. + The size of alignment is suggested to be average size of the values of the records to be + stored. If alignment is positive, padding whose size is multiple number of the alignment + is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding + is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not + saved in a database, you should specify alignment every opening a database. */ +int dpsetalign(DEPOT *depot, int align); + + +/* Set the size of the free block pool of a database handle. + `depot' specifies a database handle connected as a writer. + `size' specifies the size of the free block pool of a database. + If successful, the return value is true, else, it is false. + The default size of the free block pool is 16. If the size is greater, the space efficiency + of overwriting values is improved with the time efficiency sacrificed. */ +int dpsetfbpsiz(DEPOT *depot, int size); + + +/* Synchronize updating contents with the file and the device. + `depot' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. + This function is useful when another process uses the connected database file. */ +int dpsync(DEPOT *depot); + + +/* Optimize a database. + `depot' specifies a database handle connected as a writer. + `bnum' specifies the number of the elements of the bucket array. If it is not more than 0, + the default value is specified. + If successful, the return value is true, else, it is false. + In an alternating succession of deleting and storing with overwrite or concatenate, + dispensable regions accumulate. This function is useful to do away with them. */ +int dpoptimize(DEPOT *depot, int bnum); + + +/* Get the name of a database. + `depot' specifies a database handle. + If successful, the return value is the pointer to the region of the name of the database, + else, it is `NULL'. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *dpname(DEPOT *depot); + + +/* Get the size of a database file. + `depot' specifies a database handle. + If successful, the return value is the size of the database file, else, it is -1. */ +int dpfsiz(DEPOT *depot); + + +/* Get the number of the elements of the bucket array. + `depot' specifies a database handle. + If successful, the return value is the number of the elements of the bucket array, else, it + is -1. */ +int dpbnum(DEPOT *depot); + + +/* Get the number of the used elements of the bucket array. + `depot' specifies a database handle. + If successful, the return value is the number of the used elements of the bucket array, + else, it is -1. + This function is inefficient because it accesses all elements of the bucket array. */ +int dpbusenum(DEPOT *depot); + + +/* Get the number of the records stored in a database. + `depot' specifies a database handle. + If successful, the return value is the number of the records stored in the database, else, + it is -1. */ +int dprnum(DEPOT *depot); + + +/* Check whether a database handle is a writer or not. + `depot' specifies a database handle. + The return value is true if the handle is a writer, false if not. */ +int dpwritable(DEPOT *depot); + + +/* Check whether a database has a fatal error or not. + `depot' specifies a database handle. + The return value is true if the database has a fatal error, false if not. */ +int dpfatalerror(DEPOT *depot); + + +/* Get the inode number of a database file. + `depot' specifies a database handle. + The return value is the inode number of the database file. */ +int dpinode(DEPOT *depot); + + +/* Get the last modified time of a database. + `depot' specifies a database handle. + The return value is the last modified time of the database. */ +time_t dpmtime(DEPOT *depot); + + +/* Get the file descriptor of a database file. + `depot' specifies a database handle. + The return value is the file descriptor of the database file. + Handling the file descriptor of a database file directly is not suggested. */ +int dpfdesc(DEPOT *depot); + + +/* Remove a database file. + `name' specifies the name of a database file. + If successful, the return value is true, else, it is false. */ +int dpremove(const char *name); + + +/* Repair a broken database file. + `name' specifies the name of a database file. + If successful, the return value is true, else, it is false. + There is no guarantee that all records in a repaired database file correspond to the original + or expected state. */ +int dprepair(const char *name); + + +/* Dump all records as endian independent data. + `depot' specifies a database handle. + `name' specifies the name of an output file. + If successful, the return value is true, else, it is false. */ +int dpexportdb(DEPOT *depot, const char *name); + + +/* Load all records from endian independent data. + `depot' specifies a database handle connected as a writer. The database of the handle must + be empty. + `name' specifies the name of an input file. + If successful, the return value is true, else, it is false. */ +int dpimportdb(DEPOT *depot, const char *name); + + +/* Retrieve a record directly from a database file. + `name' specifies the name of a database file. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to + the specified key. + Because an additional zero code is appended at the end of the region of the return value, + the return value can be treated as a character string. Because the region of the return + value is allocated with the `malloc' call, it should be released with the `free' call if it + is no longer in use. Although this function can be used even while the database file is + locked by another process, it is not assured that recent updated is reflected. */ +char *dpsnaffle(const char *name, const char *kbuf, int ksiz, int *sp); + + +/* Hash function used inside Depot. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + The return value is the hash value of 31 bits length computed from the key. + This function is useful when an application calculates the state of the inside bucket array. */ +int dpinnerhash(const char *kbuf, int ksiz); + + +/* Hash function which is independent from the hash functions used inside Depot. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + The return value is the hash value of 31 bits length computed from the key. + This function is useful when an application uses its own hash algorithm outside Depot. */ +int dpouterhash(const char *kbuf, int ksiz); + + +/* Get a natural prime number not less than a number. + `num' specified a natural number. + The return value is a natural prime number not less than the specified number. + This function is useful when an application determines the size of a bucket array of its + own hash algorithm. */ +int dpprimenum(int num); + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +#define _QDBM_VERSION "1.8.77" +#define _QDBM_LIBVER 1413 + + +/* Name of the operating system. */ +MYEXTERN const char *dpsysname; + + +/* File descriptor for debugging output. */ +MYEXTERN int dpdbgfd; + + +/* Whether this build is reentrant. */ +MYEXTERN const int dpisreentrant; + + +/* Set the last happened error code. + `ecode' specifies the error code. + `line' specifies the number of the line where the error happened. */ +void dpecodeset(int ecode, const char *file, int line); + + +/* Get the pointer of the variable of the last happened error code. + The return value is the pointer of the variable. */ +int *dpecodeptr(void); + + +/* Synchronize updating contents on memory. + `depot' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. */ +int dpmemsync(DEPOT *depot); + + +/* Synchronize updating contents on memory, not physically. + `depot' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. */ +int dpmemflush(DEPOT *depot); + + +/* Get flags of a database. + `depot' specifies a database handle. + The return value is the flags of a database. */ +int dpgetflags(DEPOT *depot); + + +/* Set flags of a database. + `depot' specifies a database handle connected as a writer. + `flags' specifies flags to set. Least ten bits are reserved for internal use. + If successful, the return value is true, else, it is false. */ +int dpsetflags(DEPOT *depot, int flags); + + + +#undef MYEXTERN + +#if defined(__cplusplus) /* export for C++ */ +} +#endif + +#endif /* duplication check */ + + +/* END OF FILE */ diff --git a/qdbm/dpmgr.c b/qdbm/dpmgr.c new file mode 100644 index 00000000..f02c9e3c --- /dev/null +++ b/qdbm/dpmgr.c @@ -0,0 +1,916 @@ +/************************************************************************************************* + * Utility for debugging Depot and its applications + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define ALIGNSIZ 32 /* basic size of alignment */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +char *hextoobj(const char *str, int *sp); +char *dectoiobj(const char *str, int *sp); +int runcreate(int argc, char **argv); +int runput(int argc, char **argv); +int runout(int argc, char **argv); +int runget(int argc, char **argv); +int runlist(int argc, char **argv); +int runoptimize(int argc, char **argv); +int runinform(int argc, char **argv); +int runremove(int argc, char **argv); +int runrepair(int argc, char **argv); +int runexportdb(int argc, char **argv); +int runimportdb(int argc, char **argv); +int runsnaffle(int argc, char **argv); +void pdperror(const char *name); +void printobj(const char *obj, int size); +void printobjhex(const char *obj, int size); +int docreate(const char *name, int bnum, int sparse); +int doput(const char *name, const char *kbuf, int ksiz, const char *vbuf, int vsiz, + int dmode, int align); +int doout(const char *name, const char *kbuf, int ksiz); +int doget(const char *name, int opts, const char *kbuf, int ksiz, + int start, int max, int ox, int nb); +int dolist(const char *name, int opts, int kb, int vb, int ox); +int dooptimize(const char *name, int bnum, int align); +int doinform(const char *name, int opts); +int doremove(const char *name); +int dorepair(const char *name); +int doexportdb(const char *name, const char *file); +int doimportdb(const char *name, const char *file, int bnum); +int dosnaffle(const char *name, const char *kbuf, int ksiz, int ox, int nb); + + +/* main routine */ +int main(int argc, char **argv){ + char *env; + int rv; + cbstdiobin(); + progname = argv[0]; + if((env = getenv("QDBMDBGFD")) != NULL) dpdbgfd = atoi(env); + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "create")){ + rv = runcreate(argc, argv); + } else if(!strcmp(argv[1], "put")){ + rv = runput(argc, argv); + } else if(!strcmp(argv[1], "out")){ + rv = runout(argc, argv); + } else if(!strcmp(argv[1], "get")){ + rv = runget(argc, argv); + } else if(!strcmp(argv[1], "list")){ + rv = runlist(argc, argv); + } else if(!strcmp(argv[1], "optimize")){ + rv = runoptimize(argc, argv); + } else if(!strcmp(argv[1], "inform")){ + rv = runinform(argc, argv); + } else if(!strcmp(argv[1], "remove")){ + rv = runremove(argc, argv); + } else if(!strcmp(argv[1], "repair")){ + rv = runrepair(argc, argv); + } else if(!strcmp(argv[1], "exportdb")){ + rv = runexportdb(argc, argv); + } else if(!strcmp(argv[1], "importdb")){ + rv = runimportdb(argc, argv); + } else if(!strcmp(argv[1], "snaffle")){ + rv = runsnaffle(argc, argv); + } else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){ + printf("Powered by QDBM version %s on %s%s\n", + dpversion, dpsysname, dpisreentrant ? " (reentrant)" : ""); + printf("Copyright (c) 2000-2007 Mikio Hirabayashi\n"); + rv = 0; + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: administration utility for Depot\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s create [-s] [-bnum num] name\n", progname); + fprintf(stderr, " %s put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat] [-na] name key val\n", + progname); + fprintf(stderr, " %s out [-kx|-ki] name key\n", progname); + fprintf(stderr, " %s get [-nl] [-kx|-ki] [-start num] [-max num] [-ox] [-n] name key\n", + progname); + fprintf(stderr, " %s list [-nl] [-k|-v] [-ox] name\n", progname); + fprintf(stderr, " %s optimize [-bnum num] [-na] name\n", progname); + fprintf(stderr, " %s inform [-nl] name\n", progname); + fprintf(stderr, " %s remove name\n", progname); + fprintf(stderr, " %s repair name\n", progname); + fprintf(stderr, " %s exportdb name file\n", progname); + fprintf(stderr, " %s importdb [-bnum num] name file\n", progname); + fprintf(stderr, " %s snaffle [-kx|-ki] [-ox] [-n] name key\n", progname); + fprintf(stderr, " %s version\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* create a binary object from a hexadecimal string */ +char *hextoobj(const char *str, int *sp){ + char *buf, mbuf[3]; + int len, i, j; + len = strlen(str); + if(!(buf = malloc(len + 1))) return NULL; + j = 0; + for(i = 0; i < len; i += 2){ + while(strchr(" \n\r\t\f\v", str[i])){ + i++; + } + if((mbuf[0] = str[i]) == '\0') break; + if((mbuf[1] = str[i+1]) == '\0') break; + mbuf[2] = '\0'; + buf[j++] = (char)strtol(mbuf, NULL, 16); + } + buf[j] = '\0'; + *sp = j; + return buf; +} + + +/* create a integer object from a decimal string */ +char *dectoiobj(const char *str, int *sp){ + char *buf; + int num; + num = atoi(str); + if(!(buf = malloc(sizeof(int)))) return NULL; + *(int *)buf = num; + *sp = sizeof(int); + return buf; +} + + +/* parse arguments of create command */ +int runcreate(int argc, char **argv){ + char *name; + int i, sb, bnum, rv; + name = NULL; + sb = FALSE; + bnum = -1; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-s")){ + sb = TRUE; + } else if(!strcmp(argv[i], "-bnum")){ + if(++i >= argc) usage(); + bnum = atoi(argv[i]); + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = docreate(name, bnum, sb); + return rv; +} + + +/* parse arguments of put command */ +int runput(int argc, char **argv){ + char *name, *key, *val, *kbuf, *vbuf; + int i, kx, ki, vx, vi, vf, align, ksiz, vsiz, rv; + int dmode; + name = NULL; + kx = FALSE; + ki = FALSE; + vx = FALSE; + vi = FALSE; + vf = FALSE; + align = ALIGNSIZ; + key = NULL; + val = NULL; + dmode = DP_DOVER; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else if(!strcmp(argv[i], "-vx")){ + vx = TRUE; + } else if(!strcmp(argv[i], "-vi")){ + vi = TRUE; + } else if(!strcmp(argv[i], "-vf")){ + vf = TRUE; + } else if(!strcmp(argv[i], "-keep")){ + dmode = DP_DKEEP; + } else if(!strcmp(argv[i], "-cat")){ + dmode = DP_DCAT; + } else if(!strcmp(argv[i], "-na")){ + align = 0; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else if(!val){ + val = argv[i]; + } else { + usage(); + } + } + if(!name || !key || !val) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(vx){ + vbuf = hextoobj(val, &vsiz); + } else if(vi){ + vbuf = dectoiobj(val, &vsiz); + } else if(vf){ + vbuf = cbreadfile(val, &vsiz); + } else { + vbuf = cbmemdup(val, -1); + vsiz = -1; + } + if(kbuf && vbuf){ + rv = doput(name, kbuf, ksiz, vbuf, vsiz, dmode, align); + } else { + if(vf){ + fprintf(stderr, "%s: %s: cannot read\n", progname, val); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + } + rv = 1; + } + free(kbuf); + free(vbuf); + return rv; +} + + +/* parse arguments of out command */ +int runout(int argc, char **argv){ + char *name, *key, *kbuf; + int i, kx, ki, ksiz, rv; + name = NULL; + kx = FALSE; + ki = FALSE; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(kbuf){ + rv = doout(name, kbuf, ksiz); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* parse arguments of get command */ +int runget(int argc, char **argv){ + char *name, *key, *kbuf; + int i, opts, kx, ki, ox, nb, start, max, ksiz, rv; + name = NULL; + opts = 0; + kx = FALSE; + ki = FALSE; + ox = FALSE; + nb = FALSE; + start = 0; + max = -1; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-nl")){ + opts |= DP_ONOLCK; + } else if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else if(!strcmp(argv[i], "-n")){ + nb = TRUE; + } else if(!strcmp(argv[i], "-start")){ + if(++i >= argc) usage(); + start = atoi(argv[i]); + } else if(!strcmp(argv[i], "-max")){ + if(++i >= argc) usage(); + max = atoi(argv[i]); + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key || start < 0) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(kbuf){ + rv = doget(name, opts, kbuf, ksiz, start, max, ox, nb); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* parse arguments of list command */ +int runlist(int argc, char **argv){ + char *name; + int i, opts, kb, vb, ox, rv; + name = NULL; + opts = 0; + kb = FALSE; + vb = FALSE; + ox = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-nl")){ + opts |= DP_ONOLCK; + } else if(!strcmp(argv[i], "-k")){ + kb = TRUE; + } else if(!strcmp(argv[i], "-v")){ + vb = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dolist(name, opts, kb, vb, ox); + return rv; +} + + +/* parse arguments of optimize command */ +int runoptimize(int argc, char **argv){ + char *name; + int i, bnum, align, rv; + name = NULL; + bnum = -1; + align = ALIGNSIZ; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-bnum")){ + if(++i >= argc) usage(); + bnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-na")){ + align = 0; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dooptimize(name, bnum, align); + return rv; +} + + +/* parse arguments of inform command */ +int runinform(int argc, char **argv){ + char *name; + int i, opts, rv; + name = NULL; + opts = 0; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-nl")){ + opts |= DP_ONOLCK; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doinform(name, opts); + return rv; +} + + +/* parse arguments of remove command */ +int runremove(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doremove(name); + return rv; +} + + +/* parse arguments of repair command */ +int runrepair(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dorepair(name); + return rv; +} + + +/* parse arguments of exportdb command */ +int runexportdb(int argc, char **argv){ + char *name, *file; + int i, rv; + name = NULL; + file = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + if(!name || !file) usage(); + rv = doexportdb(name, file); + return rv; +} + + +/* parse arguments of importdb command */ +int runimportdb(int argc, char **argv){ + char *name, *file; + int i, bnum, rv; + name = NULL; + file = NULL; + bnum = -1; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-bnum")){ + if(++i >= argc) usage(); + bnum = atoi(argv[i]); + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + if(!name || !file) usage(); + rv = doimportdb(name, file, bnum); + return rv; +} + + +/* parse arguments of snaffle command */ +int runsnaffle(int argc, char **argv){ + char *name, *key, *kbuf; + int i, kx, ki, ox, nb, start, max, ksiz, rv; + name = NULL; + kx = FALSE; + ki = FALSE; + ox = FALSE; + nb = FALSE; + start = 0; + max = -1; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else if(!strcmp(argv[i], "-n")){ + nb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key || start < 0) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(kbuf){ + rv = dosnaffle(name, kbuf, ksiz, ox, nb); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* print an object */ +void printobj(const char *obj, int size){ + int i; + for(i = 0; i < size; i++){ + putchar(obj[i]); + } +} + + +/* print an object as a hexadecimal string */ +void printobjhex(const char *obj, int size){ + int i; + for(i = 0; i < size; i++){ + printf("%s%02X", i > 0 ? " " : "", ((const unsigned char *)obj)[i]); + } +} + + +/* perform create command */ +int docreate(const char *name, int bnum, int sparse){ + DEPOT *depot; + int omode; + omode = DP_OWRITER | DP_OCREAT | DP_OTRUNC | (sparse ? DP_OSPARSE : 0); + if(!(depot = dpopen(name, omode, bnum))){ + pdperror(name); + return 1; + } + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform put command */ +int doput(const char *name, const char *kbuf, int ksiz, const char *vbuf, int vsiz, + int dmode, int align){ + DEPOT *depot; + if(!(depot = dpopen(name, DP_OWRITER, -1))){ + pdperror(name); + return 1; + } + if(align > 0 && !dpsetalign(depot, align)){ + pdperror(name); + dpclose(depot); + return 1; + } + if(!dpput(depot, kbuf, ksiz, vbuf, vsiz, dmode)){ + pdperror(name); + dpclose(depot); + return 1; + } + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform out command */ +int doout(const char *name, const char *kbuf, int ksiz){ + DEPOT *depot; + if(!(depot = dpopen(name, DP_OWRITER, -1))){ + pdperror(name); + return 1; + } + if(!dpout(depot, kbuf, ksiz)){ + pdperror(name); + dpclose(depot); + return 1; + } + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform get command */ +int doget(const char *name, int opts, const char *kbuf, int ksiz, + int start, int max, int ox, int nb){ + DEPOT *depot; + char *vbuf; + int vsiz; + if(!(depot = dpopen(name, DP_OREADER | opts, -1))){ + pdperror(name); + return 1; + } + if(!(vbuf = dpget(depot, kbuf, ksiz, start, max, &vsiz))){ + pdperror(name); + dpclose(depot); + return 1; + } + if(ox){ + printobjhex(vbuf, vsiz); + } else { + printobj(vbuf, vsiz); + } + free(vbuf); + if(!nb) putchar('\n'); + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform list command */ +int dolist(const char *name, int opts, int kb, int vb, int ox){ + DEPOT *depot; + char *kbuf, *vbuf; + int ksiz, vsiz; + if(!(depot = dpopen(name, DP_OREADER | opts, -1))){ + pdperror(name); + return 1; + } + dpiterinit(depot); + while((kbuf = dpiternext(depot, &ksiz)) != NULL){ + if(!(vbuf = dpget(depot, kbuf, ksiz, 0, -1, &vsiz))){ + pdperror(name); + free(kbuf); + break; + } + if(ox){ + if(!vb) printobjhex(kbuf, ksiz); + if(!kb && !vb) putchar('\t'); + if(!kb) printobjhex(vbuf, vsiz); + } else { + if(!vb) printobj(kbuf, ksiz); + if(!kb && !vb) putchar('\t'); + if(!kb) printobj(vbuf, vsiz); + } + putchar('\n'); + free(vbuf); + free(kbuf); + } + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform optimize command */ +int dooptimize(const char *name, int bnum, int align){ + DEPOT *depot; + if(!(depot = dpopen(name, DP_OWRITER, -1))){ + pdperror(name); + return 1; + } + if(align > 0 && !dpsetalign(depot, align)){ + pdperror(name); + dpclose(depot); + return 1; + } + if(!dpoptimize(depot, bnum)){ + pdperror(name); + dpclose(depot); + return 1; + } + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform inform command */ +int doinform(const char *name, int opts){ + DEPOT *depot; + char *tmp; + if(!(depot = dpopen(name, DP_OREADER | opts, -1))){ + pdperror(name); + return 1; + } + tmp = dpname(depot); + printf("name: %s\n", tmp ? tmp : "(null)"); + free(tmp); + printf("file size: %d\n", dpfsiz(depot)); + printf("all buckets: %d\n", dpbnum(depot)); + printf("used buckets: %d\n", dpbusenum(depot)); + printf("records: %d\n", dprnum(depot)); + printf("inode number: %d\n", dpinode(depot)); + printf("modified time: %.0f\n", (double)dpmtime(depot)); + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform remove command */ +int doremove(const char *name){ + if(!dpremove(name)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform repair command */ +int dorepair(const char *name){ + if(!dprepair(name)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform exportdb command */ +int doexportdb(const char *name, const char *file){ + DEPOT *depot; + if(!(depot = dpopen(name, DP_OREADER, -1))){ + pdperror(name); + return 1; + } + if(!dpexportdb(depot, file)){ + pdperror(name); + dpclose(depot); + return 1; + } + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform importdb command */ +int doimportdb(const char *name, const char *file, int bnum){ + DEPOT *depot; + if(!(depot = dpopen(name, DP_OWRITER | DP_OCREAT | DP_OTRUNC, bnum))){ + pdperror(name); + return 1; + } + if(!dpimportdb(depot, file)){ + pdperror(name); + dpclose(depot); + return 1; + } + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform snaffle command */ +int dosnaffle(const char *name, const char *kbuf, int ksiz, int ox, int nb){ + char *vbuf; + int vsiz; + if(!(vbuf = dpsnaffle(name, kbuf, ksiz, &vsiz))){ + pdperror(name); + return 1; + } + if(ox){ + printobjhex(vbuf, vsiz); + } else { + printobj(vbuf, vsiz); + } + free(vbuf); + if(!nb) putchar('\n'); + return 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/dptest.c b/qdbm/dptest.c new file mode 100644 index 00000000..9d584961 --- /dev/null +++ b/qdbm/dptest.c @@ -0,0 +1,836 @@ +/************************************************************************************************* + * Test cases of Depot + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define RECBUFSIZ 32 /* buffer for records */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +int runwrite(int argc, char **argv); +int runread(int argc, char **argv); +int runrcat(int argc, char **argv); +int runcombo(int argc, char **argv); +int runwicked(int argc, char **argv); +int printfflush(const char *format, ...); +void pdperror(const char *name); +int myrand(void); +int dowrite(const char *name, int rnum, int bnum, int sparse); +int doread(const char *name, int wb); +int dorcat(const char *name, int rnum, int bnum, int pnum, int align, int fbpsiz, int cb); +int docombo(const char *name); +int dowicked(const char *name, int rnum, int cb); + + +/* main routine */ +int main(int argc, char **argv){ + char *env; + int rv; + cbstdiobin(); + if((env = getenv("QDBMDBGFD")) != NULL) dpdbgfd = atoi(env); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "write")){ + rv = runwrite(argc, argv); + } else if(!strcmp(argv[1], "read")){ + rv = runread(argc, argv); + } else if(!strcmp(argv[1], "rcat")){ + rv = runrcat(argc, argv); + } else if(!strcmp(argv[1], "combo")){ + rv = runcombo(argc, argv); + } else if(!strcmp(argv[1], "wicked")){ + rv = runwicked(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: test cases for Depot\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s write [-s] name rnum bnum\n", progname); + fprintf(stderr, " %s read [-wb] name\n", progname); + fprintf(stderr, " %s rcat [-c] name rnum bnum pnum align fbpsiz\n", progname); + fprintf(stderr, " %s combo name\n", progname); + fprintf(stderr, " %s wicked [-c] name rnum\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of write command */ +int runwrite(int argc, char **argv){ + char *name, *rstr, *bstr; + int i, rnum, bnum, sb, rv; + name = NULL; + rstr = NULL; + bstr = NULL; + rnum = 0; + bnum = 0; + sb = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-s")){ + sb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else if(!bstr){ + bstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr || !bstr) usage(); + rnum = atoi(rstr); + bnum = atoi(bstr); + if(rnum < 1 || bnum < 1) usage(); + rv = dowrite(name, rnum, bnum, sb); + return rv; +} + + +/* parse arguments of read command */ +int runread(int argc, char **argv){ + char *name; + int i, wb, rv; + name = NULL; + wb = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-wb")){ + wb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doread(name, wb); + return rv; +} + + +/* parse arguments of rcat command */ +int runrcat(int argc, char **argv){ + char *name, *rstr, *bstr, *pstr, *astr, *fstr; + int i, rnum, bnum, pnum, align, fbpsiz, cb, rv; + name = NULL; + rstr = NULL; + bstr = NULL; + pstr = NULL; + astr = NULL; + fstr = NULL; + rnum = 0; + bnum = 0; + pnum = 0; + align = 0; + fbpsiz = 0; + cb = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-c")){ + cb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else if(!bstr){ + bstr = argv[i]; + } else if(!pstr){ + pstr = argv[i]; + } else if(!astr){ + astr = argv[i]; + } else if(!fstr){ + fstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr || !bstr || !pstr || !astr || !fstr) usage(); + rnum = atoi(rstr); + bnum = atoi(bstr); + pnum = atoi(pstr); + align = atoi(astr); + fbpsiz= atoi(fstr); + if(rnum < 1 || bnum < 1 || pnum < 1 || fbpsiz < 0) usage(); + rv = dorcat(name, rnum, bnum, pnum, align, fbpsiz, cb); + return rv; +} + + +/* parse arguments of combo command */ +int runcombo(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = docombo(name); + return rv; +} + + +/* parse arguments of wicked command */ +int runwicked(int argc, char **argv){ + char *name, *rstr; + int i, rnum, cb, rv; + name = NULL; + rstr = NULL; + rnum = 0; + cb = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-c")){ + cb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = dowicked(name, rnum, cb); + return rv; +} + + +/* print formatted string and flush the buffer */ +int printfflush(const char *format, ...){ + va_list ap; + int rv; + va_start(ap, format); + rv = vprintf(format, ap); + if(fflush(stdout) == EOF) rv = -1; + va_end(ap); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* pseudo random number generator */ +int myrand(void){ + static int cnt = 0; + if(cnt == 0) srand(time(NULL)); + return (rand() * rand() + (rand() >> (sizeof(int) * 4)) + (cnt++)) & INT_MAX; +} + + +/* perform write command */ +int dowrite(const char *name, int rnum, int bnum, int sparse){ + DEPOT *depot; + int i, omode, err, len; + char buf[RECBUFSIZ]; + printfflush("\n name=%s rnum=%d bnum=%d s=%d\n\n", name, rnum, bnum, sparse); + /* open a database */ + omode = DP_OWRITER | DP_OCREAT | DP_OTRUNC | (sparse ? DP_OSPARSE : 0); + if(!(depot = dpopen(name, omode, bnum))){ + pdperror(name); + return 1; + } + err = FALSE; + /* loop for each record */ + for(i = 1; i <= rnum; i++){ + /* store a record */ + len = sprintf(buf, "%08d", i); + if(!dpput(depot, buf, len, buf, len, DP_DOVER)){ + pdperror(name); + err = TRUE; + break; + } + /* print progression */ + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform read command */ +int doread(const char *name, int wb){ + DEPOT *depot; + int i, rnum, err, len; + char buf[RECBUFSIZ], vbuf[RECBUFSIZ], *val; + printfflush("\n name=%s wb=%d\n\n", name, wb); + /* open a database */ + if(!(depot = dpopen(name, DP_OREADER, -1))){ + pdperror(name); + return 1; + } + /* get the number of records */ + rnum = dprnum(depot); + err = FALSE; + /* loop for each record */ + for(i = 1; i <= rnum; i++){ + /* retrieve a record */ + len = sprintf(buf, "%08d", i); + if(wb){ + if(dpgetwb(depot, buf, len, 0, RECBUFSIZ, vbuf) == -1){ + pdperror(name); + err = TRUE; + break; + } + } else { + if(!(val = dpget(depot, buf, len, 0, -1, NULL))){ + pdperror(name); + err = TRUE; + break; + } + free(val); + } + /* print progression */ + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform rcat command */ +int dorcat(const char *name, int rnum, int bnum, int pnum, int align, int fbpsiz, int cb){ + DEPOT *depot; + CBMAP *map; + int i, err, len, ksiz, vsiz, rsiz; + const char *kbuf, *vbuf; + char buf[RECBUFSIZ], *rbuf; + printfflush("\n name=%s rnum=%d bnum=%d pnum=%d align=%d" + " fbpsiz=%d c=%d\n\n", name, rnum, bnum, pnum, align, fbpsiz, cb); + if(!(depot = dpopen(name, DP_OWRITER | DP_OCREAT | DP_OTRUNC, bnum))){ + pdperror(name); + return 1; + } + if(!dpsetalign(depot, align) || !dpsetfbpsiz(depot, fbpsiz)){ + pdperror(name); + dpclose(depot); + return 1; + } + map = NULL; + if(cb) map = cbmapopen(); + err = FALSE; + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", myrand() % pnum + 1); + if(!dpput(depot, buf, len, buf, len, DP_DCAT)){ + pdperror(name); + err = TRUE; + break; + } + if(map) cbmapputcat(map, buf, len, buf, len); + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d: fsiz=%d rnum=%d)\n", i, dpfsiz(depot), dprnum(depot)); + } + } + } + if(map){ + printfflush("Matching records ... "); + cbmapiterinit(map); + while((kbuf = cbmapiternext(map, &ksiz)) != NULL){ + vbuf = cbmapget(map, kbuf, ksiz, &vsiz); + if(!(rbuf = dpget(depot, kbuf, ksiz, 0, -1, &rsiz))){ + pdperror(name); + err = TRUE; + break; + } + if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){ + fprintf(stderr, "%s: %s: unmatched record\n", progname, name); + free(rbuf); + err = TRUE; + break; + } + free(rbuf); + } + cbmapclose(map); + if(!err) printfflush("ok\n"); + } + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform combo command */ +int docombo(const char *name){ + DEPOT *depot; + char buf[RECBUFSIZ], wbuf[RECBUFSIZ], *vbuf; + int i, len, wlen, vsiz; + printfflush("\n name=%s\n\n", name); + printfflush("Creating a database with bnum 3 ... "); + if(!(depot = dpopen(name, DP_OWRITER | DP_OCREAT | DP_OTRUNC, 3))){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Setting alignment as 16 ... "); + if(!dpsetalign(depot, 16)){ + pdperror(name); + dpclose(depot); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 20 records ... "); + for(i = 1; i <= 20; i++){ + len = sprintf(buf, "%08d", i); + if(!dpput(depot, buf, len, buf, len, DP_DOVER)){ + pdperror(name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking records ... "); + for(i = 1; i <= 20; i++){ + len = sprintf(buf, "%08d", i); + if(!(vbuf = dpget(depot, buf, len, 0, -1, &vsiz))){ + pdperror(name); + dpclose(depot); + return 1; + } + free(vbuf); + if(vsiz != dpvsiz(depot, buf, len)){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Overwriting top 10 records without moving rooms ... "); + for(i = 1; i <= 10; i++){ + len = sprintf(buf, "%08d", i); + if(!dpput(depot, buf, len, buf, len, DP_DOVER)){ + pdperror(name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Overwriting top 5 records with moving rooms ... "); + for(i = 1; i <= 5; i++){ + len = sprintf(buf, "%08d", i); + wlen = sprintf(wbuf, "%024d", i); + if(!dpput(depot, buf, len, wbuf, wlen, DP_DOVER)){ + pdperror(name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Overwriting top 15 records in concatenation with moving rooms ... "); + for(i = 1; i <= 15; i++){ + len = sprintf(buf, "%08d", i); + wlen = sprintf(wbuf, "========================"); + if(!dpput(depot, buf, len, wbuf, wlen, DP_DCAT)){ + pdperror(name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking records ... "); + for(i = 1; i <= 20; i++){ + len = sprintf(buf, "%08d", i); + if(!(vbuf = dpget(depot, buf, len, 0, -1, &vsiz))){ + pdperror(name); + dpclose(depot); + return 1; + } + free(vbuf); + if(vsiz != dpvsiz(depot, buf, len)){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Deleting top 10 records ... "); + for(i = 1; i <= 10; i++){ + len = sprintf(buf, "%08d", i); + if(!dpout(depot, buf, len)){ + pdperror(name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking deleted records ... "); + for(i = 1; i <= 10; i++){ + len = sprintf(buf, "%08d", i); + vbuf = dpget(depot, buf, len, 0, -1, &vsiz); + free(vbuf); + if(vbuf || dpecode != DP_ENOITEM){ + fprintf(stderr, "%s: %s: deleting failed\n", progname, name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Overwriting top 15 records in concatenation with moving rooms ... "); + for(i = 1; i <= 15; i++){ + len = sprintf(buf, "%08d", i); + wlen = sprintf(wbuf, "========================"); + if(!dpput(depot, buf, len, wbuf, wlen, DP_DCAT)){ + pdperror(name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking records ... "); + for(i = 1; i <= 20; i++){ + len = sprintf(buf, "%08d", i); + if(!(vbuf = dpget(depot, buf, len, 0, -1, &vsiz))){ + pdperror(name); + dpclose(depot); + return 1; + } + free(vbuf); + if(vsiz != dpvsiz(depot, buf, len)){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Optimizing the database ... "); + if(!dpoptimize(depot, -1)){ + pdperror(name); + dpclose(depot); + return 1; + } + printfflush("ok\n"); + printfflush("Checking records ... "); + for(i = 1; i <= 20; i++){ + len = sprintf(buf, "%08d", i); + if(!(vbuf = dpget(depot, buf, len, 0, -1, &vsiz))){ + pdperror(name); + dpclose(depot); + return 1; + } + free(vbuf); + if(vsiz != dpvsiz(depot, buf, len)){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Closing the database ... "); + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Creating a database with bnum 1000000 ... "); + if(!(depot = dpopen(name, DP_OWRITER | DP_OCREAT | DP_OTRUNC, 1000000))){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 1000 records ... "); + for(i = 1; i <= 1000; i++){ + len = sprintf(buf, "%08d", i); + if(!dpput(depot, buf, len, buf, len, DP_DOVER)){ + pdperror(name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Adding 64 records ... "); + for(i = 1; i <= 1000; i++){ + len = sprintf(buf, "%o", i); + if(!dpput(depot, buf, len, buf, len, DP_DOVER)){ + pdperror(name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Syncing the database ... "); + if(!dpsync(depot)){ + pdperror(name); + dpclose(depot); + return 1; + } + printfflush("ok\n"); + printfflush("Retrieving records directly ... "); + for(i = 1; i <= 64; i++){ + len = sprintf(buf, "%o", i); + if(!(vbuf = dpsnaffle(name, buf, len, &vsiz))){ + pdperror(name); + dpclose(depot); + return 1; + } + if(strcmp(vbuf, buf)){ + fprintf(stderr, "%s: %s: invalid content\n", progname, name); + free(vbuf); + dpclose(depot); + return 1; + } + free(vbuf); + if(vsiz != dpvsiz(depot, buf, len)){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + dpclose(depot); + return 1; + } + } + printfflush("ok\n"); + printfflush("Optimizing the database ... "); + if(!dpoptimize(depot, -1)){ + pdperror(name); + dpclose(depot); + return 1; + } + printfflush("ok\n"); + printfflush("Closing the database ... "); + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("all ok\n\n"); + return 0; +} + + +/* perform wicked command */ +int dowicked(const char *name, int rnum, int cb){ + DEPOT *depot; + CBMAP *map; + int i, len, err, align, mksiz, mvsiz, rsiz; + const char *mkbuf, *mvbuf; + char buf[RECBUFSIZ], vbuf[RECBUFSIZ], *val; + printfflush("\n name=%s rnum=%d\n\n", name, rnum); + err = FALSE; + if(!(depot = dpopen(name, DP_OWRITER | DP_OCREAT | DP_OTRUNC, rnum / 10))){ + pdperror(name); + return 1; + } + if(!dpsetalign(depot, 16) || !dpsetfbpsiz(depot, 256)){ + pdperror(name); + err = TRUE; + } + map = NULL; + if(cb) map = cbmapopen(); + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", myrand() % rnum + 1); + switch(myrand() % 16){ + case 0: + putchar('O'); + if(!dpput(depot, buf, len, buf, len, DP_DOVER)) err = TRUE; + if(map) cbmapput(map, buf, len, buf, len, TRUE); + break; + case 1: + putchar('K'); + if(!dpput(depot, buf, len, buf, len, DP_DKEEP) && dpecode != DP_EKEEP) err = TRUE; + if(map) cbmapput(map, buf, len, buf, len, FALSE); + break; + case 2: + putchar('D'); + if(!dpout(depot, buf, len) && dpecode != DP_ENOITEM) err = TRUE; + if(map) cbmapout(map, buf, len); + break; + case 3: + putchar('G'); + if(dpgetwb(depot, buf, len, 2, RECBUFSIZ, vbuf) == -1 && dpecode != DP_ENOITEM) err = TRUE; + break; + case 4: + putchar('V'); + if(dpvsiz(depot, buf, len) == -1 && dpecode != DP_ENOITEM) err = TRUE; + break; + default: + putchar('C'); + if(!dpput(depot, buf, len, buf, len, DP_DCAT)) err = TRUE; + if(map) cbmapputcat(map, buf, len, buf, len); + break; + } + if(i % 50 == 0) printfflush(" (%08d)\n", i); + if(!err && rnum > 100 && myrand() % (rnum / 100) == 0){ + if(myrand() % 10 == 0){ + align = (myrand() % 4 + 1) * -1; + } else { + align = myrand() % 32; + } + if(!dpsetalign(depot, align)) err = TRUE; + } + if(err){ + pdperror(name); + break; + } + } + if(!dpoptimize(depot, -1)){ + pdperror(name); + err = TRUE; + } + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", i); + if(!dpput(depot, buf, len, ":", -1, DP_DCAT)){ + pdperror(name); + err = TRUE; + break; + } + if(map) cbmapputcat(map, buf, len, ":", -1); + putchar(':'); + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + if(!dpoptimize(depot, -1)){ + pdperror(name); + err = TRUE; + } + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", i); + if(!(val = dpget(depot, buf, len, 0, -1, NULL))){ + pdperror(name); + err = TRUE; + break; + } + free(val); + putchar('='); + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + if(!dpiterinit(depot)){ + pdperror(name); + err = TRUE; + } + for(i = 1; i <= rnum; i++){ + if(!(val = dpiternext(depot, NULL))){ + pdperror(name); + err = TRUE; + break; + } + free(val); + putchar('@'); + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + if(map){ + printfflush("Matching records ... "); + cbmapiterinit(map); + while((mkbuf = cbmapiternext(map, &mksiz)) != NULL){ + mvbuf = cbmapget(map, mkbuf, mksiz, &mvsiz); + if(!(val = dpget(depot, mkbuf, mksiz, 0, -1, &rsiz))){ + pdperror(name); + err = TRUE; + break; + } + if(rsiz != mvsiz || memcmp(val, mvbuf, rsiz)){ + fprintf(stderr, "%s: %s: unmatched record\n", progname, name); + free(val); + err = TRUE; + break; + } + free(val); + } + cbmapclose(map); + if(!err) printfflush("ok\n"); + } + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/dptsv.c b/qdbm/dptsv.c new file mode 100644 index 00000000..7dab42c5 --- /dev/null +++ b/qdbm/dptsv.c @@ -0,0 +1,261 @@ +/************************************************************************************************* + * Mutual converter between a database of Depot and a TSV text + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +int runimport(int argc, char **argv); +int runexport(int argc, char **argv); +void pdperror(const char *name); +char *getl(void); +int doimport(const char *name, int bnum, int bin); +int doexport(const char *name, int bin); + + +/* main routine */ +int main(int argc, char **argv){ + int rv; + cbstdiobin(); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "import")){ + rv = runimport(argc, argv); + } else if(!strcmp(argv[1], "export")){ + rv = runexport(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: mutual converter between TSV and Depot database\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s import [-bnum num] [-bin] name\n", progname); + fprintf(stderr, " %s export [-bin] name\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of import command */ +int runimport(int argc, char **argv){ + char *name; + int i, bnum, bin, rv; + name = NULL; + bnum = -1; + bin = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-bnum")){ + if(++i >= argc) usage(); + bnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-bin")){ + bin = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doimport(name, bnum, bin); + return rv; +} + + +/* parse arguments of export command */ +int runexport(int argc, char **argv){ + char *name; + int i, bin, rv; + name = NULL; + bin = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-bin")){ + bin = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doexport(name, bin); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* read a line */ +char *getl(void){ + char *buf; + int c, len, blen; + buf = NULL; + len = 0; + blen = 256; + while((c = getchar()) != EOF){ + if(blen <= len) blen *= 2; + buf = cbrealloc(buf, blen + 1); + if(c == '\n') c = '\0'; + buf[len++] = c; + if(c == '\0') break; + } + if(!buf) return NULL; + buf[len] = '\0'; + return buf; +} + + +/* perform import command */ +int doimport(const char *name, int bnum, int bin){ + DEPOT *depot; + char *buf, *kbuf, *vbuf, *ktmp, *vtmp; + int i, err, ktsiz, vtsiz; + /* open a database */ + if(!(depot = dpopen(name, DP_OWRITER | DP_OCREAT, bnum))){ + pdperror(name); + return 1; + } + /* loop for each line */ + err = FALSE; + for(i = 1; (buf = getl()) != NULL; i++){ + kbuf = buf; + if((vbuf = strchr(buf, '\t')) != NULL){ + *vbuf = '\0'; + vbuf++; + /* store a record */ + if(bin){ + ktmp = cbbasedecode(kbuf, &ktsiz); + vtmp = cbbasedecode(vbuf, &vtsiz); + if(!dpput(depot, ktmp, ktsiz, vtmp, vtsiz, DP_DOVER)){ + pdperror(name); + err = TRUE; + } + free(vtmp); + free(ktmp); + } else { + if(!dpput(depot, kbuf, -1, vbuf, -1, DP_DOVER)){ + pdperror(name); + err = TRUE; + } + } + } else { + fprintf(stderr, "%s: %s: invalid format in line %d\n", progname, name, i); + } + free(buf); + if(err) break; + } + /* close the database */ + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return err ? 1 : 0; +} + + +/* perform export command */ +int doexport(const char *name, int bin){ + DEPOT *depot; + char *kbuf, *vbuf, *tmp; + int err, ksiz, vsiz; + /* open a database */ + if(!(depot = dpopen(name, DP_OREADER, -1))){ + pdperror(name); + return 1; + } + /* initialize the iterator */ + dpiterinit(depot); + /* loop for each key */ + err = FALSE; + while((kbuf = dpiternext(depot, &ksiz)) != NULL){ + /* retrieve a value with a key */ + if(!(vbuf = dpget(depot, kbuf, ksiz, 0, -1, &vsiz))){ + pdperror(name); + free(kbuf); + err = TRUE; + break; + } + /* output data */ + if(bin){ + tmp = cbbaseencode(kbuf, ksiz); + printf("%s\t", tmp); + free(tmp); + tmp = cbbaseencode(vbuf, vsiz); + printf("%s\n", tmp); + free(tmp); + } else { + printf("%s\t%s\n", kbuf, vbuf); + } + /* free resources */ + free(vbuf); + free(kbuf); + } + /* check whether all records were retrieved */ + if(dpecode != DP_ENOITEM){ + pdperror(name); + err = TRUE; + } + /* close the database */ + if(!dpclose(depot)){ + pdperror(name); + return 1; + } + return err ? 1 : 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/hovel.c b/qdbm/hovel.c new file mode 100644 index 00000000..86964702 --- /dev/null +++ b/qdbm/hovel.c @@ -0,0 +1,568 @@ +/************************************************************************************************* + * Implementation of Hovel + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#define QDBM_INTERNAL 1 + +#include "hovel.h" +#include "myconf.h" + +#define HV_INITBNUM 32749 /* initial bucket number */ +#define HV_ALIGNSIZ 16 /* size of alignment */ + + +/* private function prototypes */ +static int gdbm_geterrno(int ecode); + + + +/************************************************************************************************* + * public objects + *************************************************************************************************/ + + +/* String containing the version information. */ +char *gdbm_version = "Powered by QDBM"; + + +/* Get a message string corresponding to an error code. */ +char *gdbm_strerror(gdbm_error gdbmerrno){ + switch(gdbmerrno){ + case GDBM_NO_ERROR: return "No error"; + case GDBM_MALLOC_ERROR: return "Malloc error"; + case GDBM_BLOCK_SIZE_ERROR: return "Block size error"; + case GDBM_FILE_OPEN_ERROR: return "File open error"; + case GDBM_FILE_WRITE_ERROR: return "File write error"; + case GDBM_FILE_SEEK_ERROR: return "File seek error"; + case GDBM_FILE_READ_ERROR: return "File read error"; + case GDBM_BAD_MAGIC_NUMBER: return "Bad magic number"; + case GDBM_EMPTY_DATABASE: return "Empty database"; + case GDBM_CANT_BE_READER: return "Can't be reader"; + case GDBM_CANT_BE_WRITER: return "Can't be writer"; + case GDBM_READER_CANT_DELETE: return "Reader can't delete"; + case GDBM_READER_CANT_STORE: return "Reader can't store"; + case GDBM_READER_CANT_REORGANIZE: return "Reader can't reorganize"; + case GDBM_UNKNOWN_UPDATE: return "Unknown update"; + case GDBM_ITEM_NOT_FOUND: return "Item not found"; + case GDBM_REORGANIZE_FAILED: return "Reorganize failed"; + case GDBM_CANNOT_REPLACE: return "Cannot replace"; + case GDBM_ILLEGAL_DATA: return "Illegal data"; + case GDBM_OPT_ALREADY_SET: return "Option already set"; + case GDBM_OPT_ILLEGAL: return "Illegal option"; + } + return "(invalid ecode)"; +} + + +/* Get a database handle after the fashion of GDBM. */ +GDBM_FILE gdbm_open(char *name, int block_size, int read_write, int mode, + void (*fatal_func)(void)){ + GDBM_FILE dbf; + int dpomode; + DEPOT *depot; + int flags, fd; + assert(name); + dpomode = DP_OREADER; + flags = O_RDONLY; + if(read_write & GDBM_READER){ + dpomode = GDBM_READER; + if(read_write & GDBM_NOLOCK) dpomode |= DP_ONOLCK; + if(read_write & GDBM_LOCKNB) dpomode |= DP_OLCKNB; + flags = O_RDONLY; + } else if(read_write & GDBM_WRITER){ + dpomode = DP_OWRITER; + if(read_write & GDBM_NOLOCK) dpomode |= DP_ONOLCK; + if(read_write & GDBM_LOCKNB) dpomode |= DP_OLCKNB; + flags = O_RDWR; + } else if(read_write & GDBM_WRCREAT){ + dpomode = DP_OWRITER | DP_OCREAT; + if(read_write & GDBM_NOLOCK) dpomode |= DP_ONOLCK; + if(read_write & GDBM_LOCKNB) dpomode |= DP_OLCKNB; + if(read_write & GDBM_SPARSE) dpomode |= DP_OSPARSE; + flags = O_RDWR | O_CREAT; + } else if(read_write & GDBM_NEWDB){ + dpomode = DP_OWRITER | DP_OCREAT | DP_OTRUNC; + if(read_write & GDBM_NOLOCK) dpomode |= DP_ONOLCK; + if(read_write & GDBM_LOCKNB) dpomode |= DP_OLCKNB; + if(read_write & GDBM_SPARSE) dpomode |= DP_OSPARSE; + flags = O_RDWR | O_CREAT | O_TRUNC; + } else { + gdbm_errno = GDBM_ILLEGAL_DATA; + return NULL; + } + mode |= 00600; + if((fd = open(name, flags, mode)) == -1 || close(fd) == -1){ + gdbm_errno = GDBM_FILE_OPEN_ERROR; + return NULL; + } + if(!(depot = dpopen(name, dpomode, HV_INITBNUM))){ + gdbm_errno = gdbm_geterrno(dpecode); + if(dpecode == DP_ESTAT) gdbm_errno = GDBM_FILE_OPEN_ERROR; + return NULL; + } + if(dpomode & DP_OWRITER){ + if(!dpsetalign(depot, HV_ALIGNSIZ)){ + gdbm_errno = gdbm_geterrno(dpecode); + dpclose(depot); + } + } + if((dpomode & DP_OWRITER) && (read_write & GDBM_SYNC)){ + if(!dpsync(depot)){ + gdbm_errno = gdbm_geterrno(dpecode); + dpclose(depot); + } + } + if(!(dbf = malloc(sizeof(GDBM)))){ + gdbm_errno = GDBM_MALLOC_ERROR; + dpclose(depot); + return NULL; + } + dbf->depot = depot; + dbf->curia = NULL; + dbf->syncmode = (dpomode & DP_OWRITER) && (read_write & GDBM_SYNC) ? TRUE : FALSE; + return dbf; +} + + +/* Get a database handle after the fashion of QDBM. */ +GDBM_FILE gdbm_open2(char *name, int read_write, int mode, int bnum, int dnum, int align){ + GDBM_FILE dbf; + int dpomode, cromode, flags, fd; + struct stat sbuf; + DEPOT *depot; + CURIA *curia; + assert(name); + dpomode = DP_OREADER; + cromode = CR_OREADER; + flags = O_RDONLY; + if(read_write & GDBM_READER){ + dpomode = DP_OREADER; + cromode = CR_OREADER; + if(read_write & GDBM_NOLOCK){ + dpomode |= DP_ONOLCK; + cromode |= CR_ONOLCK; + } + if(read_write & GDBM_LOCKNB){ + dpomode |= DP_OLCKNB; + cromode |= CR_OLCKNB; + } + flags = O_RDONLY; + } else if(read_write & GDBM_WRITER){ + dpomode = DP_OWRITER; + cromode = CR_OWRITER; + if(read_write & GDBM_NOLOCK){ + dpomode |= DP_ONOLCK; + cromode |= CR_ONOLCK; + } + if(read_write & GDBM_LOCKNB){ + dpomode |= DP_OLCKNB; + cromode |= CR_OLCKNB; + } + flags = O_RDWR; + } else if(read_write & GDBM_WRCREAT){ + dpomode = DP_OWRITER | DP_OCREAT; + cromode = CR_OWRITER | CR_OCREAT; + if(read_write & GDBM_NOLOCK){ + dpomode |= DP_ONOLCK; + cromode |= CR_ONOLCK; + } + if(read_write & GDBM_LOCKNB){ + dpomode |= DP_OLCKNB; + cromode |= CR_OLCKNB; + } + if(read_write & GDBM_SPARSE){ + dpomode |= DP_OSPARSE; + cromode |= CR_OSPARSE; + } + flags = O_RDWR | O_CREAT; + } else if(read_write & GDBM_NEWDB){ + dpomode = DP_OWRITER | DP_OCREAT | DP_OTRUNC; + cromode = CR_OWRITER | CR_OCREAT | CR_OTRUNC; + if(read_write & GDBM_NOLOCK){ + dpomode |= DP_ONOLCK; + cromode |= CR_ONOLCK; + } + if(read_write & GDBM_LOCKNB){ + dpomode |= DP_OLCKNB; + cromode |= CR_OLCKNB; + } + if(read_write & GDBM_SPARSE){ + dpomode |= DP_OSPARSE; + cromode |= CR_OSPARSE; + } + flags = O_RDWR | O_CREAT | O_TRUNC; + } else { + gdbm_errno = GDBM_ILLEGAL_DATA; + return NULL; + } + if(lstat(name, &sbuf) != -1){ + if(S_ISDIR(sbuf.st_mode)){ + if(dnum < 1) dnum = 1; + } else { + dnum = 0; + } + } + depot = NULL; + curia = NULL; + if(dnum > 0){ + mode |= 00700; + if((cromode & CR_OCREAT)){ + if(mkdir(name, mode) == -1 && errno != EEXIST){ + gdbm_errno = GDBM_FILE_OPEN_ERROR; + return NULL; + } + } + if(!(curia = cropen(name, cromode, bnum, dnum))){ + gdbm_errno = gdbm_geterrno(dpecode); + return NULL; + } + if(cromode & CR_OWRITER) crsetalign(curia, align); + if((cromode & CR_OWRITER) && (read_write & GDBM_SYNC)) crsync(curia); + } else { + mode |= 00600; + if(dpomode & DP_OWRITER){ + if((fd = open(name, flags, mode)) == -1 || close(fd) == -1){ + gdbm_errno = GDBM_FILE_OPEN_ERROR; + return NULL; + } + } + if(!(depot = dpopen(name, dpomode, bnum))){ + gdbm_errno = gdbm_geterrno(dpecode); + return NULL; + } + if(dpomode & DP_OWRITER) dpsetalign(depot, align); + if((dpomode & DP_OWRITER) && (read_write & GDBM_SYNC)) dpsync(depot); + } + if(!(dbf = malloc(sizeof(GDBM)))){ + gdbm_errno = GDBM_MALLOC_ERROR; + if(depot) dpclose(depot); + if(curia) crclose(curia); + return NULL; + } + dbf->depot = depot; + dbf->curia = curia; + dbf->syncmode = (dpomode & DP_OWRITER) && (read_write & GDBM_SYNC) ? TRUE : FALSE; + return dbf; +} + + +/* Close a database handle. */ +void gdbm_close(GDBM_FILE dbf){ + assert(dbf); + if(dbf->depot){ + if(dbf->syncmode) dpsync(dbf->depot); + dpclose(dbf->depot); + } else { + if(dbf->syncmode) crsync(dbf->curia); + crclose(dbf->curia); + } + free(dbf); +} + + +/* Store a record. */ +int gdbm_store(GDBM_FILE dbf, datum key, datum content, int flag){ + int dmode; + assert(dbf); + if(!key.dptr || key.dsize < 0 || !content.dptr || content.dsize < 0){ + gdbm_errno = GDBM_ILLEGAL_DATA; + return -1; + } + if(dbf->depot){ + if(!dpwritable(dbf->depot)){ + gdbm_errno = GDBM_READER_CANT_STORE; + return -1; + } + dmode = (flag == GDBM_INSERT) ? DP_DKEEP : DP_DOVER; + if(!dpput(dbf->depot, key.dptr, key.dsize, content.dptr, content.dsize, dmode)){ + gdbm_errno = gdbm_geterrno(dpecode); + if(dpecode == DP_EKEEP) return 1; + return -1; + } + if(dbf->syncmode && !dpsync(dbf->depot)){ + gdbm_errno = gdbm_geterrno(dpecode); + return -1; + } + } else { + if(!crwritable(dbf->curia)){ + gdbm_errno = GDBM_READER_CANT_STORE; + return -1; + } + dmode = (flag == GDBM_INSERT) ? CR_DKEEP : CR_DOVER; + if(!crput(dbf->curia, key.dptr, key.dsize, content.dptr, content.dsize, dmode)){ + gdbm_errno = gdbm_geterrno(dpecode); + if(dpecode == DP_EKEEP) return 1; + return -1; + } + if(dbf->syncmode && !crsync(dbf->curia)){ + gdbm_errno = gdbm_geterrno(dpecode); + return -1; + } + } + return 0; +} + + +/* Delete a record. */ +int gdbm_delete(GDBM_FILE dbf, datum key){ + assert(dbf); + if(!key.dptr || key.dsize < 0){ + gdbm_errno = GDBM_ILLEGAL_DATA; + return -1; + } + if(dbf->depot){ + if(!dpwritable(dbf->depot)){ + gdbm_errno = GDBM_READER_CANT_DELETE; + return -1; + } + if(!dpout(dbf->depot, key.dptr, key.dsize)){ + gdbm_errno = gdbm_geterrno(dpecode); + return -1; + } + if(dbf->syncmode && !dpsync(dbf->depot)){ + gdbm_errno = gdbm_geterrno(dpecode); + return -1; + } + } else { + if(!crwritable(dbf->curia)){ + gdbm_errno = GDBM_READER_CANT_DELETE; + return -1; + } + if(!crout(dbf->curia, key.dptr, key.dsize)){ + gdbm_errno = gdbm_geterrno(dpecode); + return -1; + } + if(dbf->syncmode && !crsync(dbf->curia)){ + gdbm_errno = gdbm_geterrno(dpecode); + return -1; + } + } + return 0; +} + + +/* Retrieve a record. */ +datum gdbm_fetch(GDBM_FILE dbf, datum key){ + datum content; + char *vbuf; + int vsiz; + assert(dbf); + if(!key.dptr || key.dsize < 0){ + gdbm_errno = GDBM_ILLEGAL_DATA; + content.dptr = NULL; + content.dsize = 0; + return content; + } + if(dbf->depot){ + if(!(vbuf = dpget(dbf->depot, key.dptr, key.dsize, 0, -1, &vsiz))){ + gdbm_errno = gdbm_geterrno(dpecode); + content.dptr = NULL; + content.dsize = 0; + return content; + } + } else { + if(!(vbuf = crget(dbf->curia, key.dptr, key.dsize, 0, -1, &vsiz))){ + gdbm_errno = gdbm_geterrno(dpecode); + content.dptr = NULL; + content.dsize = 0; + return content; + } + } + content.dptr = vbuf; + content.dsize = vsiz; + return content; +} + + +/* Check whether a record exists or not. */ +int gdbm_exists(GDBM_FILE dbf, datum key){ + assert(dbf); + if(!key.dptr || key.dsize < 0){ + gdbm_errno = GDBM_ILLEGAL_DATA; + return FALSE; + } + if(dbf->depot){ + if(dpvsiz(dbf->depot, key.dptr, key.dsize) == -1){ + gdbm_errno = gdbm_geterrno(dpecode); + return FALSE; + } + } else { + if(crvsiz(dbf->curia, key.dptr, key.dsize) == -1){ + gdbm_errno = gdbm_geterrno(dpecode); + return FALSE; + } + } + return TRUE; +} + + +/* Get the first key of a database. */ +datum gdbm_firstkey(GDBM_FILE dbf){ + datum key; + assert(dbf); + memset(&key, 0, sizeof(datum)); + if(dbf->depot){ + if(dprnum(dbf->depot) < 1){ + gdbm_errno = GDBM_EMPTY_DATABASE; + key.dptr = NULL; + key.dsize = 0; + return key; + } + dpiterinit(dbf->depot); + return gdbm_nextkey(dbf, key); + } else { + if(crrnum(dbf->curia) < 1){ + gdbm_errno = GDBM_EMPTY_DATABASE; + key.dptr = NULL; + key.dsize = 0; + return key; + } + criterinit(dbf->curia); + return gdbm_nextkey(dbf, key); + } +} + + +/* Get the next key of a database. */ +datum gdbm_nextkey(GDBM_FILE dbf, datum key){ + char *kbuf; + int ksiz; + assert(dbf); + if(dbf->depot){ + if(!(kbuf = dpiternext(dbf->depot, &ksiz))){ + gdbm_errno = gdbm_geterrno(dpecode); + key.dptr = NULL; + key.dsize = 0; + return key; + } + } else { + if(!(kbuf = criternext(dbf->curia, &ksiz))){ + gdbm_errno = gdbm_geterrno(dpecode); + key.dptr = NULL; + key.dsize = 0; + return key; + } + } + key.dptr = kbuf; + key.dsize = ksiz; + return key; +} + + +/* Synchronize contents of updating with the file and the device. */ +void gdbm_sync(GDBM_FILE dbf){ + assert(dbf); + if(dbf->depot){ + if(!dpsync(dbf->depot)) gdbm_errno = gdbm_geterrno(dpecode); + } else { + if(!crsync(dbf->curia)) gdbm_errno = gdbm_geterrno(dpecode); + } +} + + +/* Reorganize a database. */ +int gdbm_reorganize(GDBM_FILE dbf){ + assert(dbf); + if(dbf->depot){ + if(!dpwritable(dbf->depot)){ + gdbm_errno = GDBM_READER_CANT_REORGANIZE; + return -1; + } + if(!dpoptimize(dbf->depot, dprnum(dbf->depot) >= HV_INITBNUM ? -1 : HV_INITBNUM)){ + gdbm_errno = gdbm_geterrno(dpecode); + return -1; + } + } else { + if(!crwritable(dbf->curia)){ + gdbm_errno = GDBM_READER_CANT_REORGANIZE; + return -1; + } + if(!croptimize(dbf->curia, crrnum(dbf->curia) >= HV_INITBNUM ? -1 : HV_INITBNUM)){ + gdbm_errno = gdbm_geterrno(dpecode); + return -1; + } + } + return 0; +} + + +/* Get the file descriptor of a database file. */ +int gdbm_fdesc(GDBM_FILE dbf){ + assert(dbf); + if(dbf->depot){ + return dpfdesc(dbf->depot); + } else { + return -1; + } +} + + +/* No effect. */ +int gdbm_setopt(GDBM_FILE dbf, int option, int *value, int size){ + assert(dbf); + return 0; +} + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Get the pointer of the last happened error code. */ +int *gdbm_errnoptr(void){ + static int deferrno = GDBM_NO_ERROR; + void *ptr; + if(_qdbm_ptsafe){ + if(!(ptr = _qdbm_settsd(&deferrno, sizeof(int), &deferrno))){ + deferrno = GDBM_ILLEGAL_DATA; + return &deferrno; + } + return (int *)ptr; + } + return &deferrno; +} + + + +/************************************************************************************************* + * private objects + *************************************************************************************************/ + + +/* Get the error code of GDBM corresponding to an error code of Depot. + `ecode' specifies an error code of Depot. + The return value is the error code of GDBM. */ +static int gdbm_geterrno(int ecode){ + switch(ecode){ + case DP_ENOERR: return GDBM_NO_ERROR; + case DP_EBROKEN: return GDBM_BAD_MAGIC_NUMBER; + case DP_EKEEP: return GDBM_CANNOT_REPLACE; + case DP_ENOITEM: return GDBM_ITEM_NOT_FOUND; + case DP_EALLOC: return GDBM_MALLOC_ERROR; + case DP_EOPEN: return GDBM_FILE_OPEN_ERROR; + case DP_ESEEK: return GDBM_FILE_SEEK_ERROR; + case DP_EREAD: return GDBM_FILE_READ_ERROR; + case DP_EWRITE: return GDBM_FILE_WRITE_ERROR; + case DP_EMKDIR: return GDBM_FILE_OPEN_ERROR; + default: break; + } + return GDBM_ILLEGAL_DATA; +} + + + +/* END OF FILE */ diff --git a/qdbm/hovel.h b/qdbm/hovel.h new file mode 100644 index 00000000..f95a3176 --- /dev/null +++ b/qdbm/hovel.h @@ -0,0 +1,278 @@ +/************************************************************************************************* + * The GDBM-compatible API of QDBM + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#ifndef _HOVEL_H /* duplication check */ +#define _HOVEL_H + +#if defined(__cplusplus) /* export for C++ */ +extern "C" { +#endif + + +#include +#include +#include +#include +#include + + +#if defined(_MSC_VER) && !defined(QDBM_INTERNAL) && !defined(QDBM_STATIC) +#define MYEXTERN extern __declspec(dllimport) +#else +#define MYEXTERN extern +#endif + + + +/************************************************************************************************* + * API + *************************************************************************************************/ + + +enum { /* enumeration for error codes */ + GDBM_NO_ERROR, /* no error */ + GDBM_MALLOC_ERROR, /* malloc error */ + GDBM_BLOCK_SIZE_ERROR, /* block size error */ + GDBM_FILE_OPEN_ERROR, /* file open error */ + GDBM_FILE_WRITE_ERROR, /* file write error */ + GDBM_FILE_SEEK_ERROR, /* file seek error */ + GDBM_FILE_READ_ERROR, /* file read error */ + GDBM_BAD_MAGIC_NUMBER, /* bad magic number */ + GDBM_EMPTY_DATABASE, /* empty database */ + GDBM_CANT_BE_READER, /* can't be reader */ + GDBM_CANT_BE_WRITER, /* can't be writer */ + GDBM_READER_CANT_DELETE, /* reader can't delete */ + GDBM_READER_CANT_STORE, /* reader can't store */ + GDBM_READER_CANT_REORGANIZE, /* reader can't reorganize */ + GDBM_UNKNOWN_UPDATE, /* unknown update */ + GDBM_ITEM_NOT_FOUND, /* item not found */ + GDBM_REORGANIZE_FAILED, /* reorganize failed */ + GDBM_CANNOT_REPLACE, /* cannot replace */ + GDBM_ILLEGAL_DATA, /* illegal data */ + GDBM_OPT_ALREADY_SET, /* option already set */ + GDBM_OPT_ILLEGAL /* option illegal */ +}; + +typedef int gdbm_error; /* type of error codes */ + +typedef struct { /* type of structure for a database handle */ + DEPOT *depot; /* internal database handle of Depot */ + CURIA *curia; /* internal database handle of Curia */ + int syncmode; /* whether to be besyncronous mode */ +} GDBM; + +typedef GDBM *GDBM_FILE; /* type of pointer to a database handle */ + +typedef struct { /* type of structure for a key or a value */ + char *dptr; /* pointer to the region */ + size_t dsize; /* size of the region */ +} datum; + +enum { /* enumeration for open modes */ + GDBM_READER = 1 << 0, /* open as a reader */ + GDBM_WRITER = 1 << 1, /* open as a writer */ + GDBM_WRCREAT = 1 << 2, /* a writer creating */ + GDBM_NEWDB = 1 << 3, /* a writer creating and truncating */ + GDBM_SYNC = 1 << 4, /* syncronous mode */ + GDBM_NOLOCK = 1 << 5, /* no lock mode */ + GDBM_LOCKNB = 1 << 6, /* non-blocking lock mode */ + GDBM_FAST = 1 << 7, /* fast mode */ + GDBM_SPARSE = 1 << 8 /* create as sparse file */ +}; + +enum { /* enumeration for write modes */ + GDBM_INSERT, /* keep an existing value */ + GDBM_REPLACE /* overwrite an existing value */ +}; + +enum { /* enumeration for options */ + GDBM_CACHESIZE, /* set cache size */ + GDBM_FASTMODE, /* set fast mode */ + GDBM_SYNCMODE, /* set syncronous mode */ + GDBM_CENTFREE, /* set free block pool */ + GDBM_COALESCEBLKS /* set free block marging */ +}; + + +/* String containing the version information. */ +MYEXTERN char *gdbm_version; + + +/* Last happened error code. */ +#define gdbm_errno (*gdbm_errnoptr()) + + +/* Get a message string corresponding to an error code. + `gdbmerrno' specifies an error code. + The return value is the message string of the error code. The region of the return value + is not writable. */ +char *gdbm_strerror(gdbm_error gdbmerrno); + + +/* Get a database handle after the fashion of GDBM. + `name' specifies a name of a database. + `read_write' specifies the connection mode: `GDBM_READER' as a reader, `GDBM_WRITER', + `GDBM_WRCREAT' and `GDBM_NEWDB' as a writer. `GDBM_WRCREAT' makes a database file or + directory if it does not exist. `GDBM_NEWDB' makes a new database even if it exists. + You can add the following to writer modes by bitwise or: `GDBM_SYNC', `GDBM_NOLOCK', + `GDBM_LCKNB', `GDBM_FAST', and `GDBM_SPARSE'. `GDBM_SYNC' means a database is synchronized + after every updating method. `GDBM_NOLOCK' means a database is opened without file locking. + `GDBM_LOCKNB' means file locking is performed without blocking. `GDBM_FAST' is ignored. + `GDBM_SPARSE' is an original mode of QDBM and makes database a sparse file. + `mode' specifies a mode of a database file or a database directory as the one of `open' + or `mkdir' call does. + `bnum' specifies the number of elements of each bucket array. If it is not more than 0, + the default value is specified. + `dnum' specifies the number of division of the database. If it is not more than 0, the + returning handle is created as a wrapper of Depot, else, it is as a wrapper of Curia. + The return value is the database handle or `NULL' if it is not successful. + If the database already exists, whether it is one of Depot or Curia is measured + automatically. */ +GDBM_FILE gdbm_open(char *name, int block_size, int read_write, int mode, + void (*fatal_func)(void)); + + +/* Get a database handle after the fashion of QDBM. + `name' specifies a name of a database. + `read_write' specifies the connection mode: `GDBM_READER' as a reader, `GDBM_WRITER', + `GDBM_WRCREAT' and `GDBM_NEWDB' as a writer. `GDBM_WRCREAT' makes a database file or + directory if it does not exist. `GDBM_NEWDB' makes a new database even if it exists. + You can add the following to writer modes by bitwise or: `GDBM_SYNC', `GDBM_NOLOCK', + `GDBM_LOCKNB', `GDBM_FAST', and `GDBM_SPARSE'. `GDBM_SYNC' means a database is synchronized + after every updating method. `GDBM_NOLOCK' means a database is opened without file locking. + `GDBM_LOCKNB' means file locking is performed without blocking. `GDBM_FAST' is ignored. + `GDBM_SPARSE' is an original mode of QDBM and makes database sparse files. + `mode' specifies a mode of a database file as the one of `open' or `mkdir' call does. + `bnum' specifies the number of elements of each bucket array. If it is not more than 0, + the default value is specified. + `dnum' specifies the number of division of the database. If it is not more than 0, the + returning handle is created as a wrapper of Depot, else, it is as a wrapper of Curia. + `align' specifies the basic size of alignment. + The return value is the database handle or `NULL' if it is not successful. */ +GDBM_FILE gdbm_open2(char *name, int read_write, int mode, int bnum, int dnum, int align); + + +/* Close a database handle. + `dbf' specifies a database handle. + Because the region of the closed handle is released, it becomes impossible to use the + handle. */ +void gdbm_close(GDBM_FILE dbf); + + +/* Store a record. + `dbf' specifies a database handle connected as a writer. + `key' specifies a structure of a key. `content' specifies a structure of a value. + `flag' specifies behavior when the key overlaps, by the following values: `GDBM_REPLACE', + which means the specified value overwrites the existing one, `GDBM_INSERT', which means + the existing value is kept. + The return value is 0 if it is successful, 1 if it gives up because of overlaps of the key, + -1 if other error occurs. */ +int gdbm_store(GDBM_FILE dbf, datum key, datum content, int flag); + + +/* Delete a record. + `dbf' specifies a database handle connected as a writer. + `key' specifies a structure of a key. + The return value is 0 if it is successful, -1 if some errors occur. */ +int gdbm_delete(GDBM_FILE dbf, datum key); + + +/* Retrieve a record. + `dbf' specifies a database handle. + `key' specifies a structure of a key. + The return value is a structure of the result. + If a record corresponds, the member `dptr' of the structure is the pointer to the region + of the value. If no record corresponds or some errors occur, `dptr' is `NULL'. Because + the region pointed to by `dptr' is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +datum gdbm_fetch(GDBM_FILE dbf, datum key); + + +/* Check whether a record exists or not. + `dbf' specifies a database handle. + `key' specifies a structure of a key. + The return value is true if a record corresponds and no error occurs, or false, else, + it is false. */ +int gdbm_exists(GDBM_FILE dbf, datum key); + + +/* Get the first key of a database. + `dbf' specifies a database handle. + The return value is a structure of the result. + If a record corresponds, the member `dptr' of the structure is the pointer to the region + of the first key. If no record corresponds or some errors occur, `dptr' is `NULL'. + Because the region pointed to by `dptr' is allocated with the `malloc' call, it should + be released with the `free' call if it is no longer in use. */ +datum gdbm_firstkey(GDBM_FILE dbf); + + +/* Get the next key of a database. + `dbf' specifies a database handle. + The return value is a structure of the result. + If a record corresponds, the member `dptr' of the structure is the pointer to the region + of the next key. If no record corresponds or some errors occur, `dptr' is `NULL'. + Because the region pointed to by `dptr' is allocated with the `malloc' call, it should + be released with the `free' call if it is no longer in use. */ +datum gdbm_nextkey(GDBM_FILE dbf, datum key); + + +/* Synchronize updating contents with the file and the device. + `dbf' specifies a database handle connected as a writer. */ +void gdbm_sync(GDBM_FILE dbf); + + +/* Reorganize a database. + `dbf' specifies a database handle connected as a writer. + If successful, the return value is 0, else -1. */ +int gdbm_reorganize(GDBM_FILE dbf); + + +/* Get the file descriptor of a database file. + `dbf' specifies a database handle connected as a writer. + The return value is the file descriptor of the database file. + If the database is a directory the return value is -1. */ +int gdbm_fdesc(GDBM_FILE dbf); + + +/* No effect. + `dbf' specifies a database handle. + `option' is ignored. `size' is ignored. + The return value is 0. + The function is only for compatibility. */ +int gdbm_setopt(GDBM_FILE dbf, int option, int *value, int size); + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Get the pointer of the last happened error code. */ +int *gdbm_errnoptr(void); + + + +#undef MYEXTERN + +#if defined(__cplusplus) /* export for C++ */ +} +#endif + +#endif /* duplication check */ + + +/* END OF FILE */ diff --git a/qdbm/hvmgr.c b/qdbm/hvmgr.c new file mode 100644 index 00000000..f4141dcc --- /dev/null +++ b/qdbm/hvmgr.c @@ -0,0 +1,582 @@ +/************************************************************************************************* + * Utility for debugging Hovel and its applications + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define ALIGNSIZ 16 /* basic size of alignment */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +char *hextoobj(const char *str, int *sp); +int runcreate(int argc, char **argv); +int runstore(int argc, char **argv); +int rundelete(int argc, char **argv); +int runfetch(int argc, char **argv); +int runlist(int argc, char **argv); +int runoptimize(int argc, char **argv); +void pgerror(const char *name); +void printobj(const char *obj, int size); +void printobjhex(const char *obj, int size); +int docreate(char *name, int qdbm, int bnum, int dnum, int sparse); +int dostore(char *name, int qdbm, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int ins); +int dodelete(char *name, int qdbm, const char *kbuf, int ksiz); +int dofetch(char *name, int qdbm, const char *kbuf, int ksiz, int ox, int nb); +int dolist(char *name, int qdbm, int ox); +int dooptimize(char *name, int qdbm); + + +/* main routine */ +int main(int argc, char **argv){ + int rv; + cbstdiobin(); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "create")){ + rv = runcreate(argc, argv); + } else if(!strcmp(argv[1], "store")){ + rv = runstore(argc, argv); + } else if(!strcmp(argv[1], "delete")){ + rv = rundelete(argc, argv); + } else if(!strcmp(argv[1], "fetch")){ + rv = runfetch(argc, argv); + } else if(!strcmp(argv[1], "list")){ + rv = runlist(argc, argv); + } else if(!strcmp(argv[1], "optimize")){ + rv = runoptimize(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: administration utility for Hovel\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s create [-qdbm bnum dnum] [-s] name\n", progname); + fprintf(stderr, " %s store [-qdbm] [-kx] [-vx|-vf] [-insert] name key val\n", progname); + fprintf(stderr, " %s delete [-qdbm] [-kx] name key\n", progname); + fprintf(stderr, " %s fetch [-qdbm] [-kx] [-ox] [-n] name key\n", progname); + fprintf(stderr, " %s list [-qdbm] [-ox] name\n", progname); + fprintf(stderr, " %s optimize [-qdbm] name\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* create a binary object from a hexadecimal string */ +char *hextoobj(const char *str, int *sp){ + char *buf, mbuf[3]; + int len, i, j; + len = strlen(str); + if(!(buf = malloc(len + 1))) return NULL; + j = 0; + for(i = 0; i < len; i += 2){ + while(strchr(" \n\r\t\f\v", str[i])){ + i++; + } + if((mbuf[0] = str[i]) == '\0') break; + if((mbuf[1] = str[i+1]) == '\0') break; + mbuf[2] = '\0'; + buf[j++] = (char)strtol(mbuf, NULL, 16); + } + buf[j] = '\0'; + *sp = j; + return buf; +} + + +/* parse arguments of create command */ +int runcreate(int argc, char **argv){ + char *name; + int i, sb, qdbm, bnum, dnum, rv; + name = NULL; + sb = FALSE; + qdbm = FALSE; + bnum = -1; + dnum = -1; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-qdbm")){ + qdbm = TRUE; + if(++i >= argc) usage(); + bnum = atoi(argv[i]); + if(++i >= argc) usage(); + dnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-s")){ + sb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = docreate(name, qdbm, bnum, dnum, sb); + return rv; +} + + +/* parse arguments of store command */ +int runstore(int argc, char **argv){ + char *name, *key, *val, *kbuf, *vbuf; + int i, qdbm, kx, vx, vf, ins, ksiz, vsiz, rv; + name = NULL; + qdbm = FALSE; + kx = FALSE; + vx = FALSE; + vf = FALSE; + ins = FALSE; + key = NULL; + val = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-qdbm")){ + qdbm = TRUE; + } else if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-vx")){ + vx = TRUE; + } else if(!strcmp(argv[i], "-vf")){ + vf = TRUE; + } else if(!strcmp(argv[i], "-insert")){ + ins = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else if(!val){ + val = argv[i]; + } else { + usage(); + } + } + if(!name || !key || !val) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = strlen(kbuf); + } + if(vx){ + vbuf = hextoobj(val, &vsiz); + } else if(vf){ + vbuf = cbreadfile(val, &vsiz); + } else { + vbuf = cbmemdup(val, -1); + vsiz = strlen(vbuf); + } + if(kbuf && vbuf){ + rv = dostore(name, qdbm, kbuf, ksiz, vbuf, vsiz, ins); + } else { + if(vf){ + fprintf(stderr, "%s: %s: cannot read\n", progname, val); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + } + rv = 1; + } + free(kbuf); + free(vbuf); + return rv; +} + + +/* parse arguments of delete command */ +int rundelete(int argc, char **argv){ + char *name, *key, *kbuf; + int i, qdbm, kx, ksiz, rv; + name = NULL; + qdbm = FALSE; + kx = FALSE; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-qdbm")){ + qdbm = TRUE; + } else if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = strlen(kbuf); + } + if(kbuf){ + rv = dodelete(name, qdbm, kbuf, ksiz); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* parse arguments of fetch command */ +int runfetch(int argc, char **argv){ + char *name, *key, *kbuf; + int i, qdbm, kx, ox, nb, ksiz, rv; + name = NULL; + qdbm = FALSE; + kx = FALSE; + ox = FALSE; + nb = FALSE; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-qdbm")){ + qdbm = TRUE; + } else if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else if(!strcmp(argv[i], "-n")){ + nb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = strlen(kbuf); + } + if(kbuf){ + rv = dofetch(name, qdbm, kbuf, ksiz, ox, nb); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* parse arguments of list command */ +int runlist(int argc, char **argv){ + char *name; + int i, qdbm, ox, rv; + name = NULL; + qdbm = FALSE; + ox = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-qdbm")){ + qdbm = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dolist(name, qdbm, ox); + return rv; +} + + +/* parse arguments of optimize command */ +int runoptimize(int argc, char **argv){ + char *name; + int i, qdbm, rv; + name = NULL; + qdbm = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-qdbm")){ + qdbm = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dooptimize(name, qdbm); + return rv; +} + + +/* print an error message */ +void pgerror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, gdbm_strerror(gdbm_errno)); +} + + +/* print an object */ +void printobj(const char *obj, int size){ + int i; + for(i = 0; i < size; i++){ + putchar(obj[i]); + } +} + + +/* print an object as a hexadecimal string */ +void printobjhex(const char *obj, int size){ + int i; + for(i = 0; i < size; i++){ + printf("%s%02X", i > 0 ? " " : "", ((const unsigned char *)obj)[i]); + } +} + + +/* perform create command */ +int docreate(char *name, int qdbm, int bnum, int dnum, int sparse){ + GDBM_FILE dbf; + int rwmode; + rwmode = GDBM_NEWDB | (sparse ? GDBM_SPARSE : 0); + if(qdbm){ + if(!(dbf = gdbm_open2(name, rwmode, 00644, bnum, dnum, ALIGNSIZ))){ + pgerror(name); + return 1; + } + } else { + if(!(dbf = gdbm_open(name, 0, rwmode, 00644, NULL))){ + pgerror(name); + return 1; + } + } + gdbm_close(dbf); + return 0; +} + + +/* perform store command */ +int dostore(char *name, int qdbm, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int ins){ + GDBM_FILE dbf; + datum key, content; + int rv; + if(qdbm){ + if(!(dbf = gdbm_open2(name, GDBM_WRITER, 00644, -1, -1, ALIGNSIZ))){ + pgerror(name); + return 1; + } + } else { + if(!(dbf = gdbm_open(name, 0, GDBM_WRITER, 00644, NULL))){ + pgerror(name); + return 1; + } + } + key.dptr = (char *)kbuf; + key.dsize = ksiz; + content.dptr = (char *)vbuf; + content.dsize = vsiz; + rv = 0; + if(gdbm_store(dbf, key, content, ins ? GDBM_INSERT : GDBM_REPLACE) != 0){ + pgerror(name); + rv = 1; + } + gdbm_close(dbf); + return rv; +} + + +/* perform delete command */ +int dodelete(char *name, int qdbm, const char *kbuf, int ksiz){ + GDBM_FILE dbf; + datum key; + int rv; + if(qdbm){ + if(!(dbf = gdbm_open2(name, GDBM_WRITER, 00644, -1, -1, ALIGNSIZ))){ + pgerror(name); + return 1; + } + } else { + if(!(dbf = gdbm_open(name, 0, GDBM_WRITER, 00644, NULL))){ + pgerror(name); + return 1; + } + } + key.dptr = (char *)kbuf; + key.dsize = ksiz; + if(gdbm_delete(dbf, key) == 0){ + rv = 0; + } else { + pgerror(name); + rv = 1; + } + gdbm_close(dbf); + return rv; +} + + +/* perform fetch command */ +int dofetch(char *name, int qdbm, const char *kbuf, int ksiz, int ox, int nb){ + GDBM_FILE dbf; + datum key, content; + int rv; + if(qdbm){ + if(!(dbf = gdbm_open2(name, GDBM_READER, 00644, -1, -1, -1))){ + pgerror(name); + return 1; + } + } else { + if(!(dbf = gdbm_open(name, 0, GDBM_READER, 00644, NULL))){ + pgerror(name); + return 1; + } + } + key.dptr = (char *)kbuf; + key.dsize = ksiz; + content = gdbm_fetch(dbf, key); + if(content.dptr){ + if(ox){ + printobjhex(content.dptr, content.dsize); + } else { + printobj(content.dptr, content.dsize); + } + if(!nb) putchar('\n'); + rv = 0; + free(content.dptr); + } else { + pgerror(name); + rv = 1; + } + gdbm_close(dbf); + return rv; +} + + +/* perform list command */ +int dolist(char *name, int qdbm, int ox){ + GDBM_FILE dbf; + datum key, val; + if(qdbm){ + if(!(dbf = gdbm_open2(name, GDBM_READER, 00644, -1, -1, -1))){ + pgerror(name); + return 1; + } + } else { + if(!(dbf = gdbm_open(name, 0, GDBM_READER, 00644, NULL))){ + pgerror(name); + return 1; + } + } + for(key = gdbm_firstkey(dbf); key.dptr != NULL; key = gdbm_nextkey(dbf, key)){ + val = gdbm_fetch(dbf, key); + if(!val.dptr){ + free(key.dptr); + break; + } + if(ox){ + printobjhex(key.dptr, key.dsize); + putchar('\t'); + printobjhex(val.dptr, val.dsize); + } else { + printobj(key.dptr, key.dsize); + putchar('\t'); + printobj(val.dptr, val.dsize); + } + putchar('\n'); + free(val.dptr); + free(key.dptr); + } + gdbm_close(dbf); + return 0; +} + + +/* perform optimize command */ +int dooptimize(char *name, int qdbm){ + GDBM_FILE dbf; + int rv; + if(qdbm){ + if(!(dbf = gdbm_open2(name, GDBM_WRITER, 00644, -1, -1, ALIGNSIZ))){ + pgerror(name); + return 1; + } + } else { + if(!(dbf = gdbm_open(name, 0, GDBM_WRITER, 00644, NULL))){ + pgerror(name); + return 1; + } + } + rv = 0; + if(gdbm_reorganize(dbf) != 0){ + pgerror(name); + rv = 1; + } + gdbm_close(dbf); + return rv; +} + + + +/* END OF FILE */ diff --git a/qdbm/hvtest.c b/qdbm/hvtest.c new file mode 100644 index 00000000..5aea24e8 --- /dev/null +++ b/qdbm/hvtest.c @@ -0,0 +1,272 @@ +/************************************************************************************************* + * Test cases of Hovel + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define DIVNUM 5 /* number of division */ +#define ALIGNSIZ 16 /* basic size of alignment */ +#define RECBUFSIZ 32 /* buffer for records */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +int runwrite(int argc, char **argv); +int runread(int argc, char **argv); +int printfflush(const char *format, ...); +void pgerror(const char *name); +int dowrite(char *name, int rnum, int qdbm, int sparse); +int doread(char *name, int rnum, int qdbm); + + +/* main routine */ +int main(int argc, char **argv){ + int rv; + cbstdiobin(); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "write")){ + rv = runwrite(argc, argv); + } else if(!strcmp(argv[1], "read")){ + rv = runread(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: test cases for Hovel\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s write [-qdbm] [-s] name rnum\n", progname); + fprintf(stderr, " %s read [-qdbm] name rnum\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of write command */ +int runwrite(int argc, char **argv){ + char *name, *rstr; + int i, sb, qdbm, rnum, rv; + name = NULL; + rstr = NULL; + rnum = 0; + sb = FALSE; + qdbm = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-qdbm")){ + qdbm = TRUE; + } else if(!strcmp(argv[i], "-s")){ + sb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = dowrite(name, rnum, qdbm, sb); + return rv; +} + + +/* parse arguments of read command */ +int runread(int argc, char **argv){ + char *name, *rstr; + int i, qdbm, rnum, rv; + name = NULL; + rstr = NULL; + rnum = 0; + qdbm = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-qdbm")){ + qdbm = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = doread(name, rnum, qdbm); + return rv; +} + + +/* print formatted string and flush the buffer */ +int printfflush(const char *format, ...){ + va_list ap; + int rv; + va_start(ap, format); + rv = vprintf(format, ap); + if(fflush(stdout) == EOF) rv = -1; + va_end(ap); + return rv; +} + + +/* print an error message */ +void pgerror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, gdbm_strerror(gdbm_errno)); +} + + +/* perform write command */ +int dowrite(char *name, int rnum, int qdbm, int sparse){ + GDBM_FILE dbf; + datum key, content; + int i, rwmode, err, len; + char buf[RECBUFSIZ]; + printfflush("\n name=%s rnum=%d qdbm=%d\n\n", name, rnum, qdbm); + /* open a database */ + rwmode = GDBM_NEWDB | (sparse ? GDBM_SPARSE : 0); + if(qdbm){ + if(!(dbf = gdbm_open2(name, rwmode, 00644, rnum / DIVNUM, DIVNUM, ALIGNSIZ))){ + pgerror(name); + return 1; + } + } else { + if(!(dbf = gdbm_open(name, 0, rwmode, 00644, NULL))){ + pgerror(name); + return 1; + } + } + err = FALSE; + /* loop for each record */ + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", i); + key.dptr = buf; + key.dsize = len; + content.dptr = buf; + content.dsize = len; + /* store a record */ + if(gdbm_store(dbf, key, content, GDBM_REPLACE) != 0){ + pgerror(name); + err = TRUE; + break; + } + /* print progression */ + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + gdbm_close(dbf); + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform read command */ +int doread(char *name, int rnum, int qdbm){ + GDBM_FILE dbf; + datum key, content; + int i, err, len; + char buf[RECBUFSIZ]; + printfflush("\n name=%s rnum=%d qdbm=%d\n\n", name, rnum, qdbm); + /* open a database */ + if(qdbm){ + if(!(dbf = gdbm_open2(name, GDBM_READER, 00644, -1, -1, -1))){ + pgerror(name); + return 1; + } + } else { + if(!(dbf = gdbm_open(name, 0, GDBM_READER, 00644, NULL))){ + pgerror(name); + return 1; + } + } + err = FALSE; + /* loop for each record */ + for(i = 1; i <= rnum; i++){ + /* retrieve a record */ + len = sprintf(buf, "%08d", i); + key.dptr = buf; + key.dsize = len; + content = gdbm_fetch(dbf, key); + if(!content.dptr){ + pgerror(name); + err = TRUE; + break; + } + free(content.dptr); + /* print progression */ + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + gdbm_close(dbf); + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/misc/COPYING.txt b/qdbm/misc/COPYING.txt new file mode 100644 index 00000000..b1e3f5a2 --- /dev/null +++ b/qdbm/misc/COPYING.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/qdbm/misc/README-win32.txt b/qdbm/misc/README-win32.txt new file mode 100644 index 00000000..d5a98e2d --- /dev/null +++ b/qdbm/misc/README-win32.txt @@ -0,0 +1,101 @@ +================================================================ + QDBM: Quick Database Manager + Copyright (C) 2000-2007 Mikio Hirabayashi +================================================================ + +This is a package of Win32 binaries of QDBM. It contains C/Java +APIs, their utility commands, and CGI scripts. + +See http://qdbm.sourceforge.net/ for more information. + + +The following are documents of specifications. + + spex.html : fundamental specifications + spex-ja.html : fundamental specifications in Japanese + jspex.html : specifications of Java API + jspex-ja.html : specifications of Java API in Japanese + japidoc/ : documents of Java API + + +The following are header files of C language. +Include them at source codes of your applications. + + depot.h + curia.h + relic.h + hovel.h + cabin.h + villa.h + vista.h + odeum.h + + +The following are dynamic linking libraries for the API of C. +Copy them to the system directory or a directory of your project. + + qdbm.dll : QDBM itself + libqdbm.dll.a : import library for `qdbm.dll' + mgwz.dll : ZLIB + libiconv-2.dll : ICONV + + +The following is a dynamic linking library for the API of Java. +Copy it to the system directory or a directory of your project. + + jqdbm.dll + + +The following is a Java archive of the classes. +Include it in the CLASSPATH of your environment. + + qdbm.jar + + +The following are utility commands for testing and debugging. + + dpmgr.exe + dptest.exe + dptsv.exe + crmgr.exe + crtest.exe + crtsv.exe + rlmgr.exe + rltest.exe + hvmgr.exe + hvtest.exe + cbtest.exe + cbcodec.exe + vlmgr.exe + vltest.exe + vltsv.exe + odmgr.exe + odtest.exe + odidx.exe + qmttest.exe + + +The sub directory `cgi' contains CGI scripts, their configuration +files, and their specifications. + +If you want an import library or a static library for Visual C++, +please obtain the source package and use VCmakefile in it. + + +QDBM was released under the terms of the GNU Lesser General Public +License. See the file `COPYING.txt' for details. + +QDBM was written by Mikio Hirabayashi. You can contact the author +by e-mail to `mikio@users.sourceforge.net'. However, as for +topics which can be shared among other users, pleae send it to +the mailing list. To join the mailing list, refer to the following +URL. + + http://lists.sourceforge.net/lists/listinfo/qdbm-users + + +Thanks. + + + +== END OF FILE == diff --git a/qdbm/misc/VCmakefile-old b/qdbm/misc/VCmakefile-old new file mode 100644 index 00000000..8cd55467 --- /dev/null +++ b/qdbm/misc/VCmakefile-old @@ -0,0 +1,169 @@ +# Makefile to build QDBM using Microsoft Visual C++ + + + +#================================================================ +# Setting Variables +#================================================================ + + +# Targets +MYLIBS = qdbm.lib +LIBOBJS = depot.obj curia.obj relic.obj hovel.obj \ + cabin.obj villa.obj vista.obj odeum.obj myconf.obj +MYBINS = dpmgr.exe dptest.exe dptsv.exe crmgr.exe crtest.exe crtsv.exe \ + rlmgr.exe rltest.exe hvmgr.exe hvtest.exe cbtest.exe cbcodec.exe \ + vlmgr.exe vltest.exe vltsv.exe odmgr.exe odtest.exe odidx.exe + +# VC++ directory +VCPATH = C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 + +# Building binaries +CLFLAGS = /I "$(VCPATH)\Include" /I "$(VCPATH)\PlatformSDK\Include" /I "." /O2 /nologo +LIBFLAGS = /libpath:"$(VCPATH)\lib" /libpath:"$(VCPATH)\PlatformSDK\Lib" /libpath:"." /nologo +LINKFLAGS = /libpath:"$(VCPATH)\lib" /libpath:"$(VCPATH)\PlatformSDK\Lib" /libpath:"." /nologo + + + +#================================================================ +# Suffix rules +#================================================================ + + +.SUFFIXES : +.SUFFIXES : .c .obj + +.c.obj : + cl /c $(CLFLAGS) $< + + + +#================================================================ +# Actions +#================================================================ + + +all : $(MYLIBS) $(MYBINS) + + +clean : + del *.obj *.lib *.dll *.exp *.exe + + + +#================================================================ +# Building binaries +#================================================================ + + +qdbm.lib : $(LIBOBJS) + lib $(LIBFLAGS) /OUT:$@ $(LIBOBJS) + + +dpmgr.exe : dpmgr.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ dpmgr.obj qdbm.lib + + +dptest.exe : dptest.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ dptest.obj qdbm.lib + + +dptsv.exe : dptsv.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ dptsv.obj qdbm.lib + + +crmgr.exe : crmgr.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ crmgr.obj qdbm.lib + + +crtest.exe : crtest.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ crtest.obj qdbm.lib + + +crtsv.exe : crtsv.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ crtsv.obj qdbm.lib + + +rlmgr.exe : rlmgr.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ rlmgr.obj qdbm.lib + + +rltest.exe : rltest.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ rltest.obj qdbm.lib + + +hvmgr.exe : hvmgr.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ hvmgr.obj qdbm.lib + + +hvtest.exe : hvtest.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ hvtest.obj qdbm.lib + + +cbtest.exe : cbtest.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ cbtest.obj qdbm.lib + + +cbcodec.exe : cbcodec.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ cbcodec.obj qdbm.lib + + +vlmgr.exe : vlmgr.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ vlmgr.obj qdbm.lib + + +vltest.exe : vltest.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ vltest.obj qdbm.lib + + +vltsv.exe : vltsv.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ vltsv.obj qdbm.lib + + +odmgr.exe : odmgr.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ odmgr.obj qdbm.lib + + +odtest.exe : odtest.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ odtest.obj qdbm.lib + + +odidx.exe : odidx.obj qdbm.lib + link $(LINKFLAGS) /OUT:$@ odidx.obj qdbm.lib + + +depot.obj : depot.h myconf.h + +curia.obj : depot.h curia.h myconf.h + +relic.obj : depot.h relic.h myconf.h + +hovel.obj : depot.h curia.h hovel.h myconf.h + +cabin.obj : cabin.h myconf.h + +villa.obj : depot.h cabin.h villa.h myconf.h + +vista.obj : depot.h curia.h cabin.h villa.h vista.h myconf.h + +odeum.obj : depot.h curia.h cabin.h villa.h myconf.h + +myconf.obj : myconf.h + +dpmgr.obj dptest.obj dptsv.obj : depot.h cabin.h + +crmgr.obj crtest.obj crtsv.obj : depot.h curia.h cabin.h + +rlmgr.obj rltest.obj : depot.h relic.h cabin.h + +hvmgr.obj hvtest.obj : depot.h curia.h hovel.h cabin.h + +cbtest.obj cbcodec.obj : cabin.h + +vlmgr.obj vltest.obj vltsv.obj : depot.h cabin.h villa.h + +odmgr.obj odtest.obj odidx.obj : depot.h curia.h cabin.h villa.h odeum.h + + + +# END OF FILE diff --git a/qdbm/misc/benchmark.pdf b/qdbm/misc/benchmark.pdf new file mode 100644 index 00000000..8b9df904 Binary files /dev/null and b/qdbm/misc/benchmark.pdf differ diff --git a/qdbm/misc/icon16.png b/qdbm/misc/icon16.png new file mode 100644 index 00000000..6d6ed13d Binary files /dev/null and b/qdbm/misc/icon16.png differ diff --git a/qdbm/misc/icon20.png b/qdbm/misc/icon20.png new file mode 100644 index 00000000..edad7849 Binary files /dev/null and b/qdbm/misc/icon20.png differ diff --git a/qdbm/misc/index.html b/qdbm/misc/index.html new file mode 100644 index 00000000..7a5271c3 --- /dev/null +++ b/qdbm/misc/index.html @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + +QDBM: Quick Database Manager + + + + + + +

QDBM: Quick Database Manager

+ +
Copyright (C) 2000-2007 Mikio Hirabayashi
+
Last Update: Thu, 26 Oct 2006 15:00:20 +0900
+ + + + +
+ +

Overview

+ +

QDBM is a library of routines for managing a database. The database is a simple data file containing records, each is a pair of a key and a value. Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. There is neither concept of data tables nor data types. Records are organized in hash table or B+ tree.

+ +

As for database of hash table, each key must be unique within a database, so it is impossible to store two or more records with a key overlaps. The following access methods are provided to the database: storing a record with a key and a value, deleting a record by a key, retrieving a record by a key. Moreover, traversal access to every key are provided, although the order is arbitrary. These access methods are similar to ones of DBM (or its followers: NDBM and GDBM) library defined in the UNIX standard. QDBM is an alternative for DBM because of its higher performance.

+ +

As for database of B+ tree, records whose keys are duplicated can be stored. Access methods of storing, deleting, and retrieving are provided as with the database of hash table. Records are stored in order by a comparing function assigned by a user. It is possible to access each record with the cursor in ascending or descending order. According to this mechanism, forward matching search for strings and range search for integers are realized. Moreover, transaction is available in database of B+ tree.

+ +

QDBM is written in C, and provided as APIs of C, C++, Java, Perl, and Ruby. QDBM is available on platforms which have API conforming to POSIX. QDBM is a free software licensed under the GNU Lesser General Public License.

+ +
+ +

Documents

+ +

The following are documents of QDBM. They are contained also in the source package.

+ + + +
+ +

Packages

+ +

The following are packages of QDBM. The Linux binary package contains APIs for C, C++, and Java. It contains CGI scripts also. The Windows binary package contains APIs for C and Java. It contains CGI scripts also.

+ + + + + + + +
+ +

Applications

+ +

The following are links to applications of QDBM. If you run or find a project using QDBM, please tell it, and it will added to this list.

+ +
    +
  • Hyper Estraier : Full-text Search System for Communities written by Mikio Hirabayashi
  • +
  • Estraier : Personal Full-text Search System written by Mikio Hirabayashi
  • +
  • Diqt : Multilingual Dictionary Searcher written by Mikio Hirabayashi
  • +
  • RBBS : WWW-based Bulletin Board System written by Mikio Hirabayashi
  • +
  • Harvest : Distributed Search System written by Kang-Jin Lee et al
  • +
  • Bogofilter : Bayesian Spam Mail Filter written by Eric S. Raymond et al
  • +
  • MQS : Minimalist Queue Services written by Alexandre Dulaunoy
  • +
  • Ruby/Odeum : Ruby Binding to the Inverted API written by Zed A. Shaw
  • +
  • Surfulater : Utility to Save and Organize Web Pages written by Soft As it Gets Pty Ltd
  • +
  • Mutt-NG : Text Based Mail Client written by Andreas Krennmair et al
  • +
  • SMFS : Smart Sendmail Filters written by Eugene Kurmanin
  • +
  • Dixit : Romanian Dictionary Searcher written by Octavian Procopiuc
  • +
+ +
+ +

Brothers

+ +

There are many followers of UNIX DBM. Select the best suited one for your products. NDBM is ancient and you should not use it. SDBM is maintained by Apache Project, and GDBM is maintained by GNU Project. They are most popular and time-tested. TDB is maintained by Samba Team. It allows multiple simultaneous writers. While CDB does not support updating at a runtime, it is the fastest. Berkeley DB is very multifunctional and ACID compliant. It is used in many commercial products. Finally, QDBM is balanced of performance, functionality, portability, and usability.

+ +
    +
  • NDBM : New DBM written by BSD
  • +
  • SDBM : Substitute DBM written by Ozan S. Yigit
  • +
  • GDBM : GNU Database Manager written by Philip A. Nelson et al
  • +
  • TDB : Trivial Database written by Andrew Tridgell et al
  • +
  • TinyCDB : Constant Database written by Michael Tokarev
  • +
  • Berkeley DB : Berkeley DB written by Sleepycat Software
  • +
+ + + +
+ +

Information

+ +

QDBM was written by Mikio Hirabayashi. You can contact the author by e-mail to `mikio@users.sourceforge.net'. However, as for topics which can be shared among other users, pleae send it to the mailing list. To join the mailing list, refer to `http://lists.sourceforge.net/lists/listinfo/qdbm-users'.

+ +

The project page on SourceForge.net is `http://sourceforge.net/projects/qdbm/'.

+ +

Update of this project is announced on Freshmeat.net at `http://freshmeat.net/projects/qdbm/'.

+ +
+ + + + + + diff --git a/qdbm/misc/index.ja.html b/qdbm/misc/index.ja.html new file mode 100644 index 00000000..65ea073c --- /dev/null +++ b/qdbm/misc/index.ja.html @@ -0,0 +1,209 @@ + + + + + + + + + + + + + + +データベースライブラリ QDBM + + + + + + +

QDBM: Quick Database Manager

+ +
Copyright (C) 2000-2007 Mikio Hirabayashi
+
Last Update: Thu, 26 Oct 2006 15:00:20 +0900
+ + + + +
+ +

概è¦

+ +

QDBMã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†ãƒ«ãƒ¼ãƒãƒ³ç¾¤ã®ãƒ©ã‚¤ãƒ–ラリã§ã™ã€‚データベースã¨ã„ã£ã¦ã‚‚å˜ç´”ãªã‚‚ã®ã§ã€ã‚­ãƒ¼ã¨å€¤ã®ãƒšã‚¢ã‹ã‚‰ãªã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ç¾¤ã‚’æ ¼ç´ã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ã§ã™ã€‚キーã¨å€¤ã¯ä»»æ„ã®é•·ã•ã‚’æŒã¤ä¸€é€£ã®ãƒã‚¤ãƒˆåˆ—ã§ã‚ã‚Šã€æ–‡å­—列ã§ã‚‚ãƒã‚¤ãƒŠãƒªã§ã‚‚扱ã†ã“ã¨ãŒã§ãã¾ã™ã€‚テーブルやデータ型ã®æ¦‚念ã¯ã‚ã‚Šã¾ã›ã‚“。レコードã¯ãƒãƒƒã‚·ãƒ¥è¡¨ã¾ãŸã¯B+木ã§ç·¨æˆã•ã‚Œã¾ã™ã€‚

+ +

ãƒãƒƒã‚·ãƒ¥è¡¨ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã§ã¯ã€ã‚­ãƒ¼ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹å†…ã§ä¸€æ„ã§ã‚ã‚Šã€ã‚­ãƒ¼ãŒé‡è¤‡ã™ã‚‹è¤‡æ•°ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã™ã‚‹ã“ã¨ã¯ã§ãã¾ã›ã‚“。ã“ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«å¯¾ã—ã¦ã¯ã€ã‚­ãƒ¼ã¨å€¤ã‚’指定ã—ã¦ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã—ãŸã‚Šã€ã‚­ãƒ¼ã‚’指定ã—ã¦å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã—ãŸã‚Šã€ã‚­ãƒ¼ã‚’指定ã—ã¦å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã—ãŸã‚Šã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚ã¾ãŸã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã—ã¦ã‚ã‚‹å…¨ã¦ã®ã‚­ãƒ¼ã‚’é †ä¸åŒã«ä¸€ã¤ãšã¤å–り出ã™ã“ã¨ã‚‚ã§ãã¾ã™ã€‚ã“ã®ã‚ˆã†ãªæ“作ã¯ã€UNIX標準ã§å®šç¾©ã•ã‚Œã¦ã„ã‚‹DBMライブラリãŠã‚ˆã³ãã®è¿½å¾“ã§ã‚ã‚‹NDBMã‚„GDBMã«é¡žã™ã‚‹ã‚‚ã®ã§ã™ã€‚QDBMã¯DBMã®ã‚ˆã‚Šè‰¯ã„代替ã¨ã—ã¦åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚

+ +

B+木ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã§ã¯ã€ã‚­ãƒ¼ãŒé‡è¤‡ã™ã‚‹è¤‡æ•°ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚ã“ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«å¯¾ã—ã¦ã¯ã€ãƒãƒƒã‚·ãƒ¥è¡¨ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¨åŒæ§˜ã«ã€ã‚­ãƒ¼ã‚’指定ã—ã¦ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã—ãŸã‚Šå–り出ã—ãŸã‚Šå‰Šé™¤ã—ãŸã‚Šã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚レコードã¯ãƒ¦ãƒ¼ã‚¶ãŒæŒ‡ç¤ºã—ãŸæ¯”較関数ã«åŸºã¥ã„ã¦æ•´åˆ—ã•ã‚Œã¦æ ¼ç´ã•ã‚Œã¾ã™ã€‚カーソルを用ã„ã¦å„レコードを昇順ã¾ãŸã¯é™é †ã§å‚ç…§ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚ã“ã®æ©Ÿæ§‹ã«ã‚ˆã£ã¦ã€æ–‡å­—列ã®å‰æ–¹ä¸€è‡´æ¤œç´¢ã‚„数値ã®ç¯„囲検索ãŒå¯èƒ½ã«ãªã‚Šã¾ã™ã€‚ã¾ãŸã€B+木ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã§ã¯ãƒˆãƒ©ãƒ³ã‚¶ã‚¯ã‚·ãƒ§ãƒ³ãŒåˆ©ç”¨ã§ãã¾ã™ã€‚

+ +

QDBMã¯Cã§è¨˜è¿°ã•ã‚Œã€Cã€C++ã€Javaã€PerlãŠã‚ˆã³Rubyã®APIã¨ã—ã¦æä¾›ã•ã‚Œã¾ã™ã€‚QDBMã¯POSIX準拠ã®APIã‚’å‚™ãˆã‚‹ãƒ—ラットフォームã§åˆ©ç”¨ã§ãã¾ã™ã€‚QDBMã¯GNU Lesser General Public Licenseã«åŸºã¥ãフリーソフトウェアã§ã™ã€‚

+ +
+ +

文書

+ +

以下ã®æ–‡æ›¸ã‚’ãŠèª­ã¿ãã ã•ã„。ソースパッケージã«ã‚‚åŒã˜ã‚‚ã®ãŒå«ã¾ã‚Œã¦ã„ã¾ã™ã€‚

+ + + +
+ +

ダウンロード

+ +

以下ã®ãƒ‘ッケージをダウンロードã—ã¦ãã ã•ã„。Linux用ãƒã‚¤ãƒŠãƒªãƒ‘ッケージã¯ã€Cã¨C++ã¨Javaã®APIã¨ã€CGIスクリプトをç´ã‚ã¦ã„ã¾ã™ã€‚Windows用ãƒã‚¤ãƒŠãƒªãƒ‘ッケージã¯ã€Cã¨Javaã®APIã¨ã€CGIスクリプトをç´ã‚ã¦ã„ã¾ã™ã€‚

+ + + + + + + +
+ +

アプリケーション

+ +

QDBMã®ã‚¢ãƒ—リケーションã«ã¯ä»¥ä¸‹ã®ã‚‚ã®ãŒã‚ã‚Šã¾ã™ã€‚ã‚‚ã—ã‚ãªãŸã®ãƒ—ロジェクトãŒQDBMを使ã£ã¦ã„ã‚‹ãªã‚‰ã€é€£çµ¡ã‚’ã„ãŸã ã‘ã‚Œã°ã“ã®ãƒªã‚¹ãƒˆã«è¿½åŠ ã„ãŸã—ã¾ã™ã€‚

+ +
    +
  • Hyper Estraier : 平林幹雄ã«ã‚ˆã‚‹å…±åŒä½“的全文検索システム
  • +
  • Estraier : 平林幹雄ã«ã‚ˆã‚‹å€‹äººç”¨å…¨æ–‡æ¤œç´¢ã‚·ã‚¹ãƒ†ãƒ 
  • +
  • Diqt : 平林幹雄ã«ã‚ˆã‚‹å¤šè¨€èªžè¾žæ›¸æ¤œç´¢ã‚·ã‚¹ãƒ†ãƒ 
  • +
  • RBBS : 平林幹雄ã«ã‚ˆã‚‹Web掲示æ¿ã‚·ã‚¹ãƒ†ãƒ 
  • +
  • Harvest : Kang-Jin Leeらã«ã‚ˆã‚‹åˆ†æ•£æƒ…報検索システム
  • +
  • Bogofilter : Eric S. Raymondらã«ã‚ˆã‚‹ãƒ™ã‚¤ã‚ºå¼ã‚¹ãƒ‘ムメールフィルタ
  • +
  • MQS : Alexandre Dulaunoyã«ã‚ˆã‚‹ã‚­ãƒ¥ãƒ¼ç®¡ç†ã‚µãƒ¼ãƒ“ス
  • +
  • Ruby/Odeum : Zed A. Shawã«ã‚ˆã‚‹è»¢ç½®APIã®Ruby用インターフェイス
  • +
  • Surfulater : Soft As it Gets Pty社ã«ã‚ˆã‚‹Webページスクラップブック
  • +
  • Mutt-NG : Andreas Krennmairらã«ã‚ˆã‚‹ãƒ†ã‚­ã‚¹ãƒˆåž‹ãƒ¡ãƒ¼ãƒ«ã‚¯ãƒ©ã‚¤ã‚¢ãƒ³ãƒˆ
  • +
  • SMFS : Eugene Kurmaninã«ã‚ˆã‚‹Sendmail用フィルタシステム
  • +
  • Dixit : Octavian Procopiucã«ã‚ˆã‚‹ãƒ«ãƒ¼ãƒžãƒ‹ã‚¢èªžè¾žæ›¸æ¤œç´¢ã‚·ã‚¹ãƒ†ãƒ 
  • +
+ +
+ +

兄弟

+ +

UNIX標準ã®DBMã«è¿½å¾“ã—ãŸãƒ©ã‚¤ãƒ–ラリã¯ãŸãã•ã‚“ã‚ã‚Šã¾ã™ã€‚ãã‚Œãžã‚Œç‰¹å¾´ãŒã‚ã‚Šã¾ã™ã®ã§ã€ã‚ãªãŸã®è£½å“ã«ã¨ã£ã¦éƒ½åˆãŒã„ã„ã‚‚ã®ã‚’é¸ã‚“ã§ãã ã•ã„。NDBMã¯å¤ã„ã®ã§ã€ã‚‚ã¯ã‚„使ã†ç†ç”±ã¯ãªã„ã§ã—ょã†ã€‚SDBMã¯Apache Projectã§ç®¡ç†ã•ã‚Œã€GDBMã¯GNU Projectã§ç®¡ç†ã•ã‚Œã¦ã„ã¾ã™ã€‚ãれらã¯æœ€ã‚‚人気ãŒã‚ã‚Šã€ã¾ãŸæ•°å¤šãテストã•ã‚Œã¦ã„ã‚‹ã‚‚ã®ã§ã—ょã†ã€‚TDBã¯Samba Teamã§ç®¡ç†ã•ã‚Œã¦ãŠã‚Šã€è¤‡æ•°åŒæ™‚ã®æ›¸ãè¾¼ã¿ãŒå¯èƒ½ã§ã™ã€‚TinyCDBã¯éšæ™‚ã®æ›´æ–°ã¯ã§ãã¾ã›ã‚“ãŒã€æœ€ã‚‚高速ã«å‹•ä½œã—ã¾ã™ã€‚Berkeley DBã¯éžå¸¸ã«å¤šæ©Ÿèƒ½ã§ã€ACID準拠ã§ã€å¤šãã®å•†ç”¨è£½å“ã§ä½¿ã‚ã‚Œã¦ã„ã¾ã™ã€‚最後ã«ã€QDBMã¯æ€§èƒ½ã¨æ©Ÿèƒ½ã¨ç§»æ¤æ€§ã¨åˆ©ä¾¿æ€§ã®ãƒãƒ©ãƒ³ã‚¹ãŒã¨ã‚ŒãŸè£½å“ã§ã™ã€‚

+ +
    +
  • NDBM : BSDã«ã‚ˆã‚‹New DBM
  • +
  • SDBM : Ozan S. Yigitã«ã‚ˆã‚‹Substitute DBM
  • +
  • GDBM : Philip A. Nelsonらã«ã‚ˆã‚‹GNU Database Manager
  • +
  • TDB : Andrew Tridgellらã«ã‚ˆã‚‹Trivial Database
  • +
  • TinyCDB : Michael Tokarevã«ã‚ˆã‚‹Constant Database
  • +
  • Berkeley DB : Sleepycat Software社ã«ã‚ˆã‚‹Berkeley DB
  • +
+ + + +
+ +

ãã®ä»–ã®æƒ…å ±

+ +

QDBMã¯å¹³æž—幹雄ãŒä½œæˆã—ã¾ã—ãŸã€‚作者ã¨é€£çµ¡ã‚’ã¨ã‚‹ã«ã¯ã€`mikio@users.sourceforge.net' å®›ã«é›»å­ãƒ¡ãƒ¼ãƒ«ã‚’é€ã£ã¦ãã ã•ã„。ãŸã ã—ã€è³ªå•ã‚„ãƒã‚°ãƒ¬ãƒãƒ¼ãƒˆãªã©ã€ä»–ã®ãƒ¦ãƒ¼ã‚¶ã¨å…±æœ‰ã§ãる話題ã¯ãƒ¡ãƒ¼ãƒªãƒ³ã‚°ãƒªã‚¹ãƒˆã«é€ã£ã¦ãã ã•ã„。メーリングリストã®å‚加方法ã«ã¤ã„ã¦ã¯ã€`http://lists.sourceforge.net/lists/listinfo/qdbm-users' ã‚’å‚ç…§ã—ã¦ãã ã•ã„。

+ +

SourceForge.netã«ãŠã‘るプロジェクトページ㯠`http://sourceforge.net/projects/qdbm/' ã«ã‚ã‚Šã¾ã™ã€‚Freshmeatã«ãŠã‘る更新情報㯠`http://freshmeat.net/projects/qdbm/' ã‹ã‚‰å‚ç…§ã§ãã¾ã™ã€‚

+ +
+ + + + + + diff --git a/qdbm/misc/logo.png b/qdbm/misc/logo.png new file mode 100644 index 00000000..d5cf9771 Binary files /dev/null and b/qdbm/misc/logo.png differ diff --git a/qdbm/misc/makevcdef b/qdbm/misc/makevcdef new file mode 100755 index 00000000..7b36e307 --- /dev/null +++ b/qdbm/misc/makevcdef @@ -0,0 +1,48 @@ +#! /bin/sh + +#================================================================ +# makevcdef +# Generator of module definition file for Visual C++ +#================================================================ + + +# check arguments +file="$1" +if [ -f "$file" ] +then + true +else + printf 'usage: makevcdef library\n' 1>&2 + exit 1 +fi + + +# show headers +name=`echo $file | sed -e 's/^lib//' -e 's/\..*//'` +printf 'EXPORTS\r\n' + + +# show variables +nm -g "$file" | grep ' [BDR] ' | sed 's/.* [BDR] //' | grep -v '^_' | sort | uniq | +while read name +do + num=$((num + 1)) + printf ' %s = %s DATA\r\n' "$name" "$name" +done + + +# show functions +nm -g "$file" | grep ' T ' | sed 's/.* T //' | grep -v '^_' | sort | uniq | +while read name +do + num=$((num + 1)) + printf ' %s = %s\r\n' "$name" "$name" +done + + +# exit normally +exit 0 + + + +# END OF FILE diff --git a/qdbm/misc/mymemo-ja.html b/qdbm/misc/mymemo-ja.html new file mode 100644 index 00000000..87de7843 --- /dev/null +++ b/qdbm/misc/mymemo-ja.html @@ -0,0 +1,34 @@ + + + + + + + + + + +My Private Memo for QDBM + + + + +

QDBMã®ãŸã‚ã®ç§çš„メモ

+ +
+ +

cygwin+mingwã§ã®ãƒ“ルド環境ã®è¨­å®šæ–¹æ³•

+ +
    +
  • Cygwinã®ã‚»ãƒƒãƒˆã‚¢ãƒƒãƒ—時ã«ã€mingwã®gccã¨mingwã®zlibã‚‚é¸æŠžã™ã‚‹ã€‚
  • +
  • mingwã®libiconvã¯mingwã®ã‚µã‚¤ãƒˆã‹ã‚‰æ‰‹ã«å…¥ã‚Œã‚‹ã€‚ãã—ã¦ã€*.h 㯠/usr/include/mingw ã®ä¸‹ã«ã€*.dll.a 㯠/lib/mingw ã®ä¸‹ã«ã€*.dll 㯠/binã®ä¸‹ã«ç§»å‹•ã•ã›ã‚‹ã€‚
  • +
  • QDBMã®ãƒ“ルド環境ã®è¨­å®šã¯ ./configure --enable-zlib --enable-iconv ã§è¡Œã„ã€ãƒ‘ッケージã®ä½œæˆã¯ make win32pkg ã§è¡Œã†ã€‚
  • +
+ +
+ + + + + + diff --git a/qdbm/misc/tutorial-ja.html b/qdbm/misc/tutorial-ja.html new file mode 100644 index 00000000..66f1c3c3 --- /dev/null +++ b/qdbm/misc/tutorial-ja.html @@ -0,0 +1,622 @@ + + + + + + + + + + + + + + +Tutorial of QDBM Version 1 (Japanese) + + + + + +

QDBMã®ãƒãƒ¥ãƒ¼ãƒˆãƒªã‚¢ãƒ«

+ +
Copyright (C) 2000-2007 Mikio Hirabayashi
+
Last Update: Thu, 26 Oct 2006 15:00:20 +0900
+ + +
+ +

目次

+ +
    +
  1. イントロダクション
  2. +
  3. Depot: 基本API
  4. +
  5. Curia: æ‹¡å¼µAPI
  6. +
  7. Relic: NDBM互æ›API
  8. +
  9. Hovel: GDBM互æ›API
  10. +
  11. Cabin: ユーティリティAPI
  12. +
  13. Villa: 上級API
  14. +
  15. Odeum: 転置API
  16. +
+ +
+ +

イントロダクション

+ +

QDBMã¯ã€ã‚·ãƒ³ãƒ—ルãªãŒã‚‰ä¾¿åˆ©ãªãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ©ã‚¤ãƒ–ラリã§ã™ã€‚データベースã¨ã„ã†ã¨SQLやリレーショナルデータベースをæ€ã„æµ®ã‹ã¹ã‚‹äººãŒå¤šã„ã¨æ€ã„ã¾ã™ãŒã€QDBMã¯ãã‚“ãªé«˜æ©Ÿèƒ½ãªã‚‚ã®ã§ã¯ã‚ã‚Šã¾ã›ã‚“。「キーã€ã¨ã€Œå€¤ã€ã®çµ„ã‹ã‚‰ãªã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’ファイルã«ä¿å­˜ã—ãŸã‚Šã€ä¿å­˜ã—ã¦ãŠã„ãŸãƒ¬ã‚³ãƒ¼ãƒ‰ã®ä¸­ã‹ã‚‰ç‰¹å®šã®ã‚­ãƒ¼ã‚’æŒã¤ã‚‚ã®ã‚’å–り出ã™æ©Ÿèƒ½ã‚’æä¾›ã™ã‚‹ã ã‘ã§ã™ã€‚ãã®ã‚ˆã†ãªæ©Ÿèƒ½ã‚’ã“ã“ã§ã¯ã€Œãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã€ã¨å‘¼ã¶ã“ã¨ã«ã—ã¾ã™ã€‚ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ç‰¹é•·ã¯ã€ä½¿ã„æ–¹ãŒç°¡å˜ã§ã€ãƒ‘フォーマンスãŒé«˜ã„ã“ã¨ã§ã™ã€‚

+ +

QDBMã¯C言語ã®ãƒ©ã‚¤ãƒ–ラリã§ã™ï¼ˆä»–ã®è¨€èªžã®APIã‚‚ã‚ã‚Šã¾ã™ãŒï¼‰ã€‚QDBMã«ã¯ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ©Ÿèƒ½ã ã‘ã§ãªãã€ç§ï¼ˆQDBMã®ä½œè€…)ãŒãƒ—ログラミングをã™ã‚‹æ™‚ã«ã‚ˆã使ã†æ©Ÿèƒ½ãŒè©°ã‚è¾¼ã¾ã‚Œã¦ã„ã¾ã™ã€‚Cã§æ›¸ã„ãŸãƒ—ログラムã¯é«˜é€Ÿã«å‹•ä½œã™ã‚‹ã®ãŒåˆ©ç‚¹ã§ã™ãŒã€C++ã€Javaã€Perlã€Rubyã¨ã„ã£ãŸæ¯”較的高級ãªè¨€èªžã§ã¯æ¨™æº–çš„ã«ã‚µãƒãƒ¼ãƒˆã•ã‚Œã‚‹ãƒ‡ãƒ¼ã‚¿æ§‹é€ ã‚„アルゴリズムを自分ã§å®Ÿè£…ã—ãªã‘ã‚Œã°ãªã‚Šã¾ã›ã‚“。ãã†ã„ã£ãŸä½œæ¥­ã¯é¢å€’ã§ã™ã—ã€ãƒã‚°ã‚’生ã¿ã‚„ã™ã„ã‚‚ã®ã§ã™ã€‚ãã“ã§ã€QDBMã®ç™»å ´ã§ã™ã€‚QDBMã‚’å†åˆ©ç”¨ã™ã‚Œã°ã€Cã§ã®ãƒ—ログラミングãŒPerlを使ã£ã¦ã„ã‚‹ã‹ã®ã‚ˆã†ã«æ‰‹è»½ã«ãªã‚Šã¾ã™ã€‚ã—ã‹ã‚‚ã€UNIXã§ã‚‚Windowsã§ã‚‚Mac OS Xã§ã‚‚利用ã§ãã‚‹ã®ã§ã€ç§»æ¤æ€§ã®ã‚るプログラムãŒæ›¸ãã‚„ã™ããªã‚Šã¾ã™ã€‚

+ +

シンプルã¨ã„ã„ãªãŒã‚‰ã€QDBMã®æ©Ÿèƒ½ã¯ãªã‹ãªã‹è±Šå¯Œã§ã™ã€‚データベースã¨ã—ã¦ã¯ã€ãƒãƒƒã‚·ãƒ¥è¡¨ã¨B+木ãŒåˆ©ç”¨ã§ãã¾ã™ã€‚メモリ上ã§æ‰±ã†ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£ã¨ã—ã¦ã¯ã€ãƒªã‚¹ãƒˆã‚„マップãªã©ãŒã‚ã‚Šã¾ã™ã€‚MIMEã‚„CSVã‚„XMLã®è§£æžã‚‚ã§ãã¾ã™ã€‚ã—ã¾ã„ã«ã¯å…¨æ–‡æ¤œç´¢ã¾ã§ã§ããŸã‚Šã™ã‚‹ã®ã§é©šãã§ã™ã€‚

+ +

ã“ã®ãƒãƒ¥ãƒ¼ãƒˆãƒªã‚¢ãƒ«ã§ã¯QDBMã®ä½¿ã„方を簡å˜ã«èª¬æ˜Žã™ã‚‹ã¨ã¨ã‚‚ã«ã€åŸºæœ¬ä»•æ§˜æ›¸ã®è£œè¶³ã‚’è¿°ã¹ã¾ã™ã€‚QDBMã®è©³ç´°ã«ã¤ã„ã¦ã¯åŸºæœ¬ä»•æ§˜æ›¸ã‚’御覧ãã ã•ã„。ãªãŠã€ã“ã“ã§ã¯ãƒãƒƒã‚·ãƒ¥è¡¨ã‚„B+木ã¨ã„ã£ãŸãƒ‡ãƒ¼ã‚¿æ§‹é€ ã®èª¬æ˜Žã¯ã—ã¾ã›ã‚“ã®ã§ã€ä¸æ…£ã‚Œãªæ–¹ã¯é©å½“ãªæœ¬ã‚„Webサイトã§èª¿ã¹ã¦ãŠã„ã¦ãã ã•ã„。

+ +
+ +

Depot: 基本API

+ +

データベースアプリケーションã®å…¸åž‹çš„ãªä¾‹ã¨ã—ã¦ã€ã€Œç¤¾å“¡ç•ªå·ã‚’入力ã™ã‚‹ã¨ã€ãã®å†…線番å·ãŒã‚ã‹ã‚‹ã€ã¨ã„ã†ãƒ—ログラムを考ãˆã¦ã¿ã¾ã—ょã†ã€‚社員番å·ã‚’キーã¨ã—ã¦ã€ãã‚Œã«å¯¾å¿œã™ã‚‹å€¤ã§ã‚る内線番å·ã‚’検索ã™ã‚‹ã¨ã„ã†ã“ã¨ã§ã™ã€‚

+ +

ã¾ãšã¯QDBMを使ã‚ãªã„ã§ã‚„ã£ã¦ã¿ã¾ã™ã€‚社員番å·ã¨å†…線番å·ã®å¯¾å¿œè¡¨ã¯ã€CSVテキストã§ãƒ•ã‚¡ã‚¤ãƒ«ã«ä¿å­˜ã™ã‚‹ã“ã¨ã«ã—ã¾ã™ã€‚書å¼ã®ä¾‹ã‚’以下ã«ç¤ºã—ã¾ã™ã€‚

+ +
00001,8-902-1234
+00002,7-938-834
+00008,4-214-491
+
+ +

レコードを加ãˆã‚‹é–¢æ•° `putphonenumber' ã¨ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã™ã‚‹é–¢æ•° `getphonenumber' を実装ã—ã¾ã™ã€‚

+ +
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define PHONEFILE    "phone"
+#define LINEBUFSIZ   256
+
+int putphonenumber(const char *id, const char *phone){
+  FILE *OUT;
+  /* ファイルを追記モードã§é–‹ã */
+  if(!(OUT = fopen(PHONEFILE, "a"))) return -1;
+  /* レコードを書ã込む */
+  fprintf(OUT, "%s,%s\n", id, phone);
+  /* ファイルを閉ã˜ã‚‹ */
+  if(fclose(OUT) != 0) return -1;
+  return 0;
+}
+
+char *getphonenumber(const char *id){
+  FILE *IN;
+  char line[LINEBUFSIZ], *pivot, *phone;
+  int len;
+  /* ファイルを読ã¿è¾¼ã¿ãƒ¢ãƒ¼ãƒ‰ã§é–‹ã */
+  if(!(IN = fopen(PHONEFILE, "r"))) return NULL;
+  /* å„行を読ã¿è¾¼ã‚€ */
+  while(fscanf(IN, "%s", line) == 1){
+    /* 区切り文字を処ç†ã™ã‚‹ */
+    if(!(pivot = strchr(line, ','))) continue;
+    *pivot = '\0';
+    pivot++;
+    /* キーã®ä¸€è‡´åˆ¤å®š */
+    if(strcmp(line, id) == 0){
+      /* ファイルを閉ã˜ã‚‹ */
+      if(fclose(IN) != 0) return NULL;
+      /* メモリを確ä¿ã—ã¦æˆ»ã‚Šå€¤ã‚’生æˆã™ã‚‹ */
+      len = strlen(pivot);
+      if(!(phone = malloc(len + 1))) return NULL;
+      memcpy(phone, pivot, len + 1);
+      return phone;
+    }
+  }
+  /* ファイルを閉ã˜ã‚‹ */
+  fclose(IN);
+  return NULL;
+}
+
+ +

`fscanf' を使ã£ã¦ã„る時点ã§ã‹ãªã‚Šè²§å¼±ã§ã™ãŒã€ãã¡ã‚“ã¨æ›¸ã“ã†ã¨ã™ã‚‹ã¨éžå¸¸ã«é•·ããªã‚‹ã®ã§å¦¥å”ã—ã¾ã—ãŸï¼ˆã¡ãªã¿ã«ã€255文字を越ãˆã‚‹è¡ŒãŒã‚ã£ãŸã‚‰æš´èµ°ã—ã¾ã™ï¼‰ã€‚ã¨ã«ã‹ãã€ã“ã®ç¨‹åº¦ã®å‡¦ç†ã§ã‚„ãŸã‚‰é•·ã„コードを書ã‹ã­ã°ãªã‚‰ãªã„ã®ã§ã¯æ‚²ã—ããªã‚Šã¾ã™ã€‚ã•ã‚‰ã«é‡å¤§ãªæ¬ ç‚¹ã¯ã€æ¤œç´¢ã®å‡¦ç†ãŒé…ã„ã¨ã„ã†ã“ã¨ã§ã™ã€‚ファイルã®æœ€åˆã‹ã‚‰æœ€å¾Œã¾ã§ï¼ˆå¹³å‡çš„ã«ã¯åŠåˆ†ã¾ã§ï¼‰èª­ã¾ãªã‘ã‚Œã°ãªã‚‰ãªã„ã‹ã‚‰ã§ã™ã€‚既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’修正ã™ã‚‹æ™‚ã«ã‚‚ã‹ãªã‚Šé¢å€’ãªã“ã¨ã‚’ã—ãªã‘ã‚Œã°ãªã‚Šã¾ã›ã‚“。

+ +

QDBMを使ãˆã°ã‚‚ã£ã¨ã‚¨ãƒ¬ã‚¬ãƒ³ãƒˆãªã‚³ãƒ¼ãƒ‰ãŒæ›¸ã‘ã¾ã™ã€‚上記ã¨åŒã˜æ©Ÿèƒ½ã®é–¢æ•°ã‚’実装ã—ã¦ã¿ã¾ã™ã€‚

+ +
#include <depot.h>
+#include <stdlib.h>
+
+#define PHONEFILE    "phone"
+
+int putphonenumber(const char *id, const char *phone){
+  DEPOT *depot;
+  /* データベースを追記モードã§é–‹ã */
+  if(!(depot = dpopen(PHONEFILE, DP_OWRITER | DP_OCREAT, -1))) return -1;
+  /* レコードを書ã込む */
+  dpput(depot, id, -1, phone, -1, DP_DOVER);
+  /* データベースを閉ã˜ã‚‹ */
+  if(!dpclose(depot)) return -1;
+  return 0;
+}
+
+char *getphonenumber(const char *id){
+  DEPOT *depot;
+  char *phone;
+  /* データベースを読ã¿è¾¼ã¿ãƒ¢ãƒ¼ãƒ‰ã§é–‹ã */
+  if(!(depot = dpopen(PHONEFILE, DP_OREADER, -1))) return NULL;
+  /* レコードを探索ã—ã¦æˆ»ã‚Šå€¤ã‚’生æˆã™ã‚‹ */
+  phone = dpget(depot, id, -1, 0, -1, NULL);
+  /* データベースを閉ã˜ã‚‹ */
+  dpclose(depot);
+  return phone;
+}
+
+ +

ã‚‚ã¯ã‚„ファイル形å¼ã¯CSVファイルã§ã¯ãªãã€åŒºåˆ‡ã‚Šæ–‡å­—ãŒä½•ã§ã‚ã‚‹ã‹æ°—ã«ã™ã‚‹å¿…è¦ã¯ã‚ã‚Šã¾ã›ã‚“。プログラマã¯ãƒ•ã‚¡ã‚¤ãƒ«å½¢å¼ãŒã©ã†ã§ã‚ã‚‹ã‹ãªã©è€ƒãˆãªãã¦ã‚‚よã„ã®ã§ã™ã€‚メモリã®ç¢ºä¿ãªã©ã‚‚QDBMã®å†…部ã§ã‚„ã£ã¦ãれるã®ã§ã€ãƒãƒƒãƒ•ã‚¡ã®ã‚µã‚¤ã‚ºã‚’æ°—ã«ã™ã‚‹å¿…è¦ã¯ã‚ã‚Šã¾ã›ã‚“(解放ã¯å¿…è¦ã§ã™ï¼‰ã€‚処ç†é€Ÿåº¦ã‚’æ°—ã«ã™ã‚‹å¿…è¦ã‚‚ã‚ã‚Šã¾ã›ã‚“。データベースãŒã©ã‚“ãªã«å¤§ããã¦ã‚‚ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®è¿½åŠ ã‚„削除や検索ãŒä¸€çž¬ã§ã§ãã¾ã™ã€‚ã“ã®ã‚ˆã†ã«ã€ãƒ—ログラマをデータ管ç†ã®è‹¦æ‚©ã‹ã‚‰è§£æ”¾ã™ã‚‹ã®ãŒQDBMã®å½¹å‰²ã§ã™ã€‚

+ +

上記ã®ä¾‹ã§ã¯QDBMã®åŸºæœ¬APIã§ã‚ã‚‹Depotを利用ã—ã¦ã„ã¾ã™ã€‚ã¾ãšã€`DEPOT' ã¨ã„ã†åž‹ãŒç™»å ´ã—ã¦ã„ã¾ã™ã€‚ã“ã‚Œã¯æ¨™æº–ライブラリ㮠`FILE' ã¨åŒæ§˜ã«ã€æ“作対象ã®ãƒ•ã‚¡ã‚¤ãƒ«ã®æƒ…報を格ç´ã—ã¦ã„る構造体ã®åž‹ã§ã™ã€‚ã“ã®åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦å„種ã®é–¢æ•°ã«æ¸¡ã™ã“ã¨ã«ãªã‚Šã¾ã™ã€‚関数ã¨ã—ã¦ã¯ã€`dpopen'ã€`dpclose'ã€`dpput' ãŠã‚ˆã³ `dpget' ãŒç™»å ´ã—ã¦ã„ã¾ã™ã€‚ã“ã®å››ã¤ã®ä½¿ã„方を覚ãˆã‚Œã°QDBMã®åŠåˆ†ã¯ç†è§£ã—ãŸã‚ˆã†ãªã‚‚ã®ã§ã™ã€‚

+ +
DEPOT *dpopen(const char *name, int omode, int bnum);
+ +

`dpopen' ã¯ãã®åã®é€šã‚Šã€Depotã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã関数ã§ã™ã€‚ãã®çµæžœã¨ã—㦠`DEPOT' åž‹ã®æ§‹é€ ä½“ã¸ã®ãƒã‚¤ãƒ³ã‚¿ãŒè¿”ã•ã‚Œã¾ã™ã€‚第1引数ã«ã¯ãƒ‡ãƒ¼ã‚¿ã‚’æ ¼ç´ã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«åを指定ã—ã¾ã™ã€‚ã“ã‚Œã¯ç›¸å¯¾ãƒ‘スã§æŒ‡å®šã—ã¦ã‚‚絶対パスã§æŒ‡å®šã—ã¦ã‚‚構ã„ã¾ã›ã‚“。第2引数ã¯æŽ¥ç¶šãƒ¢ãƒ¼ãƒ‰ã‚’指定ã—ã¾ã™ã€‚読ã¿è¾¼ã¿ã¨æ›¸ãè¾¼ã¿ã®ä¸¡æ–¹ã‚’ã™ã‚‹ãªã‚‰ `DP_OWRITER' を指定ã—ã¾ã™ã€‚ãŸã ã—ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ãŒå­˜åœ¨ã—ãªã„å ´åˆã«æ–°è¦ä½œæˆã™ã‚‹ãªã‚‰ã°åŒæ™‚ã« `DP_OCREAT' をビットORã¨ã—ã¦åŠ ãˆã‚‹å¿…è¦ãŒã‚ã‚Šã¾ã™ã€‚ã“ã®äºŒã¤ã‚’指定ã™ã‚‹ã¨ã€`fopen' ã® `a+' モードã¨ã»ã¼åŒã˜æ„味ã«ãªã‚Šã¾ã™ã€‚ä»–ã« `DP_OTRUNC' ã¨ã„ã†ãƒ•ãƒ©ã‚°ãŒã‚ã‚‹ã®ã§ã™ãŒã€ãã‚Œã¯ãƒ•ã‚¡ã‚¤ãƒ«ã‚’切り詰ã‚ã‚‹ã“ã¨ã‚’指示ã—ã¾ã™ã€‚ãれも加ãˆã¦ä¸‰ã¤ã‚’指定ã™ã‚‹ã¨ `fopen' ã® `w+' モードã¨ã»ã¼åŒã˜æ„味ã«ãªã‚Šã¾ã™ã€‚読ã¿è¾¼ã¿ã ã‘ã‚’ã™ã‚‹å ´åˆã€`DP_OREADER' を指定ã—ã¾ã™ã€‚ã“れ㯠`fopen' ã® `r' モードã¨ã»ã¼åŒã˜æ„味ã§ã™ã€‚第3引数ã¯ãƒãƒƒã‚·ãƒ¥è¡¨ã®ãƒã‚±ãƒƒãƒˆæ•°ã‚’指定ã—ã¾ã™ã€‚ã¨ã‚Šã‚ãˆãšãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ã‚’æ„味ã™ã‚‹ `-1' を指定ã—ã¦ãŠã‘ã°ã„ã„ã§ã—ょã†ã€‚

+ +

複数ã®ãƒ—ロセスãŒåŒã˜ãƒ•ã‚¡ã‚¤ãƒ«ã‚’読ã¿æ›¸ãã™ã‚‹å ´åˆã€ã€Œãƒ¬ãƒ¼ã‚¹ã‚³ãƒ³ãƒ‡ã‚£ã‚·ãƒ§ãƒ³ã€ã¨ã„ã†å•é¡ŒãŒèµ·ã“ã‚Šã¾ã™ã€‚åŒæ™‚ã«ãƒ•ã‚¡ã‚¤ãƒ«ã«æ›¸ã込むã¨ã€å†…容ãŒæ··ã–ã£ã¦å¤‰ã«ãªã£ã¦ã—ã¾ã†å¯èƒ½æ€§ãŒã‚ã‚‹ã®ã§ã™ã€‚QDBMã§ã¯ãã‚Œã«å¯¾å‡¦ã™ã‚‹ãŸã‚ã«ã€Œãƒ•ã‚¡ã‚¤ãƒ«ãƒ­ãƒƒã‚¯ã€ã‚’ã‹ã‘ã¾ã™ã€‚ã‚るプロセスãŒãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’書ãè¾¼ã¿ãƒ¢ãƒ¼ãƒ‰ã§é–‹ã„ã¦ã„ã‚‹å ´åˆã¯ã€ä»–ã®ãƒ—ロセスãŒãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã“ã†ã¨ã—ã¦ã‚‚ブロックã•ã‚Œã‚‹ã®ã§ã™ã€‚処ç†ãŒå¤±æ•—ã™ã‚‹ã‚ã‘ã§ã¯ãªãã€æ—¢ã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã„ã¦ã„るプロセスãŒãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‰ã˜ã‚‹ã¾ã§å¾…ã£ã¦ãれるã®ã§ã™ã€‚ãªãŠã€èª­ã¿è¾¼ã¿ãƒ¢ãƒ¼ãƒ‰åŒå£«ã§ã‚ã‚Œã°ãƒ¬ãƒ¼ã‚¹ã‚³ãƒ³ãƒ‡ã‚£ã‚·ãƒ§ãƒ³ã¯èµ·ã“らãªã„ã®ã§åŒæ™‚ã«ã‚¢ã‚¯ã‚»ã‚¹ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚

+ +
int dpclose(DEPOT *depot);
+ +

`dpclose' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‰ã˜ã‚‹é–¢æ•°ã§ã™ã€‚第1引数ã«ã¯ `dpopen' ã§é–‹ã„ãŸãƒãƒ³ãƒ‰ãƒ«ã‚’渡ã—ã¾ã™ã€‚é–‹ã„ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¯å¿…ãšé–‰ã˜ã¦ãã ã•ã„。ãã†ã—ãªã„ã¨ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãŒå£Šã‚Œã¾ã™ï¼ˆèª­ã¿è¾¼ã¿ãƒ¢ãƒ¼ãƒ‰ã®å ´åˆã¯å£Šã‚Œã¾ã›ã‚“ãŒã€ãƒ¡ãƒ¢ãƒªãƒªãƒ¼ã‚¯ã«ãªã‚Šã¾ã™ï¼‰ã€‚

+ +

ã¨ã“ã‚ã§ã€QDBMを使ã‚ãªã„例ã§ã¯ã€æ›¸ãè¾¼ã¿ã®éš›ã«å‘¼ã³å‡ºã™ `fprintf' ã®æˆ»ã‚Šå€¤ã‚’ãƒã‚§ãƒƒã‚¯ã—ã¦ã„ã¾ã›ã‚“。`fprintf' ãŒå¤±æ•—ã—ãŸå ´åˆã¯ `fclose' もエラーを返ã™ã¨è¦å®šã•ã‚Œã¦ã„ã‚‹ã‹ã‚‰ã§ã™ã€‚åŒæ§˜ã«ã€QDBMã§ã‚‚データベースã«ä¸€åº¦ã§ã‚‚致命的ãªã‚¨ãƒ©ãƒ¼ãŒèµ·ããŸå ´åˆã¯ `dpclose' ãŒã‚¨ãƒ©ãƒ¼ã‚’è¿”ã™ã®ã§ã€ã‚¨ãƒ©ãƒ¼ãƒã‚§ãƒƒã‚¯ã‚’簡略化ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ã®ã§ã™ã€‚

+ +
int dpput(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
+ +

`dpput' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã™ã‚‹é–¢æ•°ã§ã™ã€‚第1引数ã«ã¯ `dpopen' ã§é–‹ã„ãŸãƒãƒ³ãƒ‰ãƒ«ã‚’渡ã—ã¾ã™ã€‚第2引数ã«ã¯ã€æ›¸ã込むレコードã®ã‚­ãƒ¼ã®å†…容をä¿æŒã™ã‚‹é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã—ã¾ã™ã€‚第3引数ã«ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã—ã¾ã™ã€‚ãã‚ŒãŒè² æ•°ã®å ´åˆã¯ã€ç¬¬2引数を文字列ã¨ã—ã¦æ‰±ã£ã¦ã€`strlen' ã®å€¤ã‚’サイズã¨ã—ã¦åˆ¤å®šã—ã¾ã™ï¼ˆæ–‡å­—列ã¨ãƒã‚¤ãƒŠãƒªã®ä¸¡æ–¹ã‚’ç°¡å˜ã«æ‰±ãˆã‚‹ã‚ˆã†ã«ã™ã‚‹ãŸã‚ã§ã™ï¼‰ã€‚第4引数ã¨ç¬¬5引数ã¯ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã«é–¢ã—ã¦åŒæ§˜ã«ãƒã‚¤ãƒ³ã‚¿ã¨ã‚µã‚¤ã‚ºã‚’指定ã—ã¾ã™ã€‚第6引数ã¯æ›¸ãè¾¼ã¿ã®ãƒ¢ãƒ¼ãƒ‰ã§ã™ã€‚データベース内ã«ã¯åŒã˜ã‚­ãƒ¼ã‚’æŒã¤è¤‡æ•°ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã™ã‚‹ã“ã¨ãŒã§ããªã„ã®ã§ã€æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã¨åŒä¸€ã®ã‚­ãƒ¼ã‚’æŒã¤ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã—よã†ã¨ã—ãŸéš›ã«ã©ã†ã™ã‚‹ã‹ã‚’指示ã™ã‚‹å¿…è¦ãŒã‚ã‚Šã¾ã™ã€‚`DP_DOVER' ã¨ã—ãŸå ´åˆã¯ã€æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ–°ã—ã„レコードã§ä¸Šæ›¸ãã—ã¾ã™ã€‚`DP_DKEEP' ã¨ã—ãŸå ´åˆã¯ã€æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’優先ã—ã€ã‚¨ãƒ©ãƒ¼ãŒè¿”ã•ã‚Œã¾ã™ï¼ˆ`DP_EKEEP' ã¨ã„ã†ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ãŒå¤–部変数 `dpecode' ã«è¨­å®šã•ã‚Œã¾ã™ï¼‰ã€‚

+ +

`dpput' ã®æ›¸ãè¾¼ã¿ãƒ¢ãƒ¼ãƒ‰ã«ã¯ã€`DP_DCAT' ã«ã‚ˆã‚‹ã€Œé€£çµãƒ¢ãƒ¼ãƒ‰ã€ã‚‚ã‚ã‚Šã¾ã™ã€‚ã“れを利用ã™ã‚‹ã“ã¨ã¯ã‚ã¾ã‚Šãªã„ã‹ã‚‚ã—ã‚Œã¾ã›ã‚“ãŒã€ä»–ã®DBMã«ã¯ãªã„特徴ãªã®ã§èª¬æ˜Žã—ã¾ã™ã€‚連çµãƒ¢ãƒ¼ãƒ‰ã¯ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã¨ã—ã¦é…列を入れる際ã«ä¾¿åˆ©ãªã®ã§ã™ã€‚例ãˆã°ã€[10,11,12] ã¨ã„ã†ä¸‰ã¤ã®æ•°å€¤ã‚’è¦ç´ ã«æŒã¤é…列を格ç´ã—ã¦ã„ã¦ã€ãれを [10,11,12,13] ã«ã—ãŸã„å ´åˆã‚’考ãˆã¦ã¿ã¾ã™ã€‚ä»–ã®DBMã§ã¯ã€ã¾ãšãã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã—ã¦ã€[10,11,12] ã‚’ç²å¾—ã—ã¦ã‹ã‚‰ã€ãれを [10,11,12,13] ã«åŠ å·¥ã—ã¦å€¤ã‚’生æˆã—ã€å…ƒã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ä¸Šæ›¸ãã§æ›¸ã込むã¨ã„ã£ãŸã“ã¨ã‚’ã—ãªã‘ã‚Œã°ãªã‚Šã¾ã›ã‚“。QDBMã®å ´åˆã¯ã€é€£çµãƒ¢ãƒ¼ãƒ‰ã§ [13] を既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«æ›¸ã込むã ã‘ã§åŒã˜ã“ã¨ãŒã§ãã¾ã™ã€‚é…列ã®è¦ç´ æ•°ãŒå¤§ãã„å ´åˆã«ã¯ã“ã®é•ã„ã¯ãƒ‘フォーマンスã«å¤§ããªå½±éŸ¿ã‚’åŠã¼ã—ã¾ã™ã€‚

+ +
char *dpget(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, int *sp);
+ +

`dpget' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’検索ã—ã¦ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å–り出ã™é–¢æ•°ã§ã™ã€‚第1引数ã¯ä»–ã¨ä¸€ç·’ã§ã™ã­ã€‚第2引数ã¨ç¬¬3引数㯠`dpput' ã¨åŒæ§˜ã«æ¤œç´¢ã‚­ãƒ¼ã®ãƒã‚¤ãƒ³ã‚¿ã¨ã‚µã‚¤ã‚ºã‚’指定ã—ã¾ã™ã€‚第4引数ã¨ç¬¬5引数ã¯ã¨ã‚Šã‚ãˆãš `0' 㨠'-1' ã«ã™ã‚‹ã‚‚ã®ã ã¨æ€ã£ã¦ã„ãŸã ã„ã¦çµæ§‹ã§ã™ã€‚一応説明ã™ã‚‹ã¨ã€å–り出ã™é ˜åŸŸã®é–‹å§‹ã‚ªãƒ•ã‚»ãƒƒãƒˆã¨æœ€å¤§ã‚µã‚¤ã‚ºã‚’指定ã—ã¾ã™ã€‚`-1' ã¯ç„¡åˆ¶é™ã¨ã„ã†æ„味ã§ã™ã€‚例ãˆã°ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ãŒ `abcdef' ã®å ´åˆã«é–‹å§‹ã‚ªãƒ•ã‚»ãƒƒãƒˆã‚’ `1'ã€ã‚µã‚¤ã‚ºã‚’ `3' ã«ã—ãŸå ´åˆã€`bcd' ãŒå–り出ã•ã‚Œã¾ã™ã€‚戻り値ã¯å–り出ã—ãŸå€¤ã®å†…容を記録ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã™ã€‚ãã®é ˜åŸŸã¯ `malloc' ã§ãƒ’ープã«ç¢ºä¿ã•ã‚Œã¦ã„ã‚‹ã®ã§ã€ã‚¢ãƒ—リケーションã®è²¬ä»»ã§ `free' ã«æ¸¡ã—ã¦è§£æ”¾ã™ã‚‹å¿…è¦ãŒã‚ã‚Šã¾ã™ã€‚戻り値ã®é ˜åŸŸã¯çµ‚端ã«ã‚¼ãƒ­ã‚³ãƒ¼ãƒ‰ãŒä»˜åŠ ã•ã‚Œã¦ã„ã‚‹ã“ã¨ãŒä¿è¨¼ã•ã‚Œã¦ã„ã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãã¾ã™ã€‚ãŸã ã—ã€ãƒã‚¤ãƒŠãƒªã‚’扱ã†å ´åˆã«ã¯æ˜Žç¤ºçš„ã«ã‚µã‚¤ã‚ºãŒçŸ¥ã‚ŠãŸã„ã§ã—ょã†ã‹ã‚‰ã€ãã®ç‚ºã«ç¬¬6引数ã«ã‚µã‚¤ã‚ºã‚’å—ã‘å–る変数ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ï¼ˆã“ã®ã‚µã‚¤ã‚ºã«ã¯çµ‚端ã®ã‚¼ãƒ­ã‚³ãƒ¼ãƒ‰ã¯å‹˜å®šã•ã‚Œã¾ã›ã‚“)。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã«ã¯ `NULL' ãŒè¿”ã•ã‚Œã¾ã™ï¼ˆ`DP_ENOITEM' ã¨ã„ã†ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ãŒå¤–部変数 `dpecode' ã«è¨­å®šã•ã‚Œã¾ã™ï¼‰ã€‚

+ +

Depotã®é–¢æ•°ã§ä»–ã«ã‚ˆã使ã†ã‚‚ã®ã¨ã—ã¦ã€`dpout'ã€`dpiterinit'ã€`dpiternext' ãŒã‚ã‚Šã¾ã™ã€‚ã“れらã«ã¤ã„ã¦ã‚‚説明ã—ã¦ãŠãã¾ã™ã€‚

+ +
int dpout(DEPOT *depot, const char *kbuf, int ksiz);
+ +

`dpout' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‹ã‚‰ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã™ã‚‹é–¢æ•°ã§ã™ã€‚三ã¤ã®å¼•æ•°ã®æ‰±ã„㯠`dpget' ã®ã‚‚ã®ã¨åŒã˜ã§ã™ã€‚該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã¯ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã—ã¾ã™ï¼ˆ`DP_ENOITEM' ã¨ã„ã†ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ãŒå¤–部変数 `dpecode' ã«è¨­å®šã•ã‚Œã¾ã™ï¼‰ã€‚

+ +

`dpiterinit' 㨠`dpiternext' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ä¸­ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’一ã¤ä¸€ã¤è¦‹ã¦ã„ãå ´åˆã«ä½¿ã„ã¾ã™ã€‚先程ã®å†…線番å·ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å…¨ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’表示ã™ã‚‹é–¢æ•°ã®ä¾‹ã‚’以下ã«ç¤ºã—ã¾ã™ã€‚

+ +
#include <depot.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define PHONEFILE    "phone"
+
+int printphonenumbers(void){
+  DEPOT *depot;
+  char *kbuf, *vbuf;
+  /* データベースを読ã¿è¾¼ã¿ãƒ¢ãƒ¼ãƒ‰ã§é–‹ã */
+  if(!(depot = dpopen(PHONEFILE, DP_OREADER, -1))) return -1;
+  /* イテレータをåˆæœŸåŒ–ã™ã‚‹ */
+  dpiterinit(depot);
+  /* å„レコードã®ã‚­ãƒ¼ã‚’å–り出㙠*/
+  while((kbuf = dpiternext(depot, NULL)) != NULL){
+    /* å„レコードã®å€¤ã‚’å–り出㙠*/
+    if((vbuf = dpget(depot, kbuf, -1, 0, -1, NULL)) != NULL){
+      printf("%s: %s\n", kbuf, vbuf);
+      /* 値ã®é ˜åŸŸã‚’解放ã™ã‚‹ */
+      free(vbuf);
+    }
+    /* キーã®é ˜åŸŸã‚’解放ã™ã‚‹ */
+    free(kbuf);
+  }
+  /* データベースを閉ã˜ã‚‹ */
+  return dpclose(depot) ? 0 : -1;
+}
+
+ +

å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’横断的ã«è¦‹ã¦ã„ãã“ã¨ã‚’「トラãƒãƒ¼ã‚µãƒ«ã‚¢ã‚¯ã‚»ã‚¹ã€ã¨å‘¼ã¶ã“ã¨ã«ã—ã¾ã™ã€‚トラãƒãƒ¼ã‚µãƒ«ã‚¢ã‚¯ã‚»ã‚¹ã®éš›ã«ã¯ã€ã€Œã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã€ã‚’利用ã—ã¾ã™ã€‚イテレータã¯é›†åˆã«å«ã¾ã‚Œã‚‹å€‹ã€…ã®è¦ç´ ã‚’処ç†ã™ã‚‹éš›ã«ã€ãã®è¦ç´ ã‚’一ã¤ãšã¤å–り出ã™æ©Ÿèƒ½ã§ã™ã€‚トラãƒãƒ¼ã‚µãƒ«ã‚¢ã‚¯ã‚»ã‚¹ã‚’ã¯ã˜ã‚ã‚‹å‰ã«ã¯ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‚’åˆæœŸåŒ–ã—ã¾ã™ã€‚ãã—ã¦ã€ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ãŒã€Œæ‰“ã¡æ­¢ã‚ã€ã®åˆå›³ã‚’è¿”ã™ã¾ã§ç¹°ã‚Šè¿”ã—ã¦å‘¼ã³å‡ºã—ã¾ã™ã€‚

+ +
int dpiterinit(DEPOT *depot);
+ +

`dpiterinit' ã¯ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‚’åˆæœŸåŒ–ã™ã‚‹é–¢æ•°ã§ã™ã€‚特ã«èª¬æ˜Žã¯å¿…è¦ã‚ã‚Šã¾ã›ã‚“ã­ã€‚

+ +
char *dpiternext(DEPOT *depot, int *sp);
+ +

`dpiternext' ã¯ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‹ã‚‰æ¬¡ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã‚’å–り出ã™é–¢æ•°ã§ã™ã€‚第1引数ã¯ä»–ã¨åŒã˜ã§ã™ã€‚例ã«ã‚ˆã£ã¦æˆ»ã‚Šå€¤ã¯ã‚¼ãƒ­ã‚³ãƒ¼ãƒ‰ãŒä»˜åŠ ã•ã‚ŒãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã™ã€‚領域㯠`malloc' ã§ç¢ºä¿ã•ã‚Œã¦ã„ã‚‹ã®ã§ã€ã‚¢ãƒ—リケーションã®è²¬ä»»ã§ `free' ã—ã¦ãã ã•ã„。明示的ã«ã‚µã‚¤ã‚ºã‚’知りãŸã„å ´åˆã¯ç¬¬2引数ã«ãれをå—ã‘å–る変数ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã—ã¾ã™ã€‚ã‚‚ã†å–り出ã™ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªããªã£ãŸã‚‰ `NULL' ãŒè¿”ã•ã‚Œã¾ã™ï¼ˆ`DP_ENOITEM' ã¨ã„ã†ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ãŒå¤–部変数 `dpecode' ã«è¨­å®šã•ã‚Œã¾ã™ï¼‰ã€‚

+ +

トラãƒãƒ¼ã‚µãƒ«ã‚¢ã‚¯ã‚»ã‚¹ã§å„レコードを辿る順番ã«ã¤ã„ã¦ã¯è¦å®šã•ã‚Œã¦ã„ã¾ã›ã‚“ã®ã§ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é †åºã«ä¾å­˜ã—ãŸãƒ—ログラミングをã—ã¦ã¯ã„ã‘ã¾ã›ã‚“(ãã®ã‚ˆã†ãªå ´åˆã¯B+木データベースを使ã„ã¾ã—ょã†ï¼‰ã€‚ã¾ãŸã€ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‚’ç¹°ã‚Šè¿”ã—ã¦ã„る途中ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’上書ãã—ãŸå ´åˆã€æ—¢ã«èª­ã‚“ã ã¯ãšã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒã¾ãŸå–り出ã•ã‚Œã‚‹å¯èƒ½æ€§ãŒã‚ã‚Šã¾ã™ã€‚途中ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã™ã‚‹ã“ã¨ã«é–¢ã—ã¦ã¯å•é¡Œã‚ã‚Šã¾ã›ã‚“。

+ +

ã“ã“ã¾ã§ã§Depotã®åŸºæœ¬çš„ãªä½¿ã„æ–¹ã¯èª¬æ˜Žã—終ãˆã¾ã—ãŸã€‚QDBMã®ãれ以外ã®APIã‚‚Depotã«ä¼¼ãŸã‚ˆã†ãªä½¿ã„方をã—ã¾ã™ã®ã§ã€åŸºæœ¬ä»•æ§˜æ›¸ã®ã‚µãƒ³ãƒ—ルコードを見れã°ç†è§£ã—ã¦ã‚‚らãˆã‚‹ã¨æ€ã„ã¾ã™ã€‚

+ +
+ +

Curia: æ‹¡å¼µAPI

+ +

Curiaã¯ã€Depotã¨ã»ã¨ã‚“ã©åŒã˜æ©Ÿèƒ½ã¨ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ã‚’å‚™ãˆã¾ã™ãŒã€ãƒ•ã‚¡ã‚¤ãƒ«ã§ãªãディレクトリã¨ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†APIã§ã™ã€‚ã‚„ãŸã‚‰ã¨å¤§é‡ã®ãƒ‡ãƒ¼ã‚¿ã‚’扱ã‚ãªã‘ã‚Œã°ãªã‚‰ãªã„å ´åˆã«ã¯CuriaãŒãŠè–¦ã‚ã§ã™ã€‚データをディレクトリã®ä¸­ã®è¤‡æ•°ã®ãƒ•ã‚¡ã‚¤ãƒ«ã«åˆ†æ•£ã—ã¦æ ¼ç´ã™ã‚‹ã®ã§ã€Depotよりも大ããªï¼ˆ2GB以上ã®ï¼‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†ã“ã¨ãŒã§ãã¾ã™ã€‚Depotã§ã¯ãƒãƒ³ãƒ‰ãƒ«ã« `DEPOT' ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’使ã„ã¾ã—ãŸãŒã€Curiaã§ã¯ `CURIA' ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’使ã„ã¾ã™ã€‚ãã—ã¦ã€Depotã§ã¯ `dp' ã§å§‹ã¾ã£ã¦ã„ãŸé–¢æ•°åãŒã€Curiaã§ã¯ `cr' ã§å§‹ã¾ã‚Šã¾ã™ã€‚åå‰ãŒé•ã†ã ã‘ã§ã€ä½¿ã„æ–¹ã¯å…¨ã一緒ã§ã™ã€‚ãŸã ã—ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã `cropen' ã¨ã„ã†é–¢æ•°ã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®åˆ†å‰²æ•°ã‚’指定ã™ã‚‹å¼•æ•°ãŒå¢—ãˆã¦ã„ã¾ã™ã€‚

+ +
CURIA *cropen(const char *name, int omode, int bnum, int dnum);
+ +

第1ã€ç¬¬2ã€ç¬¬3引数㯠`dpopen' ã®ã‚‚ã®ã¨å…¨ã一緒ã§ã™ã€‚第4引数ã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®åˆ†å‰²æ•°ã‚’指定ã—ã¾ã™ã€‚ディレクトリã®ä¸­ã«ã€æŒ‡å®šã—ãŸæ•°ã ã‘ã®ãƒ•ã‚¡ã‚¤ãƒ«ãŒä½œã‚‰ã‚Œã¾ã™ã€‚ãªãŠã€ç¬¬3引数ã§æŒ‡å®šã—ãŸå€¤ã¯ãã®å„々ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ãŒæŒã¤ãƒã‚±ãƒƒãƒˆæ•°ã«ãªã‚Šã¾ã™ã€‚戻り値ã¯Curiaã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã¨ãªã‚Šã¾ã™ã€‚

+ +

Curiaã«ã¯ã€Œãƒ©ãƒ¼ã‚¸ã‚ªãƒ–ジェクトã€ã‚’扱ã†æ©Ÿèƒ½ã‚‚ã‚ã‚Šã¾ã™ã€‚ラージオブジェクトã¨ã¯ã€å„レコードをファイルã¨ã—ã¦ç‹¬ç«‹ã•ã›ã¦ä¿å­˜ã™ã‚‹ä»•çµ„ã¿ã§ã™ã€‚ラージオブジェクトã«ã™ã‚‹ã¨é€šå¸¸ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚ˆã‚Šå‡¦ç†é€Ÿåº¦ãŒè½ã¡ã¾ã™ãŒã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ã‚µã‚¤ã‚ºã‚’ç„¡é™ã«ï¼ˆãƒ‡ã‚£ã‚¹ã‚¯ãŒè¨±ã™é™ã‚Šï¼‰å¤§ããã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚ãªãŠã€ãƒ©ãƒ¼ã‚¸ã‚ªãƒ–ジェクトã®ãƒˆãƒ©ãƒãƒ¼ã‚µãƒ«ã‚¢ã‚¯ã‚»ã‚¹ã¯ã‚µãƒãƒ¼ãƒˆã•ã‚Œã¾ã›ã‚“。

+ +
+ +

Relic: NDBM互æ›API

+ +

Relicã¯ã€NDBMã®ã‚¢ãƒ—リケーションをã™ã¹ã‹ã‚‰ãQDBMã«ä¹—ã‚Šæ›ãˆã•ã›ã‚‹ã¨ã„ã†é‡Žæœ›ã®ä¸‹ã«ä½œã‚‰ã‚ŒãŸAPIã§ã™ã€‚パフォーマンスã¯ã‚ªãƒªã‚¸ãƒŠãƒ«ã®NDBMã®æ•°å€ã¯å‡ºã¾ã™ã€‚NDBMã®ã‚¢ãƒ—リケーションã¯ã‚ã¾ã‚Šè¦‹ãªã„ã§ã™ãŒã€Perlç­‰ã®ã‚¹ã‚¯ãƒªãƒ—ト言語ãŒãã®ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ã‚’å‚™ãˆã¦ã„ã¾ã™ã€‚ã¤ã¾ã‚ŠRelicã«ã‚ˆã£ã¦å„種ã®ã‚¹ã‚¯ãƒªãƒ—ト言語ã§QDBMãŒä½¿ãˆã‚‹ã“ã¨ãŒä¿è¨¼ã•ã‚Œã‚‹ã‚ã‘ã§ã™ã€‚

+ +

ã‚ãªãŸã®ã‚¢ãƒ—リケーションã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ä¸­ã§ `ndbm.h' をインクルードã—ã¦ã„る部分を `relic.h' ã«æ›¸ãæ›ãˆã€ãƒªãƒ³ã‚¯å¯¾è±¡ã‚’ `ndbm' ã‹ã‚‰ `qdbm' ã«æ›ãˆã¦å†ã‚³ãƒ³ãƒ‘イルã—ãã ã•ã„。ãã‚Œã ã‘ã§ã‚ãªãŸã®ã‚¢ãƒ—リケーションã¯QDBMã«ä¹—ã‚Šæ›ãˆã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚ãªãŠã€æ–°ãŸã«ã‚¢ãƒ—リケーションを書ãéš›ã«ã¯ã€Relicã§ãªãDepotを利用ã™ã‚‹ã“ã¨ã‚’ãŠè–¦ã‚ã—ã¾ã™ã€‚

+ +
+ +

Hovel: GDBM互æ›API

+ +

Hovelã¯ã€GDBMã®ã‚¢ãƒ—リケーションをã™ã¹ã‹ã‚‰ãQDBMã«ä¹—ã‚Šæ›ãˆã•ã›ã‚‹ã¨ã„ã†é‡Žæœ›ã®ä¸‹ã«ä½œã‚‰ã‚ŒãŸAPIã§ã™ã€‚パフォーマンスã¯ã‚ªãƒªã‚¸ãƒŠãƒ«ã®GDBMã®æ•°å€ã¯å‡ºã¾ã™ã€‚GDBMã®ã‚¢ãƒ—リケーションã¯å¸‚å ´ã«å¤šã見られã¾ã™ãŒã€ãれらをãŠä½¿ã„ã®å ´åˆã¯ã€ãœã²ã¨ã‚‚QDBMã«ç§»æ¤ã—ã¦ã‚ã’ã¦ãã ã•ã„。パフォーマンスãŒç›®ã«è¦‹ãˆã¦ã«æ”¹å–„ã•ã‚Œã‚‹ã“ã¨ã†ã‘ã‚ã„ã§ã™ã€‚

+ +

ã‚ãªãŸã®ã‚¢ãƒ—リケーションã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ä¸­ã§ `gdbm.h' をインクルードã—ã¦ã„る部分を `hovel.h' ã«æ›¸ãæ›ãˆã€ãƒªãƒ³ã‚¯å¯¾è±¡ã‚’ `gdbm' ã‹ã‚‰ `qdbm' ã«æ›ãˆã¦å†ã‚³ãƒ³ãƒ‘イルã—ãã ã•ã„。ãã‚Œã ã‘ã§ã‚ãªãŸã®ã‚¢ãƒ—リケーションã¯QDBMã«ä¹—ã‚Šæ›ãˆã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚ãªãŠã€æ–°ãŸã«ã‚¢ãƒ—リケーションを書ãéš›ã«ã¯ã€Hovelã§ãªãDepotを利用ã™ã‚‹ã“ã¨ã‚’ãŠè–¦ã‚ã—ã¾ã™ã€‚

+ +

通常ã€HovelãŒç”Ÿæˆã™ã‚‹ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã¯Depotã®ã‚‚ã®ã¨å…¨ãåŒã˜ã‚‚ã®ã§ã™ã€‚ã—ã‹ã—ã€ã¡ã‚‡ã£ã¨ç´°å·¥ã™ã‚‹ã¨ãれをCuriaã«ã‚ˆã‚‹ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã«å¤‰æ›´ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚データベースãƒãƒ³ãƒ‰ãƒ«ã‚’å–å¾—ã™ã‚‹é–¢æ•° `gdbm_open' ã‚’ã€`gdbm_open2' ã«æ›¸ãæ›ãˆã‚Œã°ã‚ˆã„ã®ã§ã™ã€‚å˜ä¸€ã®ãƒ•ã‚¡ã‚¤ãƒ«ã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’æ ¼ç´ã—ã¦ã„ã‚‹å ´åˆã¯ã€ãƒ•ã‚¡ã‚¤ãƒ«ã‚µã‚¤ã‚ºãŒ2GBã¾ã§ã¨ã„ã†åˆ¶é™ã«ã²ã£ã‹ã‹ã£ã¦ã—ã¾ã„ã¾ã™ãŒã€`gdbm_open2' を使ãˆã°ãれを乗り越ãˆã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚`gdbm_open' を呼ã³å‡ºã—ã¦ã„ã‚‹ã¨ã“ã‚以外ã¯å…¨ã変更ã™ã‚‹å¿…è¦ãŒãªã„ã¨ã„ã†ã®ãŒå¬‰ã—ã„ã¨ã“ã‚ã§ã™ã€‚

+ +
GDBM_FILE gdbm_open2(char *name, int read_write, int mode, int bnum, int dnum, int align);
+ +

第1引数ã¯ç”Ÿæˆã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ã‹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®åå‰ã§ã™ã€‚第2引数ã¨ç¬¬3引数㯠`gdbm_open' ã®ç¬¬3引数ã¨ç¬¬4引数ã¨ã—ã¦æ¸¡ã™ã‚‚ã®ã¨ä¸€ç·’ã§ã™ã€‚第4引数ã¯ãƒã‚±ãƒƒãƒˆã®è¦ç´ æ•°ã§ã™ã€‚第5引数ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®åˆ†å‰²æ•°ã§ã™ã€‚第6引数ã¯å„レコードã®ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã§ã™ã€‚戻り値㯠`gdbm_open' ã¨åŒã˜ãデータベースãƒãƒ³ãƒ‰ãƒ«ã§ã™ã€‚

+ +
+ +

Cabin: ユーティリティAPI

+ +

Cabinã¯ã€ãƒ‡ãƒ¼ã‚¿ã®æ“作を簡å˜ã«è¡Œã†ãŸã‚ã®ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£ã‚’集ã‚ãŸAPIã§ã™ã€‚密ã‹ã«QDBMã®APIã®ä¸­ã§æœ€ã‚‚充実ã—ã¦ã„ã¾ã™ã€‚特ã«ãƒªã‚¹ãƒˆã¨ãƒžãƒƒãƒ—ã«é–¢é€£ã™ã‚‹é–¢æ•°ãŒé‡å®ã—ã¾ã™ã€‚ä»–ã«ã‚‚ã€ãƒ•ã‚¡ã‚¤ãƒ«ã‚„ディレクトリを読んã ã‚Šã€æ–‡å­—列を分割ã—ãŸã‚Šã€CSVã‚„XMLを解æžã—ãŸã‚Šã€å„種ã®ç¬¦å·åŒ–ã¨å¾©å·ã‚‚ã§ãã¾ã™ã€‚ã“ã“ã§ã¯ãƒªã‚¹ãƒˆã¨ãƒžãƒƒãƒ—ã¨XMLã«ã¤ã„ã¦è©³ã—ã説明ã—ã¾ã™ã€‚

+ +

リストã¨ã¯ã€é †åºã‚’æŒã£ãŸé›†åˆã®ã“ã¨ã§ã™ã€‚CabinãŒæ‰±ã†ãƒªã‚¹ãƒˆã«ã¯ä»»æ„ã®æ–‡å­—列やãƒã‚¤ãƒŠãƒªã‚’è¦ç´ ã¨ã—ã¦åŠ ãˆã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚リストã®å…ˆé ­ã«å¯¾ã—ã¦è¦ç´ ã®è¿½åŠ ã¨å‰Šé™¤ãŒã§ãã‚‹ã¨ã¨ã‚‚ã«ã€ãƒªã‚¹ãƒˆã®æœ«å°¾ã«å¯¾ã—ã¦è¦ç´ ã®è¿½åŠ ã¨å‰Šé™¤ã‚’ã™ã‚‹ã“ã¨ã‚‚ã§ãã¾ã™ï¼ˆã¤ã¾ã‚Šãƒ‡ã‚¯ã§ã™ï¼‰ã€‚ã¾ãŸã€é…列を使ã£ã¦å®Ÿè£…ã•ã‚Œã¦ã„ã‚‹ã®ã§ã€ä»»æ„ã®é †ç•ªã®è¦ç´ ã®å€¤ã‚’高速ã«å‚ç…§ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚以下ã®ä¾‹ã§ã¯ã€`first'ã€`second'ã€`third' ã¨ã„ã†æ–‡å­—列を順ã«æœ«å°¾ã‹ã‚‰è¿½åŠ ã—ãŸä¸Šã§ã€å…ˆé ­ã‹ã‚‰æœ«å°¾ã¾ã§è¦ç´ ã®å†…容を表示ã—ã¦ã„ã¾ã™ã€‚

+ +
#include <cabin.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void listtest(void){
+  CBLIST *list;
+  int i;
+  /* リストを開ã */
+  list = cblistopen();
+  /* è¦ç´ ã‚’末尾ã‹ã‚‰è¿½åŠ ã™ã‚‹ */
+  cblistpush(list, "first", -1);
+  cblistpush(list, "second", -1);
+  cblistpush(list, "third", -1);
+  /* 先頭ã‹ã‚‰è¦ç´ ã®å†…容を表示ã™ã‚‹ */
+  for(i = 0; i < cblistnum(list); i++){
+    printf("%s\n", cblistval(list, i, NULL));
+  }
+  /* リストを閉ã˜ã‚‹ */
+  cblistclose(list);
+}
+
+ +

`CBLIST' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’リストã®ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„ã¾ã™ã€‚実際ã®ãƒãƒ³ãƒ‰ãƒ«ã¯ `cblistopen' を呼ã³å‡ºã—ã¦ç²å¾—ã—ã¾ã™ã€‚ãƒãƒ³ãƒ‰ãƒ«ã‚’é–‰ã˜ã¦ãƒ¡ãƒ¢ãƒªã‚’解放ã™ã‚‹ã«ã¯ã€`cblistclose' を呼ã³å‡ºã—ã¾ã™ã€‚`cblistpush' ã¯æœ«å°¾ã«è¦ç´ ã‚’追加ã—ã¾ã™ã€‚`cblistnum' ã¯ãƒªã‚¹ãƒˆã®è¦ç´ æ•°ã‚’è¿”ã—ã¾ã™ã€‚`cblistval' ã¯ãƒªã‚¹ãƒˆå†…ã®ç‰¹å®šã®ç•ªå·ï¼ˆã‚¼ãƒ­ã‹ã‚‰ã¯ã˜ã¾ã‚‹ï¼‰ã®è¦ç´ ã‚’è¿”ã—ã¾ã™ã€‚リストæ“作ã®é–¢æ•°ã¯ãã®ä»–ã«ã‚‚ã„ãã¤ã‹ã‚ã‚Šã¾ã™ã€‚

+ +

マップã¨ã¯ã€ã‚­ãƒ¼ã¨å€¤ã‹ã‚‰ãªã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é›†åˆã§ã™ã€‚CabinãŒæ‰±ã†ãƒžãƒƒãƒ—ã«ã¯ä»»æ„ã®æ–‡å­—列やãƒã‚¤ãƒŠãƒªã‚’キーや値ã«æŒã¤ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚キーãŒå®Œå…¨ã«ä¸€è‡´ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã—ã¦å€¤ã‚’å–り出ã™ã“ã¨ãŒã§ãã¾ã™ï¼ˆå®Ÿè£…ã¯ãƒãƒƒã‚·ãƒ¥è¡¨ã§ã™ï¼‰ã€‚マップ内ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’先頭ã‹ã‚‰ä¸€ã¤ãšã¤å–り出ã™ã“ã¨ã‚‚ã§ãã¾ã™ã€‚ãªãŠã€å„è¦ç´ ã¯æ ¼ç´ã—ãŸé †ç•ªã§ä¸¦ã‚“ã§ã„ã‚‹ã“ã¨ãŒä¿è¨¼ã•ã‚Œã¦ã„ã¾ã™ã€‚以下ã®ä¾‹ã§ã¯ã€ã‚­ãƒ¼ `one' ã¨å€¤ `first'ã€ã‚­ãƒ¼ `two' ã¨å€¤ `second'ã€ã‚­ãƒ¼ `three' ã¨å€¤ `third' ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’é †ã«æ ¼ç´ã—ãŸä¸Šã§ã€ãã®å„々を検索ã—ã¦è¡¨ç¤ºã—ã¦ã„ã¾ã™ã€‚

+ +
#include <cabin.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void maptest(void){
+  CBMAP *map;
+  /* マップを開ã */
+  map = cbmapopen();
+  /* レコードを追加ã™ã‚‹ */
+  cbmapput(map, "one", -1, "first", -1, 1);
+  cbmapput(map, "two", -1, "second", -1, 1);
+  cbmapput(map, "three", -1, "third", -1, 1);
+  /* レコードを検索ã—ã¦å†…容を表示ã™ã‚‹ */
+  printf("one: %s\n", cbmapget(map, "one", -1, NULL));
+  printf("two: %s\n", cbmapget(map, "two", -1, NULL));
+  printf("three: %s\n", cbmapget(map, "three", -1, NULL));
+  /* マップを閉ã˜ã‚‹ */
+  cbmapclose(map);
+}
+
+ +

`CBMAP' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’マップã®ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„ã¾ã™ã€‚実際ã®ãƒãƒ³ãƒ‰ãƒ«ã¯ `cbmapopen' を呼ã³å‡ºã—ã¦ç²å¾—ã—ã¾ã™ã€‚ãƒãƒ³ãƒ‰ãƒ«ã‚’é–‰ã˜ã¦ãƒ¡ãƒ¢ãƒªã‚’解放ã™ã‚‹ã«ã¯ã€`cbmapclose' を呼ã³å‡ºã—ã¾ã™ã€‚`cbmapput' ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã—ã¾ã™ã€‚`cbmapget' ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã—ã¾ã™ã€‚マップæ“作ã®é–¢æ•°ã¯ãã®ä»–ã«ã‚‚ã„ãã¤ã‹ã‚ã‚Šã¾ã™ã€‚

+ +

XMLã‚’ç°¡å˜ã«å‡¦ç†ã™ã‚‹ãŸã‚ã«ã€ç°¡æ˜“çš„ãªãƒ‘ーザãŒç”¨æ„ã•ã‚Œã¦ã„ã¾ã™ã€‚ã“ã®ãƒ‘ーザã¯å¦¥å½“性検証をã›ãšã€æ›¸å¼ã®æ¤œæŸ»ã‚‚厳密ã§ãªã„ã®ãŒç‰¹å¾´ã§ã™ã€‚ã—ãŸãŒã£ã¦ã€ä¸€èˆ¬çš„ãªHTMLã‚„SGMLã®è§£æžã«ã‚‚用ã„ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚å˜ç´”ãªæ§‹é€ ã®XML文書を処ç†ã™ã‚‹éš›ã«ã¯ã€DOMã‚„SAXã¨ã„ã£ãŸAPIを使ã†ã‚ˆã‚Šã‚‚便利ã§ã™ã€‚以下ã®ä¾‹ã§ã¯ã€XML文書ã®ä¸­ã‹ã‚‰ `id' 属性ã®å€¤ã§è¦ç´ ã‚’指定ã—ã¦ã€ãã®ãƒ†ã‚­ã‚¹ãƒˆã‚’å–り出ã—ã¦è¡¨ç¤ºã—ã¾ã™ã€‚

+ +
#include <cabin.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+void showtextbyid(const char *xml, const char *id){
+  CBLIST *elems;
+  CBMAP *attrs;
+  const char *elem, *attr;
+  char *orig;
+  int i;
+  /* ã‚¿ã‚°ã¨ãƒ†ã‚­ã‚¹ãƒˆã®ãƒªã‚¹ãƒˆã‚’å–å¾—ã™ã‚‹ */
+  elems = cbxmlbreak(xml, 1);
+  /* リストã®å„è¦ç´ ã‚’ãŸã©ã‚‹ */
+  for(i = 0; i < cblistnum(elems); i++){
+    /* è¦ç´ ã‚’å–り出㙠*/
+    elem = cblistval(elems, i, NULL);
+    /* ã‚¿ã‚°ã§ãªã„å ´åˆã¯èª­ã¿é£›ã°ã™ */
+    if(elem[0] != '<' || elem[1] == '?' || elem[1] == '!' || elem[1] == '/') continue;
+    /* 属性ã®ãƒžãƒƒãƒ—ã‚’å–å¾—ã™ã‚‹ */
+    attrs = cbxmlattrs(elem);
+    /* IDè¦ç´ ã®å€¤ã‚’å–り出ã—ã€ä¸€è‡´ã‚’検査ã™ã‚‹ */
+    attr = cbmapget(attrs, "id", -1, NULL);
+    if(attr && !strcmp(attr, id)){
+      /* 次ã®è¦ç´ ã‚’å–り出㙠*/
+      elem = cblistval(elems, i + 1, NULL);
+      if(elem){
+        /* 実体å‚照を復元ã—ã¦è¡¨ç¤ºã™ã‚‹ */
+        orig = cbxmlunescape(elem);
+        printf("%s\n", orig);
+        free(orig);
+      }
+    }
+    /* 属性マップを閉ã˜ã‚‹ */
+    cbmapclose(attrs);
+  }
+  /* è¦ç´ ãƒªã‚¹ãƒˆã‚’é–‰ã˜ã‚‹ */
+  cblistclose(elems);
+}
+
+ +

処ç†å¯¾è±¡ã®XML文書ã®ãƒ†ã‚­ã‚¹ãƒˆã‚’ `cbxmlbreak' ã§åˆ†è§£ã—ã¾ã™ã€‚例ãˆã° `<body><p id="nuts">NUTS&amp;MILK</p></body>' を分解ã™ã‚‹ã¨ã€`<body>'ã€`<p id="nuts">'ã€`NUTS&amp;MILK'ã€`</p>'ã€`</body>' ãŒå¾—られã¾ã™ã€‚ãã—ã¦ã€å„è¦ç´ ã‚’巡回ã—ã¾ã™ã€‚1文字目㌠'<' ã§ã‚ã‚Œã°ã‚¿ã‚°ã‹å„種ã®å®£è¨€ã§ã‚ã‚Šã€ã‹ã¤2文字目㌠'?'ã€`!'ã€`/' ã®ã„ãšã‚Œã§ã‚‚ãªã‘ã‚Œã°é–‹å§‹ã‚¿ã‚°ã¾ãŸã¯ç©ºã‚¿ã‚°ã§ã‚ã‚‹ã¨åˆ¤æ–­ã§ãã¾ã™ã€‚ã‚¿ã‚°ã«å¯¾ã—㦠`cbxmlattrs' を呼ã¶ã“ã¨ã§å±žæ€§ã®ãƒžãƒƒãƒ—ãŒå¾—られã¾ã™ã€‚ã“ã®ãƒžãƒƒãƒ—ã¯å±žæ€§åをキーã«ã—ã¦å€¤ã‚’å–り出ã™ã“ã¨ãŒã§ãã¾ã™ã€‚属性値やテキストセクションã®æ–‡å­—列ã¯æ–‡æ›¸å†…ã«å‡ºç¾ã—ãŸã¾ã¾ã®å½¢å¼ã«ãªã£ã¦ã„ã¾ã™ã€‚実体å‚照をå«ã‚“ã æ–‡å­—列を復元ã™ã‚‹ã«ã¯ `cbxmlunescape' を用ã„ã¾ã™ã€‚

+ +

GTK+ã«ä»˜å±žã™ã‚‹GLibã‚„Apacheã«ä»˜å±žã™ã‚‹APRãªã©ã®ä¾¿åˆ©ãªãƒ©ã‚¤ãƒ–ラリãŒä¸–ã®ä¸­ã«ã¯ã‚ã‚Šã¾ã™ã®ã§ã€å˜ä½“ã§Cabinを利用ã™ã‚‹ä¾¡å€¤ã¯ã‚ã¾ã‚Šã‚ã‚Šã¾ã›ã‚“。正直言ã£ã¦ã€GLibã‚„APRã®æ–¹ãŒé«˜æ©Ÿèƒ½ã§ã€ãƒ¦ãƒ¼ã‚¶æ•°ã‚‚多ãã€å‚考ã«ãªã‚‹æƒ…報も多ã„ã§ã™ã€‚ã¨ã¯ã„ãˆã€Cabinã®æ–¹ãŒæ‰‹è»½ã«ä½¿ãˆã‚‹ã®ã§ç§ã¯å¥½ãã§ã™ã€‚

+ +
+ +

Villa: 上級API

+ +

Villaã¯ã€B+木ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†APIã§ã™ã€‚B+木データベースã«ã¯ãƒ¦ãƒ¼ã‚¶ãŒæŒ‡å®šã—ãŸé †åºã§ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒä¸¦ã¹ã‚‰ã‚Œã¦æ ¼ç´ã•ã‚Œã¾ã™ã€‚Depotã‚„Curiaã¯ã‚­ãƒ¼ã®å®Œå…¨ä¸€è‡´ã«ã‚ˆã‚‹æ¤œç´¢ã—ã‹ã§ãã¾ã›ã‚“ãŒã€Villaを用ã„ã‚‹ã¨ç¯„囲を指定ã—ã¦ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã€‚ã¾ãŸã€åŒã˜ã‚­ãƒ¼ã‚’æŒã¤è¤‡æ•°ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã™ã‚‹ã“ã¨ã‚‚ã§ãã¾ã™ã€‚例ãˆã°ã€ã‚­ãƒ¼ã‚’文字列ã®è¾žæ›¸é †ï¼ˆABCé †ã¨ã‹ã‚¢ã‚¤ã‚¦ã‚¨ã‚ªé †ã¨åŒã˜ã»ã¼æ„味ã§ã™ï¼‰ã§ä¸¦ã¹ã‚‹ã‚ˆã†ã«æŒ‡å®šã—ãŸå ´åˆã¯ã€æ–‡å­—列ã®å‰æ–¹ä¸€è‡´æ¤œç´¢ãŒã§ãã‚‹ã®ã§ã™ã€‚

+ +

ã¨ã¯ã„ãˆã€åŸºæœ¬çš„ãªä½¿ã„æ–¹ã¯Depotã¨ä¸€ç·’ã§ã™ã€‚Depotã®èª¬æ˜Žã§æŒ™ã’ãŸé–¢æ•°ã‚’Villaを使ã£ã¦å®Ÿè£…ã—ãªãŠã—ã¦ã¿ã¾ã™ã€‚

+ +
#include <depot.h>
+#include <cabin.h>
+#include <villa.h>
+#include <stdlib.h>
+
+#define PHONEFILE    "phone"
+
+int putphonenumber(const char *id, const char *phone){
+  VILLA *villa;
+  /* データベースを追記モードã§é–‹ã */
+  if(!(villa = vlopen(PHONEFILE, VL_OWRITER | VL_OCREAT, VL_CMPLEX))) return -1;
+  /* レコードを書ã込む */
+  vlput(villa, id, -1, phone, -1, VL_DOVER);
+  /* データベースを閉ã˜ã‚‹ */
+  if(!vlclose(villa)) return -1;
+  return 0;
+}
+
+char *getphonenumber(const char *id){
+  VILLA *villa;
+  char *phone;
+  /* データベースを読ã¿è¾¼ã¿ãƒ¢ãƒ¼ãƒ‰ã§é–‹ã */
+  if(!(villa = vlopen(PHONEFILE, VL_OREADER, VL_CMPLEX))) return NULL;
+  /* レコードを検索ã—ã¦æˆ»ã‚Šå€¤ã‚’生æˆã™ã‚‹ */
+  phone = vlget(villa, id, -1, NULL);
+  /* データベースを閉ã˜ã‚‹ */
+  vlclose(villa);
+  return phone;
+}
+
+ +

`VILLA' ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã¯ä¾‹ã«ã‚ˆã£ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã§ã™ã€‚`vlopen' ã§ãã®ãƒãƒ³ãƒ‰ãƒ«ã‚’ç²å¾—ã—ã¾ã™ã€‚ãã®ç¬¬3引数㮠`VL_CMPLEX' ã¯è¾žæ›¸é †ã®æ¯”較を行ã†é–¢æ•°ã§ã™ã€‚é–‹ã„ãŸãƒãƒ³ãƒ‰ãƒ«ã¯ `vlclose' ã§é–‰ã˜ã¾ã™ã€‚`vlput' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã™ã‚‹é–¢æ•°ã§ã€`vlget' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã™ã‚‹é–¢æ•°ã§ã™ã€‚

+ +

上記ã®ä¾‹ã§ã¯ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¨å…¨ãåŒã˜ä½¿ã„方をã—ã¾ã—ãŸãŒã€é †ç•ªã«åŸºã¥ã„ã¦ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ã‚¢ã‚¯ã‚»ã‚¹ã™ã‚‹æ©Ÿèƒ½ãŒB+木データベースã®ç‰¹å¾´ã§ã™ã€‚辞書順を例ã«ã¨ã£ã¦èª¬æ˜Žã—ã¾ã™ã€‚キーãŒãã‚Œãžã‚Œ `one'ã€`two'ã€`three'ã€`four' ã¨ã„ã†ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã—ãŸã¨ã™ã‚Œã°ã€ãれ㯠`four'ã€`one'ã€`three'ã€`two' ã¨ã„ã†é †ç•ªã§ä¸¦ã¹ã‚‰ã‚Œã¦ä¿å­˜ã•ã‚Œã¾ã™ã€‚検索ã«ã¯ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¨åŒæ§˜ã«å®Œå…¨ä¸€è‡´æ¡ä»¶ã‚‚使ãˆã¾ã™ã€‚ã•ã‚‰ã«ã€ã€Œã‚«ãƒ¼ã‚½ãƒ«ã€ã¨ã„ã†æ©Ÿèƒ½ã‚’使ã£ã¦ç¯„囲を指定ã—ãŸæ¤œç´¢ãŒã§ãã¾ã™ã€‚カーソルã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ä½ç½®ã‚’指ã—示ã—ã¾ã™ã€‚例ãˆã°ã€`one' ã®å ´æ‰€ã«ã‚«ãƒ¼ã‚½ãƒ«ã‚’飛ã°ã™ã¨ã„ã£ãŸæŒ‡å®šãŒã§ãã¾ã™ã€‚`one' ãŒãªã„å ´åˆã¯ã€`one' ã®ç›´å¾Œã® `three' ã®ä½ç½®ã«ã‚«ãƒ¼ã‚½ãƒ«ãŒé£›ã¶ã“ã¨ã«ãªã‚Šã¾ã™ï¼ˆ`one' ãŒè¤‡æ•°ã‚ã£ãŸå ´åˆã¯ã€ãã®æœ€åˆã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«é£›ã³ã¾ã™ï¼‰ã€‚カーソルã¯ã€ç¾åœ¨ä½ç½®ã‹ã‚‰å‰ã«é€²ã‚ãŸã‚Šå¾Œã‚ã«æˆ»ã—ãŸã‚Šã™ã‚‹ã“ã¨ã‚‚ã§ãã¾ã™ã€‚ãã—ã¦ã€ã‚«ãƒ¼ã‚½ãƒ«ã®ä½ç½®ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å†…容を読ã¿å‡ºã›ã°ã€ç¯„囲を指定ã—ãŸæ¤œç´¢ãŒã§ãã‚‹ã¨ã„ã†ã‚ã‘ã§ã™ã€‚以下ã®ä¾‹ã¯ã€`one' ã‹ã‚‰ `three' ã¾ã§ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã¨å€¤ã‚’表示ã™ã‚‹é–¢æ•°ã§ã™ã€‚

+ +
#include <depot.h>
+#include <cabin.h>
+#include <villa.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define WORDFILE     "word"
+#define TOPWORD      "one"
+#define BOTTOMWORD   "three"
+
+void printwords(void){
+  VILLA *villa;
+  char *kbuf, *vbuf;
+  int ksiz;
+  /* データベースを読ã¿è¾¼ã¿ãƒ¢ãƒ¼ãƒ‰ã§é–‹ã */
+  if(!(villa = vlopen(WORDFILE, VL_OREADER, VL_CMPLEX))) return;
+  /* カーソルを候補ã®å…ˆé ­ã«é£›ã°ã™ */
+  vlcurjump(villa, TOPWORD, -1, VL_JFORWARD);
+  /* å„候補を処ç†ã™ã‚‹ */
+  do {
+    /* レコードã®ã‚­ãƒ¼ã‚’å–り出㙠*/
+    kbuf = vlcurkey(villa, &ksiz);
+    /* 候補ãŒç¯„囲外ã§ã‚ã‚Œã°æŠœã‘ã‚‹ */
+    if(!kbuf || VL_CMPLEX(kbuf, ksiz, BOTTOMWORD, sizeof(BOTTOMWORD) - 1) > 0){
+      free(kbuf);
+      break;
+    }
+    /* レコードã®å€¤ã‚’å–り出ã—ã¦è¡¨ç¤ºã™ã‚‹ */
+    vbuf = vlcurval(villa, NULL);
+    if(kbuf && vbuf) printf("%s: %s\n", kbuf, vbuf);
+    /* キーã¨å€¤ã®é ˜åŸŸã‚’解放ã™ã‚‹ */
+    free(vbuf);
+    free(kbuf);
+    /* カーソルを次ã«é€²ã‚ã‚‹ */
+  } while(vlcurnext(villa));
+  /* データベースを閉ã˜ã‚‹ */
+  vlclose(villa);
+}
+
+ +

`vlcurjump' ã§ã‚«ãƒ¼ã‚½ãƒ«ã‚’候補ã®å…ˆé ­ã«é£›ã°ã—ã¦ã„ã¾ã™ã€‚`VL_JFORWARD' ã¯ã“ã‚Œã‹ã‚‰ã‚«ãƒ¼ã‚½ãƒ«ã‚’å‰ã«é€²ã‚ã¦ã„ãå ´åˆã«æŒ‡å®šã—ã¾ã™ï¼ˆå€™è£œã®æœ«å°¾ã«é£›ã°ã—ã¦ã‹ã‚‰å¾Œã‚ã«æˆ»ã—ã¦è¡Œãå ´åˆã¯ `VL_JBACKWARD' を指定ã—ã¾ã™ï¼‰ã€‚do-whileループã®æ¡ä»¶éƒ¨ã§ `vlcurnext' を呼んã§ã„ã¾ã™ãŒã€ã“ã‚ŒãŒã‚«ãƒ¼ã‚½ãƒ«ã‚’å‰ã«é€²ã‚ã¦ã„ã¾ã™ï¼ˆãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æœ€å¾Œã¾ã§æ¥ãŸã‚‰å½ã‚’è¿”ã™ã®ã§ãƒ«ãƒ¼ãƒ—ã‹ã‚‰æŠœã‘ã¾ã™ï¼‰ã€‚`vlcurkey' 㨠`vlcurval' ã¯ãã‚Œãžã‚Œã‚«ãƒ¼ã‚½ãƒ«ã®ã‚­ãƒ¼ã¨å€¤ã‚’å–り出ã—ã¾ã™ã€‚`VL_CMPLEX' を明示的ã«å‘¼ã‚“ã§ã„る場所ãŒã‚ã‚Šã¾ã™ãŒã€ã“ã“ã§å€™è£œã®æœ«å°¾ã«æ¥ãŸã‹ã©ã†ã‹åˆ¤å®šã—ã¦ã„ã¾ã™ã€‚比較関数ã¯ã€äºŒã¤ã®ã‚­ãƒ¼ã®ãƒã‚¤ãƒ³ã‚¿ã¨ã‚µã‚¤ã‚ºã‚’渡ã—ã¦ã€å‰è€…ãŒå¤§ãã„(ã¤ã¾ã‚Šå¾Œã‚ã«ä½ç½®ã™ã¹ã)ãªã‚‰æ­£ã®å€¤ã€å‰è€…ãŒå°ã•ã„(ã¤ã¾ã‚Šå‰ã«ä½ç½®ã™ã¹ã)ãªã‚‰è² ã®å€¤ã€ä¸¡è€…ãŒåŒã˜ãªã‚‰ã‚¼ãƒ­ã‚’è¿”ã™ã¨è¦å®šã•ã‚Œã¦ã„ã¾ã™ã€‚ã—ãŸãŒã£ã¦ã€æ­£ã®å€¤ãŒè¿”ã•ã‚ŒãŸå ´åˆã€ä»Šå–り出ã—ãŸã‚­ãƒ¼ã¯å€™è£œã®æœ«å°¾ã‚ˆã‚Šã‚‚後ã‚ã ã¨ã„ã†ã“ã¨ã«ãªã‚Šã¾ã™ã€‚

+ +

辞書順以外ã®æ¯”較関数も使ãˆã‚‹ã¨ã“ã‚ãŒVillaã®ãƒŸã‚½ã§ã™ã€‚intåž‹ã®æ•°å€¤ã‚’比較ã™ã‚‹ `VL_CMPINT' ã‚„ã€10進数ã®æ–‡å­—列を比較ã™ã‚‹ `VL_CMPDEC' ã¨ã„ã£ãŸé–¢æ•°ãŒæœ€åˆã‹ã‚‰ç”¨æ„ã•ã‚Œã¦ã„ã¾ã™ã€‚ã•ã‚‰ã«ã€ã‚ãªãŸãŒè‡ªåˆ†ã§å®šç¾©ã—ãŸé–¢æ•°ã‚‚比較関数ã¨ã—ã¦ä½¿ã†ã“ã¨ãŒã§ãã¾ã™ã€‚使ã„æ–¹ãŒé¢å€’ã ã¨ã„ã†æ¬ ç‚¹ã‚’除ã‘ã°ã€B+木データベースã¯ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚ˆã‚Šã‚‚多ãã®ã‚·ãƒ¼ãƒ³ã§æ´»ç”¨ã§ãã‚‹ã¨æ€ã„ã¾ã™ã€‚ファイルãŒãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚ˆã‚Šã‚‚å°ã•ã‹ã£ãŸã‚Šã€ãƒˆãƒ©ãƒ³ã‚¶ã‚¯ã‚·ãƒ§ãƒ³ãŒä½¿ãˆã‚‹ã¨ã„ã£ãŸç‰¹å¾´ã‚‚ã€äººã«ã‚ˆã£ã¦ã¯å¬‰ã—ã„ã‹ã‚‚ã—ã‚Œã¾ã›ã‚“。

+ +

Villaã¯ã€ã‚­ãƒ¥ãƒ¼ï¼ˆFIFO)を永続化ã™ã‚‹ç›®çš„ã§ã‚‚利用ã§ãã¾ã™ã€‚`VL_CMPINT' を比較関数ã«ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ãã¾ã™ã€‚å„レコードã®ã‚­ãƒ¼ã¯intåž‹ã¨ã—ã€å€¤ã«ã¯ä»»æ„ã®ã‚ªãƒ–ジェクトを入れるã“ã¨ã«ã—ã¾ã™ã€‚キューã«è¦ç´ ã‚’追加ã™ã‚‹ã«ã¯ã€æœ«å°¾ã®ã‚­ãƒ¼ã®æ•°å€¤ï¼ˆãªã‘ã‚Œã°ã‚¼ãƒ­ï¼‰ã‚’インクリメントã—ã¦ã‚­ãƒ¼ã‚’生æˆã—ã¦æ ¼ç´ã—ã¾ã™ã€‚キューã‹ã‚‰è¦ç´ ã‚’å–り出ã™ã«ã¯ã€å…ˆé ­ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å–り出ã—ã¦ã‹ã‚‰å‰Šé™¤ã™ã‚Œã°ã‚ˆã„ã®ã§ã™ã€‚ãã®ã‚ˆã†ãªæ©Ÿèƒ½ã‚’æŒã¤ãƒ©ãƒƒãƒ‘関数をã€`qopen'ã€`qclose'ã€`qappend'ã€`qconsume' ã¨ã„ã£ãŸåå‰ã§ä½œã£ã¦ãŠãã¨å°ç²‹ã§ã™ã­ã€‚

+ +
+ +

Odeum: 転置API

+ +

Odeumã¯ã€å…¨æ–‡æ¤œç´¢ç”¨ã®è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’扱ã†APIã§ã™ã€‚テキストファイル(ã¾ãŸã¯ãƒ†ã‚­ã‚¹ãƒˆã‚’å«ã‚€HTMLã‚„MS-Wordã®æ–‡æ›¸ãªã©ï¼‰ã¯å˜èªžã®é›†åˆã¨ã¿ãªã›ã¾ã™ãŒã€ã‚ã‚‹å˜èªžãŒã©ã®ãƒ•ã‚¡ã‚¤ãƒ«ã«å«ã¾ã‚Œã‚‹ã‹ã¨ã„ã†æƒ…報をデータベースã«ã—ãŸã‚‚ã®ã‚’転置インデックスã¨å‘¼ã³ã¾ã™ã€‚本ã®å·»æœ«ã«ã‚る索引ã¯ã€ã‚ã‚‹å˜èªžãŒã©ã®ãƒšãƒ¼ã‚¸ã«å«ã¾ã‚Œã‚‹ã‹ã¨ã„ã†æƒ…報をæŒã£ã¦ã„ã¾ã™ãŒã€ãã‚Œã¨ä¼¼ãŸã‚ˆã†ãªã‚‚ã®ã§ã™ã€‚ç§ãŒQDBMを開発ã™ã‚‹å¥‘æ©Ÿã¨ãªã£ãŸã®ã¯ã€ã¨ã‚る全文検索システムã®é–‹ç™ºã§ä½¿ã£ã¦ã„ãŸGDBMã®ãƒ‘フォーマンスã«é™ç•Œã‚’æ„Ÿã˜ãŸã“ã¨ã§ã™ã€‚ãã®çµŒç·¯ã‹ã‚‰ã€QDBM(特ã«Curia)ã«ã¯è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®å®Ÿç¾ã«éƒ½åˆã®ã‚ˆã„特徴ãŒã„ãã¤ã‹å‚™ã‚ã£ã¦ã„ã¾ã™ã€‚

+ +

転置インデックスã®æ ¸ã¨ãªã‚‹ã®ã¯ã€ã‚ã‚‹å˜èªžã‚’キーã¨ã—ã€ãã®å˜èªžã‚’å«ã‚€ãƒ•ã‚¡ã‚¤ãƒ«ã®IDã®é…列を値ã¨ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‹ã‚‰ãªã‚‹ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã§ã™ã€‚å˜èªžã¯å®Œå…¨ä¸€è‡´ã§æ¤œç´¢ã§ãã‚Œã°ã‚ˆã„ã®ã§ã€ãƒ‡ãƒ¼ã‚¿æ§‹é€ ã«ã¯ãƒãƒƒã‚·ãƒ¥è¡¨ã‚’採用ã—ã¦ã„ã¾ã™ã€‚転置インデックスã®ã‚¤ãƒ¡ãƒ¼ã‚¸ã‚’例示ã—ã¾ã™ã€‚ファイル `penguin.txt' ã«ã¯ã€Œflightless marine birdsã€ã¨ã„ã†ãƒ†ã‚­ã‚¹ãƒˆãŒæ ¼ç´ã•ã‚Œã¦ã„ã¦ã€ãƒ•ã‚¡ã‚¤ãƒ« `ostrich.txt' ã«ã¯ã€ã€Œflightless birds in africaã€ã¨ã„ã†ãƒ†ã‚­ã‚¹ãƒˆãŒæ ¼ç´ã•ã‚Œã¦ã„ã‚‹ã¨ã—ã¾ã™ã€‚å„ファイルã«ã¯ã€èª­ã¿è¾¼ã‚“ã é †ç•ªã§IDã‚’ã¤ã‘ã‚‹ã“ã¨ã«ã—ã¾ã™ã€‚ã“れらを対象ã¨ã—ã¦è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’作æˆã™ã‚‹ã¨ã€ä»¥ä¸‹ã®ã‚ˆã†ã«ãªã‚Šã¾ã™ã€‚IDã¨ãƒ•ã‚¡ã‚¤ãƒ«åã®å¯¾å¿œã¥ã‘ã¯åˆ¥ã®ã€Œæ–‡æ›¸ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã€ã«ä¿å­˜ã—ã¦ãŠãã¾ã™ã€‚

+ + + + + + + +
flightless1,2
marine1
birds1,2
in2
africa2
+ +

ãã®æ¬¡ã«èª­ã¿è¾¼ã‚“ã æ–‡æ›¸ã«ã€Œbirdsã€ã¨ã„ã†å˜èªžãŒå«ã¾ã‚Œã¦ã„ãŸå ´åˆã«ã¯ã€`birds' ã®å€¤ã‚’ [1,2,3] ã«å¤‰æ›´ã™ã‚‹ã“ã¨ã«ãªã‚Šã¾ã™ã€‚ã“ã®ã‚ˆã†ã«ã€æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã®æœ«å°¾ã«ãƒ‡ãƒ¼ã‚¿ã‚’追加ã™ã‚‹ã¨ã„ã†æ“作ãŒé »ç¹ã«ç™ºç”Ÿã—ã¾ã™ã€‚ã“ã®å‡¦ç†ã‚’効率的ã«è¡Œã†ãŸã‚ã«ã€Depotã‚„Curiaã®æ›¸ãè¾¼ã¿æ“作ã«ã¯ã€Œé€£çµãƒ¢ãƒ¼ãƒ‰ã€ãŒã‚ã‚‹ã®ã§ã™ã€‚

+ +

検索時ã«ã¯ã€æ¤œç´¢èªžã‚’キーã«ã—ã¦å€¤ã®é…列をå–り出ã—ã€å€‹ã€…ã®IDã«å¯¾å¿œã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«åを文書データベースã‹ã‚‰å–り出ã—ã¦æ示ã™ã‚‹ã“ã¨ã«ãªã‚Šã¾ã™ã€‚ãŸã ã—該当ã®æ–‡æ›¸ãŒå¤šã„å ´åˆã«ãã®å…¨ã¦ã‚’æ示ã—ã¦ã‚‚ユーザã¯å›°æƒ‘ã™ã‚‹ã®ã§ã€å…ˆé ­ã®ä½•ä»¶ã‹ã«çµžã£ã¦å–り出ã—ã¾ã™ã€‚Depotã‚„Curiaã®èª­ã¿è¾¼ã¿æ“作ã§ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‹ã‚‰ç‰¹å®šã®éƒ¨åˆ†ã®ã¿ã‚’å–り出ã™ã“ã¨ãŒã§ãã‚‹ã®ã§ã€ã“ã®å‡¦ç†ã‚’効率良ãè¡Œã†ã“ã¨ãŒã§ãã¾ã™ã€‚実際ã¯ã€ãƒ•ã‚¡ã‚¤ãƒ«ã«ãŠã‘ã‚‹å˜èªžã®ã‚¹ã‚³ã‚¢ï¼ˆé‡è¦åº¦ï¼‰ã‚‚é…列è¦ç´ ã®ä¸€éƒ¨ã¨ã—ã¦æ ¼ç´ã—ã¦ãŠã„ã¦ã€ãれを基準ã«ã‚½ãƒ¼ãƒˆã—ã¦ãŠãã“ã¨ã«ã‚ˆã£ã¦ã€å…ˆé ­ã®è¦ç´ ãŒãƒ¦ãƒ¼ã‚¶ã«ã¨ã£ã¦æ„味ã®ã‚ã‚‹ã‚‚ã®ã«ã—ã¦ã„ã¾ã™ã€‚

+ +

ファイルã«ã¯åå‰ä»¥å¤–ã«ã‚‚ã€ã‚¿ã‚¤ãƒˆãƒ«ã‚„作者åや更新日時ã¨ã„ã£ãŸå±žæ€§ã‚’ã¤ã‘ãŸã„å ´åˆãŒã‚ã‚Šã¾ã™ã€‚ãれらã®æƒ…å ±ã¯æ–‡æ›¸ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ä¿å­˜ã—ã¾ã™ã€‚Odeumã§æ‰±ã†ãƒ•ã‚¡ã‚¤ãƒ«ï¼ˆä»¥å¾Œã¯æ–‡æ›¸ã¨å‘¼ã³ã¾ã™ï¼‰ã¯ã€ãƒ•ã‚¡ã‚¤ãƒ«åã®ä»£ã‚ã‚Šã«URIã‚’ã¤ã‘ã‚‹ã‚‚ã®ã¨ã—ã¦ã„ã¾ã™ã€‚URI以外ã®å±žæ€§ã¯ãƒ¦ãƒ¼ã‚¶ãŒãƒ©ãƒ™ãƒ«ã‚’ã¤ã‘ã¦ä»»æ„ã®ã‚‚ã®ã‚’æ ¼ç´ã§ãã¾ã™ã€‚

+ +

Odeumã¯ã€æ–‡æ›¸ã®ãƒ†ã‚­ã‚¹ãƒˆã‚„属性を元ã®ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰æŠ½å‡ºã™ã‚‹æ©Ÿèƒ½ã«ã¤ã„ã¦ã¯æä¾›ã—ã¾ã›ã‚“。ãれらã¯ãƒ‰ãƒ¡ã‚¤ãƒ³ã«å¼·ãä¾å­˜ã™ã‚‹ã®ã§ã€å…±é€šåŒ–ã™ã‚‹ã“ã¨ãŒé›£ã—ã„ã‹ã‚‰ã§ã™ã€‚ã—ãŸãŒã£ã¦ã€ã‚¢ãƒ—リケーションãŒãれを実装ã™ã‚‹å¿…è¦ãŒã‚ã‚Šã¾ã™ã€‚Odeumã®ã‚µãƒ³ãƒ—ルアプリケーションã¯ã€ãƒ­ãƒ¼ã‚«ãƒ«ã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚·ã‚¹ãƒ†ãƒ ã«ã‚るプレーンテキストã¨HTMLã‹ã‚‰ãƒ†ã‚­ã‚¹ãƒˆã¨å±žæ€§ã‚’抽出ã§ãã¾ã™ã€‚ã‚ãªãŸã®ã‚¢ãƒ—リケーションã§ã¯ã€PDFã‚„MS-Wordã®æ–‡æ›¸ã«å¯¾å¿œã™ã‚‹ã®ã‚‚よã„ã§ã—ょã†ã€‚Webã‹ã‚‰æ–‡æ›¸ã‚’å–å¾—ã—ã¦ã‚‚よã„ã§ã—ょã†ã€‚åŒã˜ç†ç”±ã‹ã‚‰ã€Odeumã¯ãƒ†ã‚­ã‚¹ãƒˆã‹ã‚‰å˜èªžã‚’抽出ã™ã‚‹æ©Ÿèƒ½ã«ã¤ã„ã¦ã‚‚æä¾›ã—ã¾ã›ã‚“。英語ã¨æ—¥æœ¬èªžã§ã¯å…¨ãç•°ãªã‚‹æ‰‹æ³•ã§ãƒ†ã‚­ã‚¹ãƒˆã®è§£æžã‚’ã—ãªã‘ã‚Œã°ãªã‚Šã¾ã›ã‚“ãŒã€ãã†ã„ã£ãŸã“ã¨ã‚‚アプリケーションã«ä»»ã•ã‚Œã¾ã™ã€‚Odeumã®ã‚µãƒ³ãƒ—ルアプリケーションã§ã¯ã€å˜ã«ç©ºç™½ã§èªžã‚’区切るã¨ã„ã†æ‰‹æ³•ã‚’ã¨ã£ã¦ã„ã¾ã™ã€‚ã‚ãªãŸã®ã‚¢ãƒ—リケーションã§ã¯ã€æ—¥æœ¬èªžã®å½¢æ…‹ç´ è§£æžã‚’è¡Œã†ã®ã‚‚よã„ã§ã—ょã†ã€‚英å˜èªžã®ã‚¹ãƒ†ãƒŸãƒ³ã‚°å‡¦ç†ã‚’è¡Œã£ã¦ã‚‚よã„ã§ã—ょã†ã€‚

+ +

多ãã®è¨€èªžã§ã¯ã€åŒã˜å˜èªžã«å¯¾ã—ã¦ç•°ä½“や活用ãŒå­˜åœ¨ã—ã¾ã™ã€‚例ãˆã°ã€Œä½¿ã†/使ã£ï¼ˆãŸï¼‰ã€ã€Œgo/wentã€ã€Œchild/childrenã€ãªã©ã§ã™ã€‚ãã“ã§ã€Odeumã¯å„å˜èªžã‚’「正è¦å½¢ã€ãŠã‚ˆã³ã€Œå‡ºç¾å½¢ã€ã®çµ„ã¨ã—ã¦æ‰±ã„ã¾ã™ã€‚テキストã‹ã‚‰å‡ºç¾å½¢ã®å˜èªžã‚’切り出ã—ãŸã‚Šã€ãれらã®æ­£è¦å½¢ã‚’生æˆã™ã‚‹å‡¦ç†ã¯ã‚¢ãƒ—リケーションã«ä»»ã•ã‚Œã¾ã™ã€‚転置インデックスã§ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã«ã¯æ­£è¦å½¢ãŒä½¿ã‚ã‚Œã¾ã™ã€‚「childã€ã§æ¤œç´¢ã™ã‚Œã°ã€ã€Œchildrenã€ã‚’å«ã‚€æ–‡æ›¸ã‚‚該当ã•ã›ã‚‰ã‚Œã‚‹ã¨ã„ã†ã“ã¨ã§ã™ã€‚検索語ã«å¯¾ã—ã¦ã‚‚æ­£è¦åŒ–ã®å‡¦ç†ã‚’è¡Œãˆã°ã€ã€Œchildrenã€ã§æ¤œç´¢ã—ã¦ã€Œchildã€ã‚’該当ã«ã§ãã¾ã™ã€‚ãªãŠã€å‡ºç¾å½¢ã‚‚データベースã«è¨˜éŒ²ã•ã‚Œã¾ã™ãŒã€ãã‚Œã¯æ¤œç´¢çµæžœã¨ã—ã¦æ–‡æ›¸ã®è¦ç´„ã‚’æ示ã™ã‚‹ãªã©ã®ç”¨é€”ã§åˆ©ç”¨ã•ã‚Œã¾ã™ï¼ˆä¸è¦ãªå ´åˆã¯å‡ºç¾å½¢ã‚’å…¨ã¦ç©ºæ–‡å­—列ã«ã—ã¦è¨˜æ†¶é ˜åŸŸã‚’節約ã§ãã¾ã™ï¼‰ã€‚

+ +

全文検索システムã®å–„ã—悪ã—を評価ã™ã‚‹éš›ã«ã¯ã€ã‚¹ã‚³ã‚¢ãƒªãƒ³ã‚°ï¼ˆãƒ©ãƒ³ã‚­ãƒ³ã‚°ï¼‰ãŒé‡è¦ãªè¦ç´ ã«ãªã‚Šã¾ã™ã€‚検索çµæžœãŒå¤šã„å ´åˆã«ã€ãã®ä¸­ã‹ã‚‰çµžã‚Šè¾¼ã‚“ã§ãƒ¦ãƒ¼ã‚¶ã«æ示ã™ã‚‹æ–‡æ›¸ã‚’ã©ã†ã‚„ã£ã¦é¸æŠžã™ã‚‹ã‹ã¨ã„ã†ã“ã¨ã§ã™ã€‚ã„ãら検索速度ãŒé€Ÿãã¦ã‚‚ã€æº€è¶³ã®ã„ã検索çµæžœãŒæ示ã•ã‚Œãšã«ä½•åº¦ã‚‚検索ã—ãŸã‚Šã€ç„¡é§„ãªæ–‡æ›¸ã‚’閲覧ã—ãªã‘ã‚Œã°ãªã‚‰ãªã„ã®ã§ã¯ã€çµå±€ã¯æ™‚é–“ãŒã‹ã‹ã‚‹ã“ã¨ã«ãªã£ã¦ã—ã¾ã„ã¾ã™ã€‚Odeumã§ã¯ã€æ–‡æ›¸ã‚’登録ã™ã‚‹éš›ã«ã€ãã“ã«å«ã¾ã‚Œã‚‹å„å˜èªžã«ã¤ã„ã¦ä»¥ä¸‹ã®å¼ã§ã‚¹ã‚³ã‚¢ã‚’算出ã—ã¦ã€æ–‡æ›¸IDã¨ã¨ã‚‚ã«è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã«æ ¼ç´ã—ã¦ã„ã¾ã™ã€‚

+ +
スコア = (該当語ã®å‡ºç¾æ•° * 10000) / log(文書内ã®ç·èªžæ•°) ^ 3
+ +

ã‚ã‚‹å˜èªžãŒãŸãã•ã‚“出ç¾ã™ã‚‹ã¨ã„ã†ã“ã¨ã¯ã€ãã®æ–‡æ›¸ã§ãã®å˜èªžã®ã“ã¨ã«ã¤ã„ã¦è©³ã—ã説明ã•ã‚Œã¦ã„ã‚‹å¯èƒ½æ€§ãŒé«˜ã„ã¨åˆ¤æ–­ã§ãã¾ã™ã€‚ãŸã ã—ã€å¤§ããªæ–‡æ›¸ã¯å°ã•ã„文書よりもå˜èªžã®å‡ºç¾æ•°ãŒå¤šããªã‚Šã¾ã™ã®ã§ã€ãã®èª¿æ•´ã‚’ã™ã‚‹å¿…è¦ãŒã‚ã‚Šã¾ã™ã€‚ãã“ã§ã€è©²å½“語ã®å‡ºç¾æ•°ã‚’ã€ç·èªžæ•°ã®è‡ªç„¶å¯¾æ•°ã®ä¸‰ä¹—ã§å‰²ã£ã¦ã„ã‚‹ã®ã§ã™ã€‚ãªãŠã€ãƒ†ã‚­ã‚¹ãƒˆã®å…ˆé ­10%以内ã«å‡ºã¦æ¥ã‚‹å˜èªžã¯ã€Œãƒˆãƒ”ックセンテンスã€ã‚’構æˆã™ã‚‹ã¨ã¿ãªã—ã¦ã€åˆå‡ºæ™‚ã«é™ã‚Š10000ã§ãªã15000を加算ã—ã¦ã„ã¾ã™ã€‚

+ +

全文検索ã¯é€šå¸¸ã€è¤‡æ•°ã®æ¤œç´¢èªžã‚’使ã£ã¦è¡Œã‚ã‚Œã¾ã™ã€‚ãã®éš›ã«ã¯ã€å„検索語ã®ã‚¹ã‚³ã‚¢ã‚’調整ã—ãªã„ã¨ã€ç‰¹å®šã®æ¤œç´¢èªžã®ã‚¹ã‚³ã‚¢ã®å½±éŸ¿ãŒå¼·ã™ãŽã‚‹ã¨ã„ã†äº‹æ…‹ãŒç™ºç”Ÿã—ã¾ã™ã€‚例ãˆã°ã€Œthe beatlesã€ã§æ¤œç´¢ã—ãŸå ´åˆã€ã€Œtheã€ã®ã‚¹ã‚³ã‚¢ãŒã€Œbeatlesã€ã®ã‚¹ã‚³ã‚¢ã‚’圧倒ã—ã¦ã€ã€Œbeatlesã€ã«ã¤ã„ã¦çŸ¥ã‚ŠãŸã„ã®ã«ã€é–¢ä¿‚ãªã„文書ã°ã‹ã‚ŠãŒæ示ã•ã‚Œã‚‹ã“ã¨ã«ãªã£ã¦ã—ã¾ã„ã¾ã™ã€‚Odeumã¯è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®å†…容をæ示ã™ã‚‹ã ã‘ã§ã€ãれ以後ã®å‡¦ç†ã¯ã‚¢ãƒ—リケーションã«ä»»ã•ã‚Œã¾ã™ã€‚Odeumã«ä»˜å±žã™ã‚‹ã‚µãƒ³ãƒ—ルアプリケーションã§ã¯ä»¥ä¸‹ã®å¼ã§èª¿æ•´ã‚’è¡Œã£ã¦ã„ã¾ã™ã€‚

+ +
調整済ã¿ã‚¹ã‚³ã‚¢ = 登録ã•ã‚ŒãŸã‚¹ã‚³ã‚¢ / log(ãã®èªžã‚’å«ã‚€æ–‡æ›¸æ•°) ^ 2
+ +

ã‚ã‚Šãµã‚ŒãŸå˜èªžã¯ã‚¹ã‚³ã‚¢ã‚’下ã’ã€ç‰¹å¾´çš„ãªå˜èªžã¯ã‚¹ã‚³ã‚¢ã‚’維æŒã™ã¹ãã§ã™ã€‚ãã“ã§ã€ç™»éŒ²ã•ã‚ŒãŸã‚¹ã‚³ã‚¢ã‚’ã€ãã®èªžã‚’å«ã‚€æ–‡æ›¸æ•°ã®è‡ªç„¶å¯¾æ•°ã®äºŒä¹—ã§å‰²ã£ã¦ã„ã‚‹ã®ã§ã™ï¼ˆTF-IDF法を強化ã—ãŸã‚‚ã®ã§ã™ï¼‰ã€‚å„検索語ã®èª¿æ•´æ¸ˆã¿ã‚¹ã‚³ã‚¢ã‚’足ã—ãŸã‚‚ã®ã‚’文書ã®ã‚¹ã‚³ã‚¢ã¨ã—ã€ãã®é™é †ã§æ¤œç´¢çµæžœã‚’æ示ã—ã¾ã™ã€‚ä»–ã«ã‚‚ドメインã«ä¾å­˜ã—ãŸæ§˜ã€…ãªã‚¹ã‚³ã‚¢ãƒªãƒ³ã‚°æ‰‹æ³•ãŒã‚ã‚‹ã¨æ€ã„ã¾ã™ãŒã€ã‚¢ãƒ—リケーションãŒãれを実装ã§ãã‚‹ã®ãŒå¬‰ã—ã„ã¨ã“ã‚ã§ã™ã€‚

+ +

Odeumã®ã‚µãƒ³ãƒ—ルアプリケーションã§ã¯ã€é–¢é€£æ–‡æ›¸æ¤œç´¢ï¼ˆé¡žä¼¼æ–‡æ›¸æ¤œç´¢ã¨å‘¼ã‚“ã æ–¹ãŒé©åˆ‡ã‹ã‚‚ã—ã‚Œã¾ã›ã‚“)ã®æ©Ÿèƒ½ã‚‚実装ã—ã¦ã„ã¾ã™ã€‚ã‚る文書(種文書ã¨å‘¼ã³ã¾ã™ï¼‰ã«é–¢é€£ã—ãŸæ–‡æ›¸ã®ä¸€è¦§ã‚’æ示ã™ã‚‹ã‚‚ã®ã§ã™ã€‚å˜èªžã®å‡ºç¾å‚¾å‘ãŒä¼¼é€šã£ãŸæ–‡æ›¸ã¯äº’ã„ã«é–¢é€£ã—ã¦ã„ã‚‹ã¨ã„ã†è€ƒãˆæ–¹ï¼ˆãƒ™ã‚¯ãƒˆãƒ«ç©ºé–“モデル)ã«åŸºã¥ã„ã¦ã„ã¾ã™ã€‚文書をデータベースã«ç™»éŒ²ã™ã‚‹éš›ã«ã¯ã€å„文書ã«å«ã¾ã‚Œã‚‹å…¨å˜èªžã«å¯¾ã—ã¦èª¿æ•´æ¸ˆã¿ã‚¹ã‚³ã‚¢ã‚’計算ã—ã€ãã®ä¸Šä½32語(キーワードã¨å‘¼ã³ã¾ã™ï¼‰ã®æƒ…報を文書ã¨å¯¾å¿œã¥ã‘ã¦ç™»éŒ²ã—ã¦ãŠãã¾ã™ã€‚検索時ã«ã¯ã€ç¨®æ–‡æ›¸ã®ã‚­ãƒ¼ãƒ¯ãƒ¼ãƒ‰ã¨ã‚¹ã‚³ã‚¢ã‚’å–り出ã—ã€ãれを32次元ã®ãƒ™ã‚¯ãƒˆãƒ«ã¨ã—ã¦è¡¨ç¾ã—ã¾ã™ã€‚関連度を判定ã™ã‚‹å¯¾è±¡ã®å„文書ã‹ã‚‰ã‚‚キーワードã¨ã‚¹ã‚³ã‚¢ã‚’å–り出ã—ã€ç¨®æ–‡æ›¸ã®ãƒ™ã‚¯ãƒˆãƒ«ç©ºé–“ã«å¯¾å¿œã—ãŸãƒ™ã‚¯ãƒˆãƒ«ã‚’生æˆã—ã¾ã™ã€‚ãã†ã—ã¦ã§ããŸäºŒã¤ã®ãƒ™ã‚¯ãƒˆãƒ«ã®ãªã™è§’ãŒå°ã•ã„ã‚‚ã®ã¯é–¢é€£åº¦ãŒé«˜ã„ã¨åˆ¤å®šã—ã¾ã™ã€‚実際ã«ã¯ã€ãªã™è§’ã®ä½™å¼¦ï¼ˆ0ã‹ã‚‰1ã®ç¯„囲ã§ã€å®Œå…¨ä¸€è‡´ã™ã‚‹å ´åˆã¯1ã«ãªã‚‹ï¼‰ãŒå¤§ãã„ã‚‚ã®ã‹ã‚‰æ示ã•ã‚Œã‚‹ã“ã¨ã«ãªã‚Šã¾ã™ã€‚ãªãŠã€ç™»éŒ²ã•ã‚ŒãŸå…¨ã¦ã®æ–‡æ›¸ã‚’対象ã¨ã—ã¦é¡žä¼¼åº¦ã®åˆ¤å®šã‚’è¡Œã†ã¨ã‚ã¾ã‚Šã«æ™‚é–“ãŒã‹ã‹ã‚‹ã®ã§ã€ã‚­ãƒ¼ãƒ¯ãƒ¼ãƒ‰ã§OR検索を行ã£ãŸçµæžœã®ä¸Šä½ã®æ–‡æ›¸ã®ã¿ã‚’関連度算出ã®å¯¾è±¡ã¨ã—ã¦ã„ã¾ã™ã€‚

+ +

å‰ç½®ãã¯ã“ã“ã¾ã§ã«ã—ã¦ã€Odeumã®ä½¿ç”¨æ–¹æ³•ã«ã¤ã„ã¦ã®èª¬æ˜Žã«å…¥ã‚Šã¾ã™ã€‚URI㌠`http://tako.ika/uni.txt' ã§ã€ãã“ã‹ã‚‰å–り出ã—ãŸãƒ†ã‚­ã‚¹ãƒˆãŒã€ŒThe sun is driven by the Grateful Dead.ã€ã§ã€åˆ‡ã‚Šå‡ºã—ãŸå˜èªžï¼ˆæ­£è¦å½¢/出ç¾å½¢ï¼‰ãŒã€Œthe/Theã€ã€Œsun/sunã€ã€Œbe/isã€ã€Œdrive/drivenã€ã€Œby/byã€ã€Œthe/theã€ã€Œgrateful/Gratefulã€ã€Œdie/deadã€ã€Œï¼ˆæ­£è¦å½¢ãªã—)/.ã€ã ã¨ã—ã¾ã—ょã†ï¼ˆã“ã®å‡¦ç†ã¯ã‚¢ãƒ—リケーションãŒç‹¬è‡ªã«å®Ÿè£…ã—ã¦ãã ã•ã„)(ã„ã‚ゆるストップワードã¯æ­£è¦å½¢ã‚’空文字列ã«ã—ã¦è¡¨ç¾ã—ã¾ã™ï¼‰ã€‚ãれを `index' ã¨ã„ã†åå‰ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ç™»éŒ²ã™ã‚‹ä¾‹ã‚’示ã—ã¾ã™ã€‚

+ +
#include <depot.h>
+#include <cabin.h>
+#include <odeum.h>
+#include <stdlib.h>
+
+int docregistertest(void){
+  ODEUM *odeum;
+  ODDOC *doc;
+  /* データベースを開ã */
+  if(!(odeum = odopen("index", OD_OWRITER | OD_OCREAT))) return -1;
+  /* 文書を表ç¾ã™ã‚‹ */
+  doc = oddocopen("http://tako.ika/uni.txt");
+  oddocaddword(doc, "the", "the");
+  oddocaddword(doc, "sun", "sun");
+  oddocaddword(doc, "be", "is");
+  oddocaddword(doc, "drive", "driven");
+  oddocaddword(doc, "by", "by");
+  oddocaddword(doc, "the", "the");
+  oddocaddword(doc, "grateful", "Grateful");
+  oddocaddword(doc, "die", "Dead");
+  oddocaddword(doc, "", ".");
+  /* 文書を登録ã™ã‚‹ */
+  odput(odeum, doc, -1, 1);
+  /* 文書ã®é ˜åŸŸã‚’解放ã™ã‚‹ */
+  oddocclose(doc);
+  /* データベースを閉ã˜ã‚‹ */
+  if(!odclose(odeum)) return -1;
+  return 0;
+}
+
+ +

`ODEUM' ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã¯ä¾‹ã«ã‚ˆã£ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã§ã™ã€‚`odopen' ã§ãã®ãƒãƒ³ãƒ‰ãƒ«ã‚’ç²å¾—ã—ã¾ã™ã€‚é–‹ã„ãŸãƒãƒ³ãƒ‰ãƒ«ã¯ `odclose' ã§é–‰ã˜ã¾ã™ã€‚`ODDOC' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã§ã™ã€‚å„文書ã®å†…容ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã«ã‚ˆã£ã¦è¡¨ç¾ã•ã‚Œã¾ã™ã€‚`oddocopen' ã¯ãƒãƒ³ãƒ‰ãƒ«ã‚’é–‹ã関数ã§ã™ã€‚ãã®ç¬¬1引数ã§æ–‡æ›¸ã®URIを指定ã—ã¾ã™ã€‚文書ãƒãƒ³ãƒ‰ãƒ«ã¯ä¸è¦ã«ãªã£ãŸã‚‰ `oddocclose' ã§è§£æ”¾ã—ã¾ã™ã€‚テキストã®å„å˜èªžã‚’文書ã«ç™»éŒ²ã™ã‚‹ã«ã¯ã€`oddocaddword' を用ã„ã¾ã™ã€‚ãã®ç¬¬2引数ã¯å˜èªžã®æ­£è¦å½¢ã§ã€ç¬¬3引数ã¯å‡ºç¾å½¢ã§ã™ã€‚文書を表ç¾ã—ãŸã‚‰ã€ãれを `odput' ã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ç™»éŒ²ã—ã¾ã™ã€‚第3引数ã¯ã€æ–‡æ›¸ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ç™»éŒ²ã™ã‚‹èªžæ•°ã‚’指定ã—ã¾ã™ã€‚`-1' ã«ã™ã‚‹ã¨å…¨éƒ¨ã®èªžãŒç™»éŒ²ã•ã‚Œã¾ã™ã€‚第4引数ã¯ã€åŒã˜URIã®æ—¢å­˜ã®æ–‡æ›¸ãŒã‚ã‚‹å ´åˆã«ã€ãれを上書ãã™ã‚‹ã‹å¦ã‹æŒ‡å®šã—ã¾ã™ã€‚

+ +

`odput' ã®ç¬¬3引数ã®æŒ‡å®šãŒå°‘ã—難ã—ã„ã®ã§è£œè¶³ã—ã¾ã™ã€‚ã‚る文書ãŒé©åˆ‡ã«æ¤œç´¢ã•ã‚Œã‚‹ãŸã‚ã«ã€è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã«ãŠã„ã¦ã€ãã®æ–‡æ›¸ã«å«ã¾ã‚Œã‚‹å…¨ã¦ã®å˜èªžã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã«ãã®æ–‡æ›¸ã®IDãŒç„¡æ¡ä»¶ã§è¿½åŠ ã•ã‚Œã¾ã™ã€‚ã¨ã“ã‚ã§ã€å¤šãã®å…¨æ–‡æ¤œç´¢ã‚·ã‚¹ãƒ†ãƒ ã§ã¯ã€æ¤œç´¢çµæžœã®ç”»é¢ã§è©²å½“ã®æ–‡æ›¸ã®è¦ç´„を表示ã—ã¾ã™ã€‚ãã®ãŸã‚ã«ã¯ã€æ–‡æ›¸ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ä¸­ã«ã€å„文書ã¨é–¢é€£ã¥ã‘ã¦å«ã¾ã‚Œã‚‹å˜èªžã‚’順番ã«è¨˜éŒ²ã—ã¦ãŠãå¿…è¦ãŒã‚ã‚Šã¾ã™ã€‚検索語ã®å‘¨è¾ºã®æ–‡ã‚’切り出ã—ã¦è¡¨ç¤ºã™ã‚‹å ´åˆã‚’考ãˆã‚‹ã¨ã€æ¤œç´¢èªžãŒæ–‡æ›¸ä¸­ã®ã©ã“ã«ç¾ã‚Œã‚‹ã‹ã¯äºˆæƒ³ã§ããªã„ã®ã§ã€å…¨ã¦ã®å˜èªžã‚’文書データベースã«è¨˜éŒ²ã—ã¦ãŠã‹ãªã‘ã‚Œã°ãªã‚Šã¾ã›ã‚“。ã‚ã‚‹ã„ã¯ã€å†’é ­ã®ä½•èªžã‹ã ã‘表示ã™ã‚‹å ´åˆã«ã¯ã€ãã®èªžæ•°åˆ†ã®èªžã‚’登録ã—ã¦ãŠã‘ã°ã‚ˆã„ã“ã¨ã«ãªã‚Šã¾ã™ã€‚ãã†ã„ã£ãŸæ±ºå®šã‚’アプリケーションã«ä»»ã›ã‚‹ãŸã‚ã«ã€æ–‡æ›¸ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ç™»éŒ²ã™ã‚‹èªžæ•°ã‚’指定ã§ãるよã†ã«ãªã£ã¦ã„ã‚‹ã®ã§ã™ã€‚

+ +

以下ã®ä¾‹ã§ã¯ã€`grateful' ã¨ã„ã†å˜èªžã‚’å«ã‚€æ–‡æ›¸ã‚’検索ã—ã¦ã€ãã®URIã¨ã‚¹ã‚³ã‚¢ã‚’表示ã—ã¾ã™ã€‚ã¾ãšè»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’検索ã—ã¦çµæžœã®é…列をå—ã‘å–ã‚Šã¾ã™ã€‚ãã®é…列ã®å„è¦ç´ ã¯æ–‡æ›¸ã®IDã¨ã‚¹ã‚³ã‚¢ã®çµ„ã§ã™ã€‚文書ã®å†…容をå–å¾—ã™ã‚‹ã«ã¯ã€æ–‡æ›¸IDを使ã£ã¦æ–‡æ›¸ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«å•ã„åˆã‚ã›ã¾ã™ã€‚

+ +
#include <depot.h>
+#include <cabin.h>
+#include <odeum.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void docsearchtest(void){
+  ODEUM *odeum;
+  ODPAIR *pairs;
+  ODDOC *doc;
+  int i, pnum;
+  /* データベースを読ã¿è¾¼ã¿ãƒ¢ãƒ¼ãƒ‰ã§é–‹ã */
+  if(!(odeum = odopen("index", OD_OREADER))) return;
+  /* 転置インデックスを検索ã™ã‚‹ */
+  pairs = odsearch(odeum, "grateful", -1, &pnum);
+  if(pairs && pnum > 0){
+    /* 該当ã®å„文書を処ç†ã™ã‚‹ */
+    for(i = 0; i < pnum; i++){
+      /* 文書データベースã‹ã‚‰æ–‡æ›¸ã‚’å–り出㙠*/
+      if(!(doc = odgetbyid(odeum, pairs[i].id))) continue;
+      /* 文書ã®å†…容を表示ã™ã‚‹ */
+      printf("URI: %s\n", oddocuri(doc));
+      printf("SCORE: %d\n", pairs[i].score);
+      /* 文書ã®é ˜åŸŸã‚’解放ã™ã‚‹ */
+      oddocclose(doc);
+    }
+  }
+  /* 検索çµæžœã®é ˜åŸŸã‚’解放ã™ã‚‹ */
+  free(pairs);
+  /* データベースを閉ã˜ã‚‹ */
+  odclose(odeum);
+}
+
+ +

転置インデックスを検索ã™ã‚‹ã®ãŒ `odsearch' ã¨ã„ã†é–¢æ•°ã§ã™ã€‚第2引数ã«ã¯æ­£è¦å½¢ã®æ¤œç´¢èªžã‚’指定ã—ã¾ã™ã€‚第3引数ã«ã¯ã€æ¤œç´¢ã™ã‚‹æ–‡æ›¸ã®æœ€å¤§æ•°ã‚’指定ã—ã¾ã™ãŒã€å…¨éƒ¨å–り出ã™å ´åˆã¯ `-1' ã¨ã—ã¾ã™ã€‚çµæžœã®é…列ã¯ã‚¹ã‚³ã‚¢ã®é™é †ã§ã‚½ãƒ¼ãƒˆã•ã‚Œã¦ã„ã‚‹ã“ã¨ãŒè¦å®šã•ã‚Œã¦ã„ã¾ã™ã€‚第4引数ã«ã¯ã€çµæžœã®é…列ã®è¦ç´ æ•°ã‚’æ ¼ç´ã™ã‚‹å¤‰æ•°ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã—ã¾ã™ã€‚次ã«ã€é…列ã®å„è¦ç´ ã‚’処ç†ã—ã¦ã„ãã¾ã™ã€‚`odgetbyid' ã¯æ–‡æ›¸IDを用ã„ã¦æ–‡æ›¸ã®å†…容をå•ã„åˆã‚ã›ã‚‹é–¢æ•°ã§ã™ã€‚転置インデックスã®ä¸­ã«ã¯æ—¢ã«å‰Šé™¤ã•ã‚ŒãŸã‚Šä¸Šæ›¸ãã•ã‚Œã¦IDãŒå¤‰æ›´ã•ã‚ŒãŸæ–‡æ›¸ã®æƒ…報も入ã£ã¦ã„ã‚‹ã®ã§ï¼ˆæœ€é©åŒ–ã™ã‚Œã°ä¸è¦ãªæƒ…å ±ã¯ãªããªã‚Šã¾ã™ãŒï¼‰ã€`odgetbyid' ã¯å¤±æ•—ã™ã‚‹å¯èƒ½æ€§ãŒã‚ã‚Šã¾ã™ã€‚ãã†ã„ã†æ™‚ã¯å˜ã«ç„¡è¦–ã—ã¦æ¬¡ã®ãƒ«ãƒ¼ãƒ—ã«é€²ã‚“ã§ãã ã•ã„。文書ãŒå–å¾—ã§ããŸã‚‰ã€ã‚ã¨ã¯ãれを表示ã—ã¾ã™ã€‚`oddocuri' ã¯æ–‡æ›¸ã®URIã‚’è¿”ã™é–¢æ•°ã§ã™ã€‚ä»–ã«ã‚‚文書ã®æƒ…報をå–å¾—ã™ã‚‹é–¢æ•°ãŒã„ãã¤ã‹ç”¨æ„ã•ã‚Œã¦ã„ã¾ã™ã€‚

+ +

Odeumã§ã¯ã€è¤‡æ•°ã®æ¤œç´¢èªžã‚’用ã„ã¦ã€ANDæ¡ä»¶ï¼ˆæ¤œç´¢èªžã®å…¨ã¦ã‚’å«ã‚€ï¼‰ã‚„ORæ¡ä»¶ï¼ˆæ¤œç´¢èªžã®ã„ãšã‚Œã‹ã‚’å«ã‚€ï¼‰ã‚„NOTANDæ¡ä»¶ï¼ˆæ¤œç´¢èªžã®å‰è€…ã‚’å«ã‚€ãŒå¾Œè€…ã¯å«ã¾ãªã„)ã¨ã„ã£ãŸé›†åˆæ¼”算を処ç†ã™ã‚‹ãŸã‚ã®é–¢æ•°ãŒç”¨æ„ã•ã‚Œã¦ã„ã‚‹ã»ã‹ã€å…¨æ–‡æ¤œç´¢ã‚·ã‚¹ãƒ†ãƒ ã®å®Ÿè£…ã«ä¾¿åˆ©ãªãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£é–¢æ•°ãŒå¤šæ•°æä¾›ã•ã‚Œã¾ã™ã€‚全文検索システムを実装ã™ã‚‹éš›ã«ã¯æ€§èƒ½ã¨ç²¾åº¦ã®ãƒãƒ©ãƒ³ã‚¹ã‚’考ãˆãªã‘ã‚Œã°ãªã‚Šã¾ã›ã‚“ãŒã€Odeumã®APIã¯ã‚¢ãƒ—リケーションãŒãれを任æ„ã«æ±ºã‚られるよã†ã«è¨­è¨ˆã•ã‚Œã¦ã„ã¾ã™ã€‚大è¦æ¨¡ãªã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’扱ã†éš›ã«ã¯ã€ã¾ãšç²¾åº¦ã‚’è½ã—ãŸæ¤œç´¢ã‚’è¡Œã£ã¦ã€ãã®çµæžœãŒãƒ¦ãƒ¼ã‚¶ã®è¦æ±‚を満ãŸã•ãªã‘ã‚Œã°ç²¾åº¦ã‚’高ã‚ãŸãƒ‘ラメータã§å†æ¤œç´¢ã™ã‚‹æ‰‹æ³•ãŒæœ‰åŠ¹ã§ã—ょã†ã€‚

+ +
+ + + + + + diff --git a/qdbm/misc/win32check.bat b/qdbm/misc/win32check.bat new file mode 100644 index 00000000..63dae180 --- /dev/null +++ b/qdbm/misc/win32check.bat @@ -0,0 +1,111 @@ +dptest write casket 50000 5000 +if errorlevel 1 goto error +dptest read casket +if errorlevel 1 goto error +dptest read -wb casket +if errorlevel 1 goto error +dptest rcat casket 50000 50 500 32 32 +if errorlevel 1 goto error +dptest combo casket +if errorlevel 1 goto error +dptest wicked casket 5000 +if errorlevel 1 goto error +del /Q casket + +crtest write casket 50000 500 10 +if errorlevel 1 goto error +crtest read casket +if errorlevel 1 goto error +crtest read -wb casket +if errorlevel 1 goto error +crtest rcat casket 50000 5 10 500 32 32 +if errorlevel 1 goto error +crtest combo casket +if errorlevel 1 goto error +crtest wicked casket 5000 +if errorlevel 1 goto error +rd /S /Q casket + +crtest write -lob casket 1000 50 10 +if errorlevel 1 goto error +crtest read -lob casket +if errorlevel 1 goto error +rd /S /Q casket + +rltest write casket 50000 +if errorlevel 1 goto error +rltest read casket 50000 +if errorlevel 1 goto error +del /Q casket* + +hvtest write casket 50000 +if errorlevel 1 goto error +hvtest read casket 50000 +if errorlevel 1 goto error +del /Q casket + +hvtest write -qdbm casket 50000 +if errorlevel 1 goto error +hvtest read -qdbm casket 50000 +if errorlevel 1 goto error +rd /S /Q casket + +cbtest sort 5000 +if errorlevel 1 goto error +cbtest strstr 500 +if errorlevel 1 goto error +cbtest list 50000 +if errorlevel 1 goto error +cbtest map 50000 +if errorlevel 1 goto error +cbtest wicked 5000 +if errorlevel 1 goto error +cbtest misc +if errorlevel 1 goto error + +vltest write -tune 25 64 32 32 casket 50000 +if errorlevel 1 goto error +vltest read casket +if errorlevel 1 goto error +vltest rdup -tune 25 64 256 256 casket 50000 50000 +if errorlevel 1 goto error +vltest combo casket +if errorlevel 1 goto error +vltest wicked casket 5000 +if errorlevel 1 goto error +del /Q casket + +vltest write -int -cz -tune 25 64 32 32 casket 50000 +if errorlevel 1 goto error +vltest read -int casket +if errorlevel 1 goto error +vltest rdup -int -cz -tune 25 64 256 256 casket 50000 50000 +if errorlevel 1 goto error +vltest combo -cz casket +if errorlevel 1 goto error +vltest wicked -cz casket 5000 +if errorlevel 1 goto error +del /Q casket + +odtest write casket 500 50 5000 +if errorlevel 1 goto error +odtest read casket +if errorlevel 1 goto error +odtest combo casket +if errorlevel 1 goto error +odtest wicked casket 500 +if errorlevel 1 goto error +rd /S /Q casket + +@echo off +echo #================================ +echo # SUCCESS +echo #================================ +goto :EOF + +:error +@echo off +echo #================================ +echo # ERROR +echo #================================ +goto :EOF diff --git a/qdbm/myconf.c b/qdbm/myconf.c new file mode 100644 index 00000000..1d1f7a7c --- /dev/null +++ b/qdbm/myconf.c @@ -0,0 +1,1113 @@ +/************************************************************************************************* + * Emulation of system calls + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include "myconf.h" + + + +/************************************************************************************************* + * for dosish filesystems + *************************************************************************************************/ + + +#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || defined(_SYS_CYGWIN_) + + +#define DOSPATHBUFSIZ 8192 + + +int _qdbm_win32_lstat(const char *pathname, struct stat *buf){ + char pbuf[DOSPATHBUFSIZ], *p; + int inode; + if(stat(pathname, buf) == -1) return -1; + if(GetFullPathName(pathname, DOSPATHBUFSIZ, pbuf, &p) != 0){ + inode = 11003; + for(p = pbuf; *p != '\0'; p++){ + inode = inode * 31 + *(unsigned char *)p; + } + buf->st_ino = (inode * 911) & 0x7FFF; + } + return 0; +} + + +#endif + + + +/************************************************************************************************* + * for POSIX thread + *************************************************************************************************/ + + +#if defined(MYPTHREAD) + + +#include + + +#define PTKEYMAX 8 + + +struct { void *ptr; pthread_key_t key; } _qdbm_ptkeys[PTKEYMAX]; +int _qdbm_ptknum = 0; + + +static void *_qdbm_gettsd(void *ptr, int size, const void *initval); + + +void *_qdbm_settsd(void *ptr, int size, const void *initval){ + static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + char *val; + if((val = _qdbm_gettsd(ptr, size, initval)) != NULL) return val; + if(pthread_mutex_lock(&mutex) != 0) return NULL; + if((val = _qdbm_gettsd(ptr, size, initval)) != NULL){ + pthread_mutex_unlock(&mutex); + return val; + } + if(_qdbm_ptknum >= PTKEYMAX){ + pthread_mutex_unlock(&mutex); + return NULL; + } + _qdbm_ptkeys[_qdbm_ptknum].ptr = ptr; + if(pthread_key_create(&(_qdbm_ptkeys[_qdbm_ptknum].key), free) != 0){ + pthread_mutex_unlock(&mutex); + return NULL; + } + if(!(val = malloc(size))){ + pthread_key_delete(_qdbm_ptkeys[_qdbm_ptknum].key); + pthread_mutex_unlock(&mutex); + return NULL; + } + memcpy(val, initval, size); + if(pthread_setspecific(_qdbm_ptkeys[_qdbm_ptknum].key, val) != 0){ + free(val); + pthread_key_delete(_qdbm_ptkeys[_qdbm_ptknum].key); + pthread_mutex_unlock(&mutex); + return NULL; + } + _qdbm_ptknum++; + pthread_mutex_unlock(&mutex); + return val; +} + + +static void *_qdbm_gettsd(void *ptr, int size, const void *initval){ + char *val; + int i; + for(i = 0; i < _qdbm_ptknum; i++){ + if(_qdbm_ptkeys[i].ptr == ptr){ + if(!(val = pthread_getspecific(_qdbm_ptkeys[i].key))){ + if(!(val = malloc(size))) return NULL; + memcpy(val, initval, size); + if(pthread_setspecific(_qdbm_ptkeys[i].key, val) != 0){ + free(val); + return NULL; + } + } + return val; + } + } + return NULL; +} + + +#endif + + + +/************************************************************************************************* + * for systems without mmap + *************************************************************************************************/ + + +#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) + + +#define MMFDESCMAX 2048 + + +struct { void *start; HANDLE handle; } mmhandles[MMFDESCMAX]; +int mmhnum = 0; +CRITICAL_SECTION mmcsec; + + +static void _qdbm_delete_mmap_env(void); + + +void *_qdbm_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset){ + static volatile long first = TRUE; + static volatile long ready = FALSE; + HANDLE handle; + int i; + if(InterlockedExchange((void *)&first, FALSE)){ + InitializeCriticalSection(&mmcsec); + atexit(_qdbm_delete_mmap_env); + InterlockedExchange((void *)&ready, TRUE); + } + while(!InterlockedCompareExchange((void *)&ready, TRUE, TRUE)){ + Sleep(1); + } + if(fd < 0 || flags & MAP_FIXED) return MAP_FAILED; + if(!(handle = CreateFileMapping((HANDLE)_get_osfhandle(fd), NULL, + (prot & PROT_WRITE) ? PAGE_READWRITE : PAGE_READONLY, + 0, length, NULL))) return MAP_FAILED; + if(!(start = MapViewOfFile(handle, (prot & PROT_WRITE) ? FILE_MAP_WRITE : FILE_MAP_READ, + 0, 0, length))){ + CloseHandle(handle); + return MAP_FAILED; + } + EnterCriticalSection(&mmcsec); + if(mmhnum >= MMFDESCMAX - 1){ + UnmapViewOfFile(start); + CloseHandle(handle); + LeaveCriticalSection(&mmcsec); + return MAP_FAILED; + } + for(i = 0; i < MMFDESCMAX; i++){ + if(!mmhandles[i].start){ + mmhandles[i].start = start; + mmhandles[i].handle = handle; + break; + } + } + mmhnum++; + LeaveCriticalSection(&mmcsec); + return start; +} + + +int _qdbm_munmap(void *start, size_t length){ + HANDLE handle; + int i; + EnterCriticalSection(&mmcsec); + handle = NULL; + for(i = 0; i < MMFDESCMAX; i++){ + if(mmhandles[i].start == start){ + handle = mmhandles[i].handle; + mmhandles[i].start = NULL; + mmhandles[i].handle = NULL; + break; + } + } + if(!handle){ + LeaveCriticalSection(&mmcsec); + return -1; + } + mmhnum--; + LeaveCriticalSection(&mmcsec); + if(!UnmapViewOfFile(start)){ + CloseHandle(handle); + return -1; + } + if(!CloseHandle(handle)) return -1; + return 0; +} + + +int _qdbm_msync(const void *start, size_t length, int flags){ + if(!FlushViewOfFile(start, length)) return -1; + return 0; +} + + +static void _qdbm_delete_mmap_env(void){ + DeleteCriticalSection(&mmcsec); +} + + +#elif defined(_SYS_FREEBSD_) || defined(_SYS_NETBSD_) || defined(_SYS_OPENBSD_) || \ + defined(_SYS_AIX_) || defined(_SYS_RISCOS_) || defined(MYNOMMAP) + + +void *_qdbm_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset){ + char *buf, *wp; + int rv, rlen; + if(flags & MAP_FIXED) return MAP_FAILED; + if(lseek(fd, SEEK_SET, offset) == -1) return MAP_FAILED; + if(!(buf = malloc(sizeof(int) * 3 + length))) return MAP_FAILED; + wp = buf; + *(int *)wp = fd; + wp += sizeof(int); + *(int *)wp = offset; + wp += sizeof(int); + *(int *)wp = prot; + wp += sizeof(int); + rlen = 0; + while((rv = read(fd, wp + rlen, length - rlen)) > 0){ + rlen += rv; + } + if(rv == -1 || rlen != length){ + free(buf); + return MAP_FAILED; + } + return wp; +} + + +int _qdbm_munmap(void *start, size_t length){ + char *buf, *rp; + int fd, offset, prot, rv, wlen; + buf = (char *)start - sizeof(int) * 3; + rp = buf; + fd = *(int *)rp; + rp += sizeof(int); + offset = *(int *)rp; + rp += sizeof(int); + prot = *(int *)rp; + rp += sizeof(int); + if(prot & PROT_WRITE){ + if(lseek(fd, offset, SEEK_SET) == -1){ + free(buf); + return -1; + } + wlen = 0; + while(wlen < (int)length){ + rv = write(fd, rp + wlen, length - wlen); + if(rv == -1){ + if(errno == EINTR) continue; + free(buf); + return -1; + } + wlen += rv; + } + } + free(buf); + return 0; +} + + +int _qdbm_msync(const void *start, size_t length, int flags){ + char *buf, *rp; + int fd, offset, prot, rv, wlen; + buf = (char *)start - sizeof(int) * 3; + rp = buf; + fd = *(int *)rp; + rp += sizeof(int); + offset = *(int *)rp; + rp += sizeof(int); + prot = *(int *)rp; + rp += sizeof(int); + if(prot & PROT_WRITE){ + if(lseek(fd, offset, SEEK_SET) == -1) return -1; + wlen = 0; + while(wlen < (int)length){ + rv = write(fd, rp + wlen, length - wlen); + if(rv == -1){ + if(errno == EINTR) continue; + return -1; + } + wlen += rv; + } + } + return 0; +} + + +#endif + + + +/************************************************************************************************* + * for reentrant time routines + *************************************************************************************************/ + + +#if defined(_SYS_LINUX_) || defined(_SYS_FREEBSD_) || defined(_SYS_OPENBSD_) || \ + defined(_SYS_NETBSD_) || defined(_SYS_SUNOS_) || defined(_SYS_HPUX_) || \ + defined(_SYS_MACOSX_) || defined(_SYS_CYGWIN_) + + +struct tm *_qdbm_gmtime(const time_t *timep, struct tm *result){ + return gmtime_r(timep, result); +} + + +struct tm *_qdbm_localtime(const time_t *timep, struct tm *result){ + return localtime_r(timep, result); +} + + +# else + + +struct tm *_qdbm_gmtime(const time_t *timep, struct tm *result){ + return gmtime(timep); +} + + +struct tm *_qdbm_localtime(const time_t *timep, struct tm *result){ + return localtime(timep); +} + + +# endif + + + +/************************************************************************************************* + * for systems without times + *************************************************************************************************/ + + +#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) + + +clock_t _qdbm_times(struct tms *buf){ + buf->tms_utime = clock(); + buf->tms_stime = 0; + buf->tms_cutime = 0; + buf->tms_cstime = 0; + return 0; +} + + +#endif + + + +/************************************************************************************************* + * for Win32 + *************************************************************************************************/ + + +#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) + + +#define WINLOCKWAIT 100 + + +int _qdbm_win32_fcntl(int fd, int cmd, struct flock *lock){ + HANDLE fh; + DWORD opt; + OVERLAPPED ol; + fh = (HANDLE)_get_osfhandle(fd); + opt = (cmd == F_SETLK) ? LOCKFILE_FAIL_IMMEDIATELY : 0; + if(lock->l_type == F_WRLCK) opt |= LOCKFILE_EXCLUSIVE_LOCK; + memset(&ol, 0, sizeof(OVERLAPPED)); + ol.Offset = INT_MAX; + ol.OffsetHigh = 0; + ol.hEvent = 0; + if(!LockFileEx(fh, opt, 0, 1, 0, &ol)){ + if(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED){ + while(TRUE){ + if(LockFile(fh, 0, 0, 1, 0)) return 0; + Sleep(WINLOCKWAIT); + } + } + return -1; + } + return 0; +} + + +#endif + + +#if defined(_SYS_MSVC_) + + +DIR *_qdbm_win32_opendir(const char *name){ + char expr[8192]; + int len; + DIR *dir; + HANDLE fh; + WIN32_FIND_DATA data; + len = strlen(name); + if(len > 0 && name[len-1] == MYPATHCHR){ + sprintf(expr, "%s*", name); + } else { + sprintf(expr, "%s%c*", name, MYPATHCHR); + } + if((fh = FindFirstFile(expr, &data)) == INVALID_HANDLE_VALUE) return NULL; + if(!(dir = malloc(sizeof(DIR)))){ + FindClose(fh); + return NULL; + } + dir->fh = fh; + dir->data = data; + dir->first = TRUE; + return dir; +} + + +int _qdbm_win32_closedir(DIR *dir){ + if(!FindClose(dir->fh)){ + free(dir); + return -1; + } + free(dir); + return 0; +} + + +struct dirent *_qdbm_win32_readdir(DIR *dir){ + if(dir->first){ + sprintf(dir->de.d_name, "%s", dir->data.cFileName); + dir->first = FALSE; + return &(dir->de); + } + if(!FindNextFile(dir->fh, &(dir->data))) return NULL; + sprintf(dir->de.d_name, "%s", dir->data.cFileName); + return &(dir->de); +} + + +#endif + + + +/************************************************************************************************* + * for checking information of the system + *************************************************************************************************/ + + +#if defined(_SYS_LINUX_) + + +int _qdbm_vmemavail(size_t size){ + char buf[4096], *rp; + int fd, rv, bsiz; + double avail; + if((fd = open("/proc/meminfo", O_RDONLY, 00644)) == -1) return TRUE; + rv = TRUE; + if((bsiz = read(fd, buf, sizeof(buf) - 1)) > 0){ + buf[bsiz] = '\0'; + avail = -1; + if((rp = strstr(buf, "MemFree:")) != NULL){ + rp = strchr(rp, ':') + 1; + avail = strtod(rp, NULL) * 1024.0; + if((rp = strstr(buf, "SwapFree:")) != NULL){ + rp = strchr(rp, ':') + 1; + avail += strtod(rp, NULL) * 1024.0; + } + if(size >= avail) rv = FALSE; + } + } + close(fd); + return rv; +} + + +#elif defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || defined(_SYS_CYGWIN_) + + +int _qdbm_vmemavail(size_t size){ + MEMORYSTATUS sbuf; + sbuf.dwLength = sizeof(MEMORYSTATUS); + GlobalMemoryStatus(&sbuf); + return size < sbuf.dwAvailVirtual; +} + + +#else + + +int _qdbm_vmemavail(size_t size){ + return TRUE; +} + + +#endif + + + +/************************************************************************************************* + * for ZLIB + *************************************************************************************************/ + + +#if defined(MYZLIB) + + +#include + +#define ZLIBBUFSIZ 8192 + + +static char *_qdbm_deflate_impl(const char *ptr, int size, int *sp, int mode); +static char *_qdbm_inflate_impl(const char *ptr, int size, int *sp, int mode); +static unsigned int _qdbm_getcrc_impl(const char *ptr, int size); + + +char *(*_qdbm_deflate)(const char *, int, int *, int) = _qdbm_deflate_impl; +char *(*_qdbm_inflate)(const char *, int, int *, int) = _qdbm_inflate_impl; +unsigned int (*_qdbm_getcrc)(const char *, int) = _qdbm_getcrc_impl; + + +static char *_qdbm_deflate_impl(const char *ptr, int size, int *sp, int mode){ + z_stream zs; + char *buf, *swap; + unsigned char obuf[ZLIBBUFSIZ]; + int rv, asiz, bsiz, osiz; + if(size < 0) size = strlen(ptr); + zs.zalloc = Z_NULL; + zs.zfree = Z_NULL; + zs.opaque = Z_NULL; + switch(mode){ + case _QDBM_ZMRAW: + if(deflateInit2(&zs, 5, Z_DEFLATED, -15, 7, Z_DEFAULT_STRATEGY) != Z_OK) + return NULL; + break; + case _QDBM_ZMGZIP: + if(deflateInit2(&zs, 6, Z_DEFLATED, 15 + 16, 9, Z_DEFAULT_STRATEGY) != Z_OK) + return NULL; + break; + default: + if(deflateInit2(&zs, 6, Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY) != Z_OK) + return NULL; + break; + } + asiz = size + 16; + if(asiz < ZLIBBUFSIZ) asiz = ZLIBBUFSIZ; + if(!(buf = malloc(asiz))){ + deflateEnd(&zs); + return NULL; + } + bsiz = 0; + zs.next_in = (unsigned char *)ptr; + zs.avail_in = size; + zs.next_out = obuf; + zs.avail_out = ZLIBBUFSIZ; + while((rv = deflate(&zs, Z_FINISH)) == Z_OK){ + osiz = ZLIBBUFSIZ - zs.avail_out; + if(bsiz + osiz > asiz){ + asiz = asiz * 2 + osiz; + if(!(swap = realloc(buf, asiz))){ + free(buf); + deflateEnd(&zs); + return NULL; + } + buf = swap; + } + memcpy(buf + bsiz, obuf, osiz); + bsiz += osiz; + zs.next_out = obuf; + zs.avail_out = ZLIBBUFSIZ; + } + if(rv != Z_STREAM_END){ + free(buf); + deflateEnd(&zs); + return NULL; + } + osiz = ZLIBBUFSIZ - zs.avail_out; + if(bsiz + osiz + 1 > asiz){ + asiz = asiz * 2 + osiz; + if(!(swap = realloc(buf, asiz))){ + free(buf); + deflateEnd(&zs); + return NULL; + } + buf = swap; + } + memcpy(buf + bsiz, obuf, osiz); + bsiz += osiz; + buf[bsiz] = '\0'; + if(mode == _QDBM_ZMRAW) bsiz++; + *sp = bsiz; + deflateEnd(&zs); + return buf; +} + + +static char *_qdbm_inflate_impl(const char *ptr, int size, int *sp, int mode){ + z_stream zs; + char *buf, *swap; + unsigned char obuf[ZLIBBUFSIZ]; + int rv, asiz, bsiz, osiz; + zs.zalloc = Z_NULL; + zs.zfree = Z_NULL; + zs.opaque = Z_NULL; + switch(mode){ + case _QDBM_ZMRAW: + if(inflateInit2(&zs, -15) != Z_OK) return NULL; + break; + case _QDBM_ZMGZIP: + if(inflateInit2(&zs, 15 + 16) != Z_OK) return NULL; + break; + default: + if(inflateInit2(&zs, 15) != Z_OK) return NULL; + break; + } + asiz = size * 2 + 16; + if(asiz < ZLIBBUFSIZ) asiz = ZLIBBUFSIZ; + if(!(buf = malloc(asiz))){ + inflateEnd(&zs); + return NULL; + } + bsiz = 0; + zs.next_in = (unsigned char *)ptr; + zs.avail_in = size; + zs.next_out = obuf; + zs.avail_out = ZLIBBUFSIZ; + while((rv = inflate(&zs, Z_NO_FLUSH)) == Z_OK){ + osiz = ZLIBBUFSIZ - zs.avail_out; + if(bsiz + osiz >= asiz){ + asiz = asiz * 2 + osiz; + if(!(swap = realloc(buf, asiz))){ + free(buf); + inflateEnd(&zs); + return NULL; + } + buf = swap; + } + memcpy(buf + bsiz, obuf, osiz); + bsiz += osiz; + zs.next_out = obuf; + zs.avail_out = ZLIBBUFSIZ; + } + if(rv != Z_STREAM_END){ + free(buf); + inflateEnd(&zs); + return NULL; + } + osiz = ZLIBBUFSIZ - zs.avail_out; + if(bsiz + osiz >= asiz){ + asiz = asiz * 2 + osiz; + if(!(swap = realloc(buf, asiz))){ + free(buf); + inflateEnd(&zs); + return NULL; + } + buf = swap; + } + memcpy(buf + bsiz, obuf, osiz); + bsiz += osiz; + buf[bsiz] = '\0'; + if(sp) *sp = bsiz; + inflateEnd(&zs); + return buf; +} + + +static unsigned int _qdbm_getcrc_impl(const char *ptr, int size){ + int crc; + if(size < 0) size = strlen(ptr); + crc = crc32(0, Z_NULL, 0); + return crc32(crc, (unsigned char *)ptr, size); +} + + +#else + + +char *(*_qdbm_deflate)(const char *, int, int *, int) = NULL; +char *(*_qdbm_inflate)(const char *, int, int *, int) = NULL; +unsigned int (*_qdbm_getcrc)(const char *, int) = NULL; + + +#endif + + + +/************************************************************************************************* + * for LZO + *************************************************************************************************/ + + +#if defined(MYLZO) + + +#include + + +static char *_qdbm_lzoencode_impl(const char *ptr, int size, int *sp); +static char *_qdbm_lzodecode_impl(const char *ptr, int size, int *sp); + + +int _qdbm_lzo_init = FALSE; +char *(*_qdbm_lzoencode)(const char *, int, int *) = _qdbm_lzoencode_impl; +char *(*_qdbm_lzodecode)(const char *, int, int *) = _qdbm_lzodecode_impl; + + +static char *_qdbm_lzoencode_impl(const char *ptr, int size, int *sp){ + char wrkmem[LZO1X_1_MEM_COMPRESS]; + lzo_bytep buf; + lzo_uint bsiz; + if(!_qdbm_lzo_init){ + if(lzo_init() != LZO_E_OK) return NULL; + _qdbm_lzo_init = TRUE; + } + if(size < 0) size = strlen(ptr); + if(!(buf = malloc(size + size / 16 + 80))) return NULL; + if(lzo1x_1_compress((lzo_bytep)ptr, size, buf, &bsiz, wrkmem) != LZO_E_OK){ + free(buf); + return NULL; + } + buf[bsiz] = '\0'; + *sp = bsiz; + return (char *)buf; +} + + +static char *_qdbm_lzodecode_impl(const char *ptr, int size, int *sp){ + lzo_bytep buf; + lzo_uint bsiz; + int rat, rv; + if(!_qdbm_lzo_init){ + if(lzo_init() != LZO_E_OK) return NULL; + _qdbm_lzo_init = TRUE; + } + rat = 6; + while(TRUE){ + bsiz = (size + 256) * rat + 3; + if(!(buf = malloc(bsiz + 1))) return NULL; + rv = lzo1x_decompress_safe((lzo_bytep)(ptr), size, buf, &bsiz, NULL); + if(rv == LZO_E_OK){ + break; + } else if(rv == LZO_E_OUTPUT_OVERRUN){ + free(buf); + rat *= 2; + } else { + free(buf); + return NULL; + } + } + buf[bsiz] = '\0'; + if(sp) *sp = bsiz; + return (char *)buf; +} + + +#else + + +char *(*_qdbm_lzoencode)(const char *, int, int *) = NULL; +char *(*_qdbm_lzodecode)(const char *, int, int *) = NULL; + + +#endif + + + +/************************************************************************************************* + * for BZIP2 + *************************************************************************************************/ + + +#if defined(MYBZIP) + + +#include + +#define BZIPBUFSIZ 8192 + + +static char *_qdbm_bzencode_impl(const char *ptr, int size, int *sp); +static char *_qdbm_bzdecode_impl(const char *ptr, int size, int *sp); + + +char *(*_qdbm_bzencode)(const char *, int, int *) = _qdbm_bzencode_impl; +char *(*_qdbm_bzdecode)(const char *, int, int *) = _qdbm_bzdecode_impl; + + +static char *_qdbm_bzencode_impl(const char *ptr, int size, int *sp){ + bz_stream zs; + char *buf, *swap, obuf[BZIPBUFSIZ]; + int rv, asiz, bsiz, osiz; + if(size < 0) size = strlen(ptr); + zs.bzalloc = NULL; + zs.bzfree = NULL; + zs.opaque = NULL; + if(BZ2_bzCompressInit(&zs, 9, 0, 30) != BZ_OK) return NULL; + asiz = size + 16; + if(asiz < BZIPBUFSIZ) asiz = BZIPBUFSIZ; + if(!(buf = malloc(asiz))){ + BZ2_bzCompressEnd(&zs); + return NULL; + } + bsiz = 0; + zs.next_in = (char *)ptr; + zs.avail_in = size; + zs.next_out = obuf; + zs.avail_out = BZIPBUFSIZ; + while((rv = BZ2_bzCompress(&zs, BZ_FINISH)) == BZ_FINISH_OK){ + osiz = BZIPBUFSIZ - zs.avail_out; + if(bsiz + osiz > asiz){ + asiz = asiz * 2 + osiz; + if(!(swap = realloc(buf, asiz))){ + free(buf); + BZ2_bzCompressEnd(&zs); + return NULL; + } + buf = swap; + } + memcpy(buf + bsiz, obuf, osiz); + bsiz += osiz; + zs.next_out = obuf; + zs.avail_out = BZIPBUFSIZ; + } + if(rv != BZ_STREAM_END){ + free(buf); + BZ2_bzCompressEnd(&zs); + return NULL; + } + osiz = BZIPBUFSIZ - zs.avail_out; + if(bsiz + osiz + 1 > asiz){ + asiz = asiz * 2 + osiz; + if(!(swap = realloc(buf, asiz))){ + free(buf); + BZ2_bzCompressEnd(&zs); + return NULL; + } + buf = swap; + } + memcpy(buf + bsiz, obuf, osiz); + bsiz += osiz; + buf[bsiz] = '\0'; + *sp = bsiz; + BZ2_bzCompressEnd(&zs); + return buf; +} + + +static char *_qdbm_bzdecode_impl(const char *ptr, int size, int *sp){ + bz_stream zs; + char *buf, *swap, obuf[BZIPBUFSIZ]; + int rv, asiz, bsiz, osiz; + zs.bzalloc = NULL; + zs.bzfree = NULL; + zs.opaque = NULL; + if(BZ2_bzDecompressInit(&zs, 0, 0) != BZ_OK) return NULL; + asiz = size * 2 + 16; + if(asiz < BZIPBUFSIZ) asiz = BZIPBUFSIZ; + if(!(buf = malloc(asiz))){ + BZ2_bzDecompressEnd(&zs); + return NULL; + } + bsiz = 0; + zs.next_in = (char *)ptr; + zs.avail_in = size; + zs.next_out = obuf; + zs.avail_out = BZIPBUFSIZ; + while((rv = BZ2_bzDecompress(&zs)) == BZ_OK){ + osiz = BZIPBUFSIZ - zs.avail_out; + if(bsiz + osiz >= asiz){ + asiz = asiz * 2 + osiz; + if(!(swap = realloc(buf, asiz))){ + free(buf); + BZ2_bzDecompressEnd(&zs); + return NULL; + } + buf = swap; + } + memcpy(buf + bsiz, obuf, osiz); + bsiz += osiz; + zs.next_out = obuf; + zs.avail_out = BZIPBUFSIZ; + } + if(rv != BZ_STREAM_END){ + free(buf); + BZ2_bzDecompressEnd(&zs); + return NULL; + } + osiz = BZIPBUFSIZ - zs.avail_out; + if(bsiz + osiz >= asiz){ + asiz = asiz * 2 + osiz; + if(!(swap = realloc(buf, asiz))){ + free(buf); + BZ2_bzDecompressEnd(&zs); + return NULL; + } + buf = swap; + } + memcpy(buf + bsiz, obuf, osiz); + bsiz += osiz; + buf[bsiz] = '\0'; + if(sp) *sp = bsiz; + BZ2_bzDecompressEnd(&zs); + return buf; +} + + +#else + + +char *(*_qdbm_bzencode)(const char *, int, int *) = NULL; +char *(*_qdbm_bzdecode)(const char *, int, int *) = NULL; + + +#endif + + + +/************************************************************************************************* + * for ICONV + *************************************************************************************************/ + + +#if defined(MYICONV) + + +#include + +#define ICONVCHECKSIZ 32768 +#define ICONVMISSMAX 256 +#define ICONVALLWRAT 0.001 + + +static char *_qdbm_iconv_impl(const char *ptr, int size, + const char *icode, const char *ocode, int *sp, int *mp); +static const char *_qdbm_encname_impl(const char *ptr, int size); +static int _qdbm_encmiss(const char *ptr, int size, const char *icode, const char *ocode); + + +char *(*_qdbm_iconv)(const char *, int, const char *, const char *, + int *, int *) = _qdbm_iconv_impl; +const char *(*_qdbm_encname)(const char *, int) = _qdbm_encname_impl; + + +static char *_qdbm_iconv_impl(const char *ptr, int size, + const char *icode, const char *ocode, int *sp, int *mp){ + iconv_t ic; + char *obuf, *wp, *rp; + size_t isiz, osiz; + int miss; + if(size < 0) size = strlen(ptr); + isiz = size; + if((ic = iconv_open(ocode, icode)) == (iconv_t)-1) return NULL; + osiz = isiz * 5; + if(!(obuf = malloc(osiz + 1))){ + iconv_close(ic); + return NULL; + } + wp = obuf; + rp = (char *)ptr; + miss = 0; + while(isiz > 0){ + if(iconv(ic, (void *)&rp, &isiz, &wp, &osiz) == -1){ + if(errno == EILSEQ && (*rp == 0x5c || *rp == 0x7e)){ + *wp = *rp; + wp++; + rp++; + isiz--; + } else if(errno == EILSEQ || errno == EINVAL){ + rp++; + isiz--; + miss++; + } else { + break; + } + } + } + *wp = '\0'; + if(iconv_close(ic) == -1){ + free(obuf); + return NULL; + } + if(sp) *sp = wp - obuf; + if(mp) *mp = miss; + return obuf; +} + + +static const char *_qdbm_encname_impl(const char *ptr, int size){ + const char *hypo; + int i, miss, cr; + if(size < 0) size = strlen(ptr); + if(size > ICONVCHECKSIZ) size = ICONVCHECKSIZ; + if(size >= 2 && (!memcmp(ptr, "\xfe\xff", 2) || !memcmp(ptr, "\xff\xfe", 2))) return "UTF-16"; + for(i = 0; i < size - 1; i += 2){ + if(ptr[i] == 0 && ptr[i+1] != 0) return "UTF-16BE"; + if(ptr[i+1] == 0 && ptr[i] != 0) return "UTF-16LE"; + } + for(i = 0; i < size - 3; i++){ + if(ptr[i] == 0x1b){ + i++; + if(ptr[i] == '(' && strchr("BJHI", ptr[i+1])) return "ISO-2022-JP"; + if(ptr[i] == '$' && strchr("@B(", ptr[i+1])) return "ISO-2022-JP"; + } + } + if(_qdbm_encmiss(ptr, size, "US-ASCII", "UTF-16BE") < 1) return "US-ASCII"; + if(_qdbm_encmiss(ptr, size, "UTF-8", "UTF-16BE") < 1) return "UTF-8"; + hypo = NULL; + cr = FALSE; + for(i = 0; i < size; i++){ + if(ptr[i] == 0xd){ + cr = TRUE; + break; + } + } + if(cr){ + if((miss = _qdbm_encmiss(ptr, size, "Shift_JIS", "EUC-JP")) < 1) return "Shift_JIS"; + if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "Shift_JIS"; + if((miss = _qdbm_encmiss(ptr, size, "EUC-JP", "UTF-16BE")) < 1) return "EUC-JP"; + if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "EUC-JP"; + } else { + if((miss = _qdbm_encmiss(ptr, size, "EUC-JP", "UTF-16BE")) < 1) return "EUC-JP"; + if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "EUC-JP"; + if((miss = _qdbm_encmiss(ptr, size, "Shift_JIS", "EUC-JP")) < 1) return "Shift_JIS"; + if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "Shift_JIS"; + } + if((miss = _qdbm_encmiss(ptr, size, "UTF-8", "UTF-16BE")) < 1) return "UTF-8"; + if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "UTF-8"; + if((miss = _qdbm_encmiss(ptr, size, "CP932", "UTF-16BE")) < 1) return "CP932"; + if(!hypo && miss / (double)size <= ICONVALLWRAT) hypo = "CP932"; + return hypo ? hypo : "ISO-8859-1"; +} + + +static int _qdbm_encmiss(const char *ptr, int size, const char *icode, const char *ocode){ + iconv_t ic; + char obuf[ICONVCHECKSIZ], *wp, *rp; + size_t isiz, osiz; + int miss; + isiz = size; + if((ic = iconv_open(ocode, icode)) == (iconv_t)-1) return ICONVMISSMAX; + miss = 0; + rp = (char *)ptr; + while(isiz > 0){ + osiz = ICONVCHECKSIZ; + wp = obuf; + if(iconv(ic, (void *)&rp, &isiz, &wp, &osiz) == -1){ + if(errno == EILSEQ || errno == EINVAL){ + rp++; + isiz--; + miss++; + if(miss >= ICONVMISSMAX) break; + } else { + break; + } + } + } + if(iconv_close(ic) == -1) return ICONVMISSMAX; + return miss; +} + + +#else + + +char *(*_qdbm_iconv)(const char *, int, const char *, const char *, int *, int *) = NULL; +const char *(*_qdbm_encname)(const char *, int) = NULL; + + +#endif + + + +/************************************************************************************************* + * common settings + *************************************************************************************************/ + + +int _qdbm_dummyfunc(void){ + return 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/myconf.h b/qdbm/myconf.h new file mode 100644 index 00000000..3b33ed37 --- /dev/null +++ b/qdbm/myconf.h @@ -0,0 +1,593 @@ +/************************************************************************************************* + * System configurations for QDBM + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#ifndef _MYCONF_H /* duplication check */ +#define _MYCONF_H + +#if defined(__cplusplus) /* export for C++ */ +extern "C" { +#endif + + + +/************************************************************************************************* + * system discrimination + *************************************************************************************************/ + + +#if defined(__linux__) + +#define _SYS_LINUX_ +#define _QDBM_SYSNAME "Linux" + +#elif defined(__FreeBSD__) + +#define _SYS_FREEBSD_ +#define _QDBM_SYSNAME "FreeBSD" + +#elif defined(__NetBSD__) + +#define _SYS_NETBSD_ +#define _QDBM_SYSNAME "NetBSD" + +#elif defined(__OpenBSD__) + +#define _SYS_OPENBSD_ +#define _QDBM_SYSNAME "OpenBSD" + +#elif defined(__sun__) + +#define _SYS_SUNOS_ +#define _QDBM_SYSNAME "SunOS" + +#elif defined(__hpux) + +#define _SYS_HPUX_ +#define _QDBM_SYSNAME "HP-UX" + +#elif defined(__osf) + +#define _SYS_TRU64_ +#define _QDBM_SYSNAME "Tru64" + +#elif defined(_AIX) + +#define _SYS_AIX_ +#define _QDBM_SYSNAME "AIX" + +#elif defined(__APPLE__) && defined(__MACH__) + +#define _SYS_MACOSX_ +#define _QDBM_SYSNAME "Mac OS X" + +#elif defined(_MSC_VER) + +#define _SYS_MSVC_ +#define _QDBM_SYSNAME "Windows (VC++)" + +#elif defined(_WIN32) + +#define _SYS_MINGW_ +#define _QDBM_SYSNAME "Windows (MinGW)" + +#elif defined(__CYGWIN__) + +#define _SYS_CYGWIN_ +#define _QDBM_SYSNAME "Windows (Cygwin)" + +#elif defined(__riscos__) || defined(__riscos) + +#define _SYS_RISCOS_ +#define _QDBM_SYSNAME "RISC OS" + +#else + +#define _SYS_GENERIC_ +#define _QDBM_SYSNAME "Generic" + +#endif + + + +/************************************************************************************************* + * general headers + *************************************************************************************************/ + + +#if defined(_SYS_MSVC_) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#elif defined(_SYS_MINGW_) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#elif defined(_SYS_CYGWIN_) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#else + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif + + + +/************************************************************************************************* + * notation of filesystems + *************************************************************************************************/ + + +#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) + +#define MYPATHCHR '\\' +#define MYPATHSTR "\\" +#define MYEXTCHR '.' +#define MYEXTSTR "." +#define MYCDIRSTR "." +#define MYPDIRSTR ".." + +#elif defined(_SYS_RISCOS_) + +#define MYPATHCHR '.' +#define MYPATHSTR "." +#define MYEXTCHR '/' +#define MYEXTSTR "/" +#define MYCDIRSTR "@" +#define MYPDIRSTR "^" + +#else + +#define MYPATHCHR '/' +#define MYPATHSTR "/" +#define MYEXTCHR '.' +#define MYEXTSTR "." +#define MYCDIRSTR "." +#define MYPDIRSTR ".." + +#endif + + + +/************************************************************************************************* + * for dosish filesystems + *************************************************************************************************/ + + +#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || defined(_SYS_CYGWIN_) + +#undef UNICODE +#undef open + +#define \ + open(pathname, flags, mode) \ + open(pathname, flags | O_BINARY, mode) + +#define \ + lstat(pathname, buf) \ + _qdbm_win32_lstat(pathname, buf) + +int _qdbm_win32_lstat(const char *pathname, struct stat *buf); + +#else + +#undef O_BINARY +#undef O_TEXT +#undef setmode + +#define O_BINARY 0 +#define O_TEXT 1 + +#define \ + setmode(fd, mode) \ + (O_BINARY) + +#endif + + + +/************************************************************************************************* + * for POSIX thread + *************************************************************************************************/ + + +#if defined(MYPTHREAD) + +#define _qdbm_ptsafe TRUE + +void *_qdbm_settsd(void *ptr, int size, const void *initval); + +#else + +#define _qdbm_ptsafe FALSE + +#define \ + _qdbm_settsd(ptr, size, initval) \ + (NULL) + +#endif + + + +/************************************************************************************************* + * for systems without file locking + *************************************************************************************************/ + + +#if defined(_SYS_RISCOS_) || defined(MYNOLOCK) + +#undef fcntl + +#define \ + fcntl(fd, cmd, lock) \ + (0) + +#endif + + + +/************************************************************************************************* + * for systems without mmap + *************************************************************************************************/ + + +#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) || \ + defined(_SYS_FREEBSD_) || defined(_SYS_NETBSD_) || defined(_SYS_OPENBSD_) || \ + defined(_SYS_AIX_) || defined(_SYS_RISCOS_) || defined(MYNOMMAP) + +#undef PROT_EXEC +#undef PROT_READ +#undef PROT_WRITE +#undef PROT_NONE +#undef MAP_FIXED +#undef MAP_SHARED +#undef MAP_PRIVATE +#undef MAP_FAILED +#undef MS_ASYNC +#undef MS_SYNC +#undef MS_INVALIDATE +#undef mmap +#undef munmap +#undef msync +#undef mflush + +#define PROT_EXEC (1 << 0) +#define PROT_READ (1 << 1) +#define PROT_WRITE (1 << 2) +#define PROT_NONE (1 << 3) +#define MAP_FIXED 1 +#define MAP_SHARED 2 +#define MAP_PRIVATE 3 +#define MAP_FAILED ((void *)-1) +#define MS_ASYNC (1 << 0) +#define MS_SYNC (1 << 1) +#define MS_INVALIDATE (1 << 2) + +#define \ + mmap(start, length, prot, flags, fd, offset) \ + _qdbm_mmap(start, length, prot, flags, fd, offset) + +#define \ + munmap(start, length) \ + _qdbm_munmap(start, length) + +#define \ + msync(start, length, flags) \ + _qdbm_msync(start, length, flags) + +#define \ + mflush(start, length, flags) \ + _qdbm_msync(start, length, flags) + +void *_qdbm_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); +int _qdbm_munmap(void *start, size_t length); +int _qdbm_msync(const void *start, size_t length, int flags); + +#else + +#undef mflush +#define \ + mflush(start, length, flags) \ + (0) + +#endif + + + +/************************************************************************************************* + * for reentrant time routines + *************************************************************************************************/ + + +struct tm *_qdbm_gmtime(const time_t *timep, struct tm *result); +struct tm *_qdbm_localtime(const time_t *timep, struct tm *result); + + + +/************************************************************************************************* + * for systems without times + *************************************************************************************************/ + + +#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) + +#undef times +#undef sysconf + +struct tms { + clock_t tms_utime; + clock_t tms_stime; + clock_t tms_cutime; + clock_t tms_cstime; +}; + +#define \ + times(buf) \ + _qdbm_times(buf) + +#define \ + sysconf(name) \ + (CLOCKS_PER_SEC) + +clock_t _qdbm_times(struct tms *buf); + +#endif + + + +/************************************************************************************************* + * for Win32 + *************************************************************************************************/ + + +#if defined(_SYS_MSVC_) || defined(_SYS_MINGW_) + +#undef F_WRLCK +#undef F_RDLCK +#undef F_SETLK +#undef F_SETLKW +#undef fcntl +#undef ftruncate +#undef fsync +#undef mkdir +#undef rename + +#define F_WRLCK 0 +#define F_RDLCK 1 +#define F_SETLK 0 +#define F_SETLKW 1 + +struct flock { + int l_type; + int l_whence; + int l_start; + int l_len; + int l_pid; +}; + +#define \ + fcntl(fd, cmd, lock) \ + _qdbm_win32_fcntl(fd, cmd, lock) + +#define \ + ftruncate(fd, length) \ + _chsize(fd, length) + +#define \ + fsync(fd) \ + (0) + +#define \ + mkdir(pathname, mode) \ + mkdir(pathname) + +#define \ + rename(oldpath, newpath) \ + (unlink(newpath), rename(oldpath, newpath)) + +int _qdbm_win32_fcntl(int fd, int cmd, struct flock *lock); + +#endif + + +#if defined(_SYS_MSVC_) + +#undef S_ISDIR +#undef S_ISREG +#undef opendir +#undef closedir +#undef readdir + +#define S_ISDIR(x) (x & _S_IFDIR) +#define S_ISREG(x) (x & _S_IFREG) + +struct dirent { + char d_name[1024]; +}; + +typedef struct { + HANDLE fh; + WIN32_FIND_DATA data; + struct dirent de; + int first; +} DIR; + +#define \ + opendir(name) \ + _qdbm_win32_opendir(name) + +#define \ + closedir(dir) \ + _qdbm_win32_closedir(dir) + +#define \ + readdir(dir) \ + _qdbm_win32_readdir(dir) + +DIR *_qdbm_win32_opendir(const char *name); + +int _qdbm_win32_closedir(DIR *dir); + +struct dirent *_qdbm_win32_readdir(DIR *dir); + +#endif + + + +/************************************************************************************************* + * for checking information of the system + *************************************************************************************************/ + + +int _qdbm_vmemavail(size_t size); + + + +/************************************************************************************************* + * for ZLIB + *************************************************************************************************/ + + +enum { + _QDBM_ZMZLIB, + _QDBM_ZMRAW, + _QDBM_ZMGZIP +}; + + +extern char *(*_qdbm_deflate)(const char *, int, int *, int); + +extern char *(*_qdbm_inflate)(const char *, int, int *, int); + +extern unsigned int (*_qdbm_getcrc)(const char *, int); + + + +/************************************************************************************************* + * for LZO + *************************************************************************************************/ + + +extern char *(*_qdbm_lzoencode)(const char *, int, int *); + +extern char *(*_qdbm_lzodecode)(const char *, int, int *); + + + +/************************************************************************************************* + * for BZIP2 + *************************************************************************************************/ + + +extern char *(*_qdbm_bzencode)(const char *, int, int *); + +extern char *(*_qdbm_bzdecode)(const char *, int, int *); + + + +/************************************************************************************************* + * for ICONV + *************************************************************************************************/ + + +extern char *(*_qdbm_iconv)(const char *, int, const char *, const char *, int *, int *); + +extern const char *(*_qdbm_encname)(const char *, int); + + + +/************************************************************************************************* + * common settings + *************************************************************************************************/ + + +#undef TRUE +#define TRUE 1 +#undef FALSE +#define FALSE 0 + +#define sizeof(a) ((int)sizeof(a)) + +int _qdbm_dummyfunc(void); + + + +#if defined(__cplusplus) /* export for C++ */ +} +#endif + +#endif /* duplication check */ + + +/* END OF FILE */ diff --git a/qdbm/odeum.c b/qdbm/odeum.c new file mode 100644 index 00000000..15395224 --- /dev/null +++ b/qdbm/odeum.c @@ -0,0 +1,2090 @@ +/************************************************************************************************* + * Implementation of Odeum + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#define QDBM_INTERNAL 1 + +#include "odeum.h" +#include "myconf.h" + +#define OD_NAMEMAX 256 /* max size of a database name */ +#define OD_DIRMODE 00755 /* permission of a creating directory */ +#define OD_PATHBUFSIZ 1024 /* size of a path buffer */ +#define OD_NUMBUFSIZ 32 /* size of a buffer for a number */ +#define OD_MAPPBNUM 127 /* bucket size of a petit map handle */ +#define OD_DOCSNAME "docs" /* name of the database for documents */ +#define OD_INDEXNAME "index" /* name of the database for inverted index */ +#define OD_RDOCSNAME "rdocs" /* name of the database for reverse dictionary */ +#define OD_DOCSBNUM 2039 /* initial bucket number of document database */ +#define OD_DOCSDNUM 17 /* division number of document database */ +#define OD_DOCSALIGN -4 /* alignment of document database */ +#define OD_DOCSFBP 32 /* size of free block pool of document database */ +#define OD_INDEXBNUM 32749 /* initial bucket number of inverted index */ +#define OD_INDEXDNUM 7 /* division number of inverted index */ +#define OD_INDEXALIGN -2 /* alignment of inverted index */ +#define OD_INDEXFBP 32 /* size of free block pool of inverted index */ +#define OD_RDOCSLRM 81 /* records in a leaf node of reverse dictionary */ +#define OD_RDOCSNIM 192 /* records in a non-leaf node of reverse dictionary */ +#define OD_RDOCSLCN 128 /* number of leaf cache of reverse dictionary */ +#define OD_RDOCSNCN 32 /* number of non-leaf cache of reverse dictionary */ +#define OD_CACHEBNUM 262139 /* number of buckets for dirty buffers */ +#define OD_CACHESIZ 8388608 /* max bytes to use memory for dirty buffers */ +#define OD_CFLIVERAT 0.8 /* ratio of usable cache region */ +#define OD_CFBEGSIZ 2048 /* beginning size of flushing frequent words */ +#define OD_CFENDSIZ 64 /* lower limit of flushing frequent words */ +#define OD_CFRFRAT 0.2 /* ratio of flushing rare words a time */ +#define OD_OTCBBUFSIZ 1024 /* size of a buffer for call back functions */ +#define OD_OTPERWORDS 10000 /* frequency of call back in merging index */ +#define OD_OTPERDOCS 1000 /* frequency of call back in merging docs */ +#define OD_MDBRATIO 2.5 /* ratio of bucket number and document number */ +#define OD_MIBRATIO 1.5 /* ratio of bucket number and word number */ +#define OD_MIARATIO 0.75 /* ratio of alignment to the first words */ +#define OD_MIWUNIT 32 /* writing unit of merging inverted index */ +#define OD_DMAXEXPR "dmax" /* key of max number of the document ID */ +#define OD_DNUMEXPR "dnum" /* key of number of the documents */ +#define OD_URIEXPR "1" /* map key of URI */ +#define OD_ATTRSEXPR "2" /* map key of attributes */ +#define OD_NWORDSEXPR "3" /* map key of normal words */ +#define OD_AWORDSEXPR "4" /* map key of as-is words */ +#define OD_WTOPRATE 0.1 /* ratio of top words */ +#define OD_WTOPBONUS 5000 /* bonus points of top words */ +#define OD_KEYCRATIO 1.75 /* ratio of number to max of keyword candidates */ +#define OD_WOCCRPOINT 10000 /* points per occurence */ +#define OD_SPACECHARS "\t\n\v\f\r " /* space characters */ +#define OD_DELIMCHARS "!\"#$%&'()*/<=>?[\\]^`{|}~" /* delimiter characters */ +#define OD_GLUECHARS "+,-.:;@" /* glueing characters */ +#define OD_MAXWORDLEN 48 /* max length of a word */ + +typedef struct { /* type of structure for word counting */ + const char *word; /* pointer to the word */ + int num; /* frequency of the word */ +} ODWORD; + +enum { /* enumeration for events binded to each character */ + OD_EVWORD, /* word */ + OD_EVSPACE, /* space */ + OD_EVDELIM, /* delimiter */ + OD_EVGLUE /* glue */ +}; + + +/* private global variables */ +int odindexbnum = OD_INDEXBNUM; +int odindexdnum = OD_INDEXDNUM; +int odcachebnum = OD_CACHEBNUM; +int odcachesiz = OD_CACHESIZ; +void (*odotcb)(const char *, ODEUM *, const char *) = NULL; + + +/* private function prototypes */ +static ODEUM *odopendb(const char *name, int omode, int docsbnum, int indexbnum, + const char *fname); +static int odcacheflush(ODEUM *odeum, const char *fname); +static int odcacheflushfreq(ODEUM *odeum, const char *fname, int min); +static int odcacheflushrare(ODEUM *odeum, const char *fname, double ratio); +static int odsortindex(ODEUM *odeum, const char *fname); +static int odsortcompare(const void *a, const void *b); +static int odpurgeindex(ODEUM *odeum, const char *fname); +static CBMAP *odpairsmap(const ODPAIR *pairs, int num); +static int odwordcompare(const void *a, const void *b); +static int odmatchoperator(ODEUM *odeum, CBLIST *tokens); +static ODPAIR *odparsesubexpr(ODEUM *odeum, CBLIST *tokens, CBLIST *nwords, int *np, + CBLIST *errors); +static ODPAIR *odparseexpr(ODEUM *odeum, CBLIST *tokens, CBLIST *nwords, int *np, + CBLIST *errors); +static void odfixtokens(ODEUM *odeum, CBLIST *tokens); +static void odcleannormalized(ODEUM *odeum, CBLIST *nwords); + + + +/************************************************************************************************* + * public objects + *************************************************************************************************/ + + +/* Get a database handle. */ +ODEUM *odopen(const char *name, int omode){ + assert(name); + return odopendb(name, omode, OD_DOCSBNUM, odindexbnum, "odopen"); +} + + +/* Close a database handle. */ +int odclose(ODEUM *odeum){ + char numbuf[OD_NUMBUFSIZ]; + int err; + assert(odeum); + err = FALSE; + if(odotcb) odotcb("odclose", odeum, "closing the connection"); + if(odeum->wmode){ + if(odotcb) odotcb("odclose", odeum, "writing meta information"); + sprintf(numbuf, "%d", odeum->dmax); + if(!vlput(odeum->rdocsdb, OD_DMAXEXPR, sizeof(OD_DMAXEXPR), numbuf, -1, VL_DOVER)) err = TRUE; + sprintf(numbuf, "%d", odeum->dnum); + if(!vlput(odeum->rdocsdb, OD_DNUMEXPR, sizeof(OD_DNUMEXPR), numbuf, -1, VL_DOVER)) err = TRUE; + if(!odcacheflushfreq(odeum, "odclose", OD_CFENDSIZ)) err = TRUE; + if(!odcacheflushrare(odeum, "odclose", OD_CFRFRAT)) err = TRUE; + if(!odcacheflush(odeum, "odclose")) err = TRUE; + if(!odsortindex(odeum, "odclose")) err = TRUE; + cbmapclose(odeum->cachemap); + cbmapclose(odeum->sortmap); + } + if(!vlclose(odeum->rdocsdb)) err = TRUE; + if(!crclose(odeum->indexdb)) err = TRUE; + if(!crclose(odeum->docsdb)) err = TRUE; + free(odeum->name); + free(odeum); + return err ? FALSE : TRUE; +} + + +/* Store a document. */ +int odput(ODEUM *odeum, ODDOC *doc, int wmax, int over){ + char *tmp, *zbuf; + const char *word, *ctmp; + int i, docid, tsiz, wsiz, wnum, tmax, num, zsiz; + double ival; + ODPAIR pair; + CBMAP *map; + CBLIST *tlist; + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!odeum->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if((tmp = vlget(odeum->rdocsdb, doc->uri, -1, &tsiz)) != NULL){ + if(!over){ + free(tmp); + dpecodeset(DP_EKEEP, __FILE__, __LINE__); + return FALSE; + } + if(tsiz != sizeof(int) || !odoutbyid(odeum, *(int *)tmp)){ + free(tmp); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + odeum->fatal = TRUE; + return FALSE; + } + free(tmp); + } + odeum->dmax++; + odeum->dnum++; + docid = odeum->dmax; + map = cbmapopen(); + cbmapput(map, OD_URIEXPR, sizeof(OD_URIEXPR), doc->uri, -1, TRUE); + tmp = cbmapdump(doc->attrs, &tsiz); + cbmapput(map, OD_ATTRSEXPR, sizeof(OD_ATTRSEXPR), tmp, tsiz, TRUE); + free(tmp); + if(wmax < 0 || wmax > cblistnum(doc->nwords)) wmax = cblistnum(doc->nwords); + tlist = cblistopen(); + for(i = 0; i < wmax; i++){ + ctmp = cblistval(doc->nwords, i, &wsiz); + cblistpush(tlist, ctmp, wsiz); + } + tmp = cblistdump(tlist, &tsiz); + cbmapput(map, OD_NWORDSEXPR, sizeof(OD_NWORDSEXPR), tmp, tsiz, TRUE); + free(tmp); + cblistclose(tlist); + tlist = cblistopen(); + for(i = 0; i < wmax; i++){ + ctmp = cblistval(doc->awords, i, &wsiz); + if(strcmp(ctmp, cblistval(doc->nwords, i, NULL))){ + cblistpush(tlist, ctmp, wsiz); + } else { + cblistpush(tlist, "\0", 1); + } + } + tmp = cblistdump(tlist, &tsiz); + cbmapput(map, OD_AWORDSEXPR, sizeof(OD_AWORDSEXPR), tmp, tsiz, TRUE); + free(tmp); + cblistclose(tlist); + tmp = cbmapdump(map, &tsiz); + cbmapclose(map); + if(_qdbm_deflate){ + if(!(zbuf = _qdbm_deflate(tmp, tsiz, &zsiz, _QDBM_ZMRAW))){ + free(tmp); + dpecodeset(DP_EMISC, __FILE__, __LINE__); + odeum->fatal = TRUE; + return FALSE; + } + free(tmp); + tmp = zbuf; + tsiz = zsiz; + } + if(!crput(odeum->docsdb, (char *)&docid, sizeof(int), tmp, tsiz, CR_DKEEP)){ + free(tmp); + if(dpecode == DP_EKEEP) dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + odeum->fatal = TRUE; + return FALSE; + } + free(tmp); + if(!vlput(odeum->rdocsdb, doc->uri, -1, (char *)&docid, sizeof(int), VL_DOVER)){ + odeum->fatal = TRUE; + return FALSE; + } + map = cbmapopen(); + wnum = cblistnum(doc->nwords); + tmax = (int)(wnum * OD_WTOPRATE); + for(i = 0; i < wnum; i++){ + word = cblistval(doc->nwords, i, &wsiz); + if(wsiz < 1) continue; + if((ctmp = cbmapget(map, word, wsiz, NULL)) != NULL){ + num = *(int *)ctmp + OD_WOCCRPOINT; + } else { + num = i <= tmax ? OD_WTOPBONUS + OD_WOCCRPOINT : OD_WOCCRPOINT; + } + cbmapput(map, word, wsiz, (char *)&num, sizeof(int), TRUE); + } + ival = odlogarithm(wnum); + ival = (ival * ival * ival) / 8.0; + if(ival < 8.0) ival = 8.0; + cbmapiterinit(map); + while((word = cbmapiternext(map, &wsiz)) != NULL){ + pair.id = docid; + pair.score = (int)(*(int *)cbmapget(map, word, wsiz, NULL) / ival); + cbmapputcat(odeum->cachemap, word, wsiz, (char *)&pair, sizeof(pair)); + cbmapmove(odeum->cachemap, word, wsiz, FALSE); + odeum->cacheasiz += sizeof(pair); + cbmapput(odeum->sortmap, word, wsiz, "", 0, FALSE); + } + cbmapclose(map); + if(odeum->cacheasiz > odcachesiz){ + for(i = OD_CFBEGSIZ; odeum->cacheasiz > odcachesiz * OD_CFLIVERAT && i >= OD_CFENDSIZ; + i /= 2){ + if(!odcacheflushfreq(odeum, "odput", i)) return FALSE; + } + while(odeum->cacheasiz > odcachesiz * OD_CFLIVERAT){ + if(!odcacheflushrare(odeum, "odput", OD_CFRFRAT)) return FALSE; + } + } + doc->id = docid; + odeum->ldid = docid; + return TRUE; +} + + +/* Delete a document by a URL. */ +int odout(ODEUM *odeum, const char *uri){ + char *tmp; + int tsiz, docid; + assert(odeum && uri); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!odeum->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(!(tmp = vlget(odeum->rdocsdb, uri, -1, &tsiz))){ + if(dpecode != DP_ENOITEM) odeum->fatal = TRUE; + return FALSE; + } + if(tsiz != sizeof(int)){ + free(tmp); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + odeum->fatal = TRUE; + return FALSE; + } + docid = *(int *)tmp; + free(tmp); + return odoutbyid(odeum, docid); +} + + +/* Delete a document specified by an ID number. */ +int odoutbyid(ODEUM *odeum, int id){ + char *tmp, *zbuf; + const char *uritmp; + int tsiz, uritsiz, zsiz; + CBMAP *map; + assert(odeum && id > 0); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!odeum->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(!(tmp = crget(odeum->docsdb, (char *)&id, sizeof(int), 0, -1, &tsiz))){ + if(dpecode != DP_ENOITEM) odeum->fatal = TRUE; + return FALSE; + } + if(_qdbm_inflate){ + if(!(zbuf = _qdbm_inflate(tmp, tsiz, &zsiz, _QDBM_ZMRAW))){ + free(tmp); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + odeum->fatal = TRUE; + return FALSE; + } + free(tmp); + tmp = zbuf; + tsiz = zsiz; + } + map = cbmapload(tmp, tsiz); + free(tmp); + uritmp = cbmapget(map, OD_URIEXPR, sizeof(OD_URIEXPR), &uritsiz); + if(!uritmp || !vlout(odeum->rdocsdb, uritmp, uritsiz)){ + cbmapclose(map); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + odeum->fatal = TRUE; + return FALSE; + } + cbmapclose(map); + if(!crout(odeum->docsdb, (char *)&id, sizeof(int))){ + odeum->fatal = TRUE; + return FALSE; + } + odeum->dnum--; + return TRUE; +} + + +/* Retrieve a document by a URI. */ +ODDOC *odget(ODEUM *odeum, const char *uri){ + char *tmp; + int tsiz, docid; + assert(odeum && uri); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return NULL; + } + if(!(tmp = vlget(odeum->rdocsdb, uri, -1, &tsiz))){ + if(dpecode != DP_ENOITEM) odeum->fatal = TRUE; + return NULL; + } + if(tsiz != sizeof(int)){ + free(tmp); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + odeum->fatal = TRUE; + return NULL; + } + docid = *(int *)tmp; + free(tmp); + return odgetbyid(odeum, docid); +} + + +/* Retrieve a document by an ID number. */ +ODDOC *odgetbyid(ODEUM *odeum, int id){ + char *tmp, *zbuf; + const char *uritmp, *attrstmp, *nwordstmp, *awordstmp, *asis, *normal; + int i, tsiz, uritsiz, attrstsiz, nwordstsiz, awordstsiz, zsiz, asiz, nsiz; + ODDOC *doc; + CBMAP *map; + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return NULL; + } + if(id < 1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return NULL; + } + if(!(tmp = crget(odeum->docsdb, (char *)&id, sizeof(int), 0, -1, &tsiz))){ + if(dpecode != DP_ENOITEM) odeum->fatal = TRUE; + return NULL; + } + if(_qdbm_inflate){ + if(!(zbuf = _qdbm_inflate(tmp, tsiz, &zsiz, _QDBM_ZMRAW))){ + free(tmp); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + odeum->fatal = TRUE; + return NULL; + } + free(tmp); + tmp = zbuf; + tsiz = zsiz; + } + map = cbmapload(tmp, tsiz); + free(tmp); + uritmp = cbmapget(map, OD_URIEXPR, sizeof(OD_URIEXPR), &uritsiz); + attrstmp = cbmapget(map, OD_ATTRSEXPR, sizeof(OD_ATTRSEXPR), &attrstsiz); + nwordstmp = cbmapget(map, OD_NWORDSEXPR, sizeof(OD_NWORDSEXPR), &nwordstsiz); + awordstmp = cbmapget(map, OD_AWORDSEXPR, sizeof(OD_AWORDSEXPR), &awordstsiz); + if(!uritmp || !attrstmp || !nwordstmp || !awordstmp){ + cbmapclose(map); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + odeum->fatal = TRUE; + return NULL; + } + doc = cbmalloc(sizeof(ODDOC)); + doc->id = id; + doc->uri = cbmemdup(uritmp, uritsiz); + doc->attrs = cbmapload(attrstmp, attrstsiz); + doc->nwords = cblistload(nwordstmp, nwordstsiz); + doc->awords = cblistload(awordstmp, awordstsiz); + cbmapclose(map); + for(i = 0; i < cblistnum(doc->awords); i++){ + asis = cblistval(doc->awords, i, &asiz); + if(asiz == 1 && asis[0] == '\0'){ + normal = cblistval(doc->nwords, i, &nsiz); + cblistover(doc->awords, i, normal, nsiz); + } + } + return doc; +} + + +/* Retrieve the ID of the document specified by a URI. */ +int odgetidbyuri(ODEUM *odeum, const char *uri){ + char *tmp; + int tsiz, docid; + assert(odeum && uri); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + if(!(tmp = vlget(odeum->rdocsdb, uri, -1, &tsiz))){ + if(dpecode != DP_ENOITEM) odeum->fatal = TRUE; + return -1; + } + if(tsiz != sizeof(int)){ + free(tmp); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + odeum->fatal = TRUE; + return -1; + } + docid = *(int *)tmp; + free(tmp); + return docid; +} + + +/* Check whether the document specified by an ID number exists. */ +int odcheck(ODEUM *odeum, int id){ + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(id < 1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + return crvsiz(odeum->docsdb, (char *)&id, sizeof(int)) != -1; +} + + +/* Search the inverted index for documents including a word. */ +ODPAIR *odsearch(ODEUM *odeum, const char *word, int max, int *np){ + char *tmp; + int tsiz; + assert(odeum && word && np); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return NULL; + } + if(odeum->wmode && cbmaprnum(odeum->sortmap) > 0 && + (!odcacheflush(odeum, "odsearch") || !odsortindex(odeum, "odsearch"))){ + odeum->fatal = TRUE; + return NULL; + } + max = max < 0 ? -1 : max * sizeof(ODPAIR); + if(!(tmp = crget(odeum->indexdb, word, -1, 0, max, &tsiz))){ + if(dpecode != DP_ENOITEM){ + odeum->fatal = TRUE; + return NULL; + } + *np = 0; + return cbmalloc(1); + } + *np = tsiz / sizeof(ODPAIR); + return (ODPAIR *)tmp; +} + + +/* Get the number of documents including a word. */ +int odsearchdnum(ODEUM *odeum, const char *word){ + int rv; + assert(odeum && word); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + rv = crvsiz(odeum->indexdb, word, -1); + return rv < 0 ? -1 : rv / sizeof(ODPAIR); +} + + +/* Initialize the iterator of a database handle. */ +int oditerinit(ODEUM *odeum){ + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + return criterinit(odeum->docsdb); +} + + +/* Get the next key of the iterator. */ +ODDOC *oditernext(ODEUM *odeum){ + char *tmp; + int tsiz, docsid; + ODDOC *doc; + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return NULL; + } + doc = NULL; + while(TRUE){ + if(!(tmp = criternext(odeum->docsdb, &tsiz))){ + if(dpecode != DP_ENOITEM) odeum->fatal = TRUE; + return NULL; + } + if(tsiz != sizeof(int)){ + free(tmp); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + odeum->fatal = TRUE; + return NULL; + } + docsid = *(int *)tmp; + free(tmp); + if((doc = odgetbyid(odeum, docsid)) != NULL) break; + if(dpecode != DP_ENOITEM){ + odeum->fatal = TRUE; + return NULL; + } + } + return doc; +} + + +/* Synchronize updating contents with the files and the devices. */ +int odsync(ODEUM *odeum){ + char numbuf[OD_NUMBUFSIZ]; + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!odeum->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(odotcb) odotcb("odsync", odeum, "writing meta information"); + sprintf(numbuf, "%d", odeum->dmax); + if(!vlput(odeum->rdocsdb, OD_DMAXEXPR, sizeof(OD_DMAXEXPR), numbuf, -1, VL_DOVER)){ + odeum->fatal = TRUE; + return FALSE; + } + sprintf(numbuf, "%d", odeum->dnum); + if(!vlput(odeum->rdocsdb, OD_DNUMEXPR, sizeof(OD_DNUMEXPR), numbuf, -1, VL_DOVER)){ + odeum->fatal = TRUE; + return FALSE; + } + if(!odcacheflush(odeum, "odsync")){ + odeum->fatal = TRUE; + return FALSE; + } + if(!odsortindex(odeum, "odsync")){ + odeum->fatal = TRUE; + return FALSE; + } + if(odotcb) odotcb("odsync", odeum, "synchronizing the document database"); + if(!crsync(odeum->docsdb)){ + odeum->fatal = TRUE; + return FALSE; + } + if(odotcb) odotcb("odsync", odeum, "synchronizing the inverted index"); + if(!crsync(odeum->indexdb)){ + odeum->fatal = TRUE; + return FALSE; + } + if(odotcb) odotcb("odsync", odeum, "synchronizing the reverse dictionary"); + if(!vlsync(odeum->rdocsdb)){ + odeum->fatal = TRUE; + return FALSE; + } + return TRUE; +} + + +/* Optimize a database. */ +int odoptimize(ODEUM *odeum){ + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return FALSE; + } + if(!odeum->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(!odcacheflush(odeum, "odoptimize")){ + odeum->fatal = TRUE; + return FALSE; + } + if(odeum->ldid < 1 || odeum->ldid != odeum->dnum){ + if(!odpurgeindex(odeum, "odoptimize")){ + odeum->fatal = TRUE; + return FALSE; + } + } + if(odeum->ldid > 0){ + if(!odsortindex(odeum, "odoptimize")){ + odeum->fatal = TRUE; + return FALSE; + } + } + if(odotcb) odotcb("odoptimize", odeum, "optimizing the document database"); + if(!croptimize(odeum->docsdb, -1)){ + odeum->fatal = TRUE; + return FALSE; + } + if(odotcb) odotcb("odoptimize", odeum, "optimizing the inverted index"); + if(!croptimize(odeum->indexdb, -1)){ + odeum->fatal = TRUE; + return FALSE; + } + if(odotcb) odotcb("odoptimize", odeum, "optimizing the reverse dictionary"); + if(!vloptimize(odeum->rdocsdb)){ + odeum->fatal = TRUE; + return FALSE; + } + return TRUE; +} + + +/* Get the name of a database. */ +char *odname(ODEUM *odeum){ + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return NULL; + } + return cbmemdup(odeum->name, -1); +} + + +/* Get the total size of database files. */ +double odfsiz(ODEUM *odeum){ + double fsiz, rv; + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + fsiz = 0; + if((rv = crfsizd(odeum->docsdb)) < 0) return -1.0; + fsiz += rv; + if((rv = crfsizd(odeum->indexdb)) < 0) return -1.0; + fsiz += rv; + if((rv = vlfsiz(odeum->rdocsdb)) == -1) return -1.0; + fsiz += rv; + return fsiz; +} + + +/* Get the total number of the elements of the bucket arrays for the inverted index. */ +int odbnum(ODEUM *odeum){ + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + return crbnum(odeum->indexdb); +} + + +/* Get the total number of the used elements of the bucket arrays in the inverted index. */ +int odbusenum(ODEUM *odeum){ + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + return crbusenum(odeum->indexdb); +} + + +/* Get the number of the documents stored in a database. */ +int oddnum(ODEUM *odeum){ + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + return odeum->dnum; +} + + +/* Get the number of the words stored in a database. */ +int odwnum(ODEUM *odeum){ + assert(odeum); + if(odeum->fatal){ + dpecodeset(DP_EFATAL, __FILE__, __LINE__); + return -1; + } + return crrnum(odeum->indexdb); +} + + +/* Check whether a database handle is a writer or not. */ +int odwritable(ODEUM *odeum){ + assert(odeum); + return odeum->wmode; +} + + +/* Check whether a database has a fatal error or not. */ +int odfatalerror(ODEUM *odeum){ + assert(odeum); + return odeum->fatal; +} + + +/* Get the inode number of a database directory. */ +int odinode(ODEUM *odeum){ + assert(odeum); + return odeum->inode; +} + + +/* Get the last modified time of a database. */ +time_t odmtime(ODEUM *odeum){ + assert(odeum); + return crmtime(odeum->indexdb); +} + + +/* Merge plural database directories. */ +int odmerge(const char *name, const CBLIST *elemnames){ + ODEUM *odeum, **elems; + CURIA *curia, *ecuria; + VILLA *villa, *evilla; + ODPAIR *pairs; + char *word, *kbuf, *vbuf, *dbuf, otmsg[OD_OTCBBUFSIZ]; + char *wpunit[OD_MIWUNIT], *vpunit[OD_MIWUNIT]; + int i, j, k, num, dnum, wnum, dbnum, ibnum, tnum, wsunit[OD_MIWUNIT], vsunit[OD_MIWUNIT]; + int err, *bases, sum, max, wsiz, ksiz, vsiz, uend, unum, pnum, align, id, nid, dsiz; + assert(name && elemnames); + num = cblistnum(elemnames); + elems = cbmalloc(num * sizeof(ODEUM *) + 1); + dnum = 0; + wnum = 0; + for(i = 0; i < num; i++){ + if(!(elems[i] = odopen(cblistval(elemnames, i, NULL), OD_OREADER))){ + for(i -= 1; i >= 0; i--){ + odclose(elems[i]); + } + free(elems); + return FALSE; + } + dnum += oddnum(elems[i]); + wnum += odwnum(elems[i]); + } + dbnum = (int)(dnum * OD_MDBRATIO / OD_DOCSDNUM); + ibnum = (int)(wnum * OD_MIBRATIO / odindexdnum); + if(!(odeum = odopendb(name, OD_OWRITER | OD_OCREAT | OD_OTRUNC, dbnum, ibnum, "odmerge"))){ + for(i = 0; i < num; i++){ + odclose(elems[i]); + } + free(elems); + return FALSE; + } + err = FALSE; + if(odotcb) odotcb("odmerge", odeum, "calculating the base ID numbers"); + bases = cbmalloc(num * sizeof(int) + 1); + sum = 0; + for(i = 0; i < num; i++){ + ecuria = elems[i]->docsdb; + max = 0; + if(!criterinit(ecuria) && dpecode != DP_ENOITEM) err = TRUE; + while((kbuf = criternext(ecuria, &ksiz)) != NULL){ + if(ksiz == sizeof(int)){ + if(*(int *)kbuf > max) max = *(int *)kbuf; + } + free(kbuf); + } + bases[i] = sum; + sum += max; + } + curia = odeum->indexdb; + for(i = 0; i < num; i++){ + if(odotcb){ + sprintf(otmsg, "merging the inverted index (%d/%d)", i + 1, num); + odotcb("odmerge", odeum, otmsg); + } + ecuria = elems[i]->indexdb; + tnum = 0; + uend = FALSE; + if(!criterinit(ecuria) && dpecode != DP_ENOITEM) err = TRUE; + while(!uend){ + for(unum = 0; unum < OD_MIWUNIT; unum++){ + if(!(word = criternext(ecuria, &wsiz))){ + uend = TRUE; + break; + } + if(!(vbuf = crget(ecuria, word, wsiz, 0, -1, &vsiz))){ + err = TRUE; + free(word); + break; + } + wpunit[unum] = word; + wsunit[unum] = wsiz; + vpunit[unum] = vbuf; + vsunit[unum] = vsiz; + } + for(j = 0; j < unum; j++){ + word = wpunit[j]; + wsiz = wsunit[j]; + vbuf = vpunit[j]; + vsiz = vsunit[j]; + pairs = (ODPAIR *)vbuf; + pnum = vsiz / sizeof(ODPAIR); + for(k = 0; k < pnum; k++){ + pairs[k].id += bases[i]; + } + align = (int)(i < num - 1 ? vsiz * (num - i) * OD_MIARATIO : OD_INDEXALIGN); + if(!crsetalign(curia, align)) err = TRUE; + if(!crput(curia, word, wsiz, vbuf, vsiz, CR_DCAT)) err = TRUE; + free(vbuf); + free(word); + if(odotcb && (tnum + 1) % OD_OTPERWORDS == 0){ + sprintf(otmsg, "... (%d/%d)", tnum + 1, crrnum(ecuria)); + odotcb("odmerge", odeum, otmsg); + } + tnum++; + } + } + } + if(odotcb) odotcb("odmerge", odeum, "sorting the inverted index"); + tnum = 0; + if(!criterinit(curia) && dpecode != DP_ENOITEM) err = TRUE; + while((word = criternext(curia, &wsiz)) != NULL){ + if((vbuf = crget(curia, word, wsiz, 0, -1, &vsiz)) != NULL){ + if(vsiz > sizeof(ODPAIR)){ + pairs = (ODPAIR *)vbuf; + pnum = vsiz / sizeof(ODPAIR); + qsort(pairs, pnum, sizeof(ODPAIR), odsortcompare); + if(!crput(curia, word, wsiz, vbuf, vsiz, CR_DOVER)) err = TRUE; + } + free(vbuf); + } + free(word); + if(odotcb && (tnum + 1) % OD_OTPERWORDS == 0){ + sprintf(otmsg, "... (%d/%d)", tnum + 1, crrnum(curia)); + odotcb("odmerge", odeum, otmsg); + } + tnum++; + } + if(odotcb) odotcb("odmerge", odeum, "synchronizing the inverted index"); + if(!crsync(curia)) err = TRUE; + dnum = 0; + curia = odeum->docsdb; + villa = odeum->rdocsdb; + for(i = 0; i < num; i++){ + if(odotcb){ + sprintf(otmsg, "merging the document database (%d/%d)", i + 1, num); + odotcb("odmerge", odeum, otmsg); + } + evilla = elems[i]->rdocsdb; + ecuria = elems[i]->docsdb; + tnum = 0; + if(!vlcurfirst(evilla) && dpecode != DP_ENOITEM) err = TRUE; + while(TRUE){ + if(!(kbuf = vlcurkey(evilla, &ksiz))) break; + if((ksiz == sizeof(OD_DMAXEXPR) && !memcmp(kbuf, OD_DMAXEXPR, ksiz)) || + (ksiz == sizeof(OD_DNUMEXPR) && !memcmp(kbuf, OD_DNUMEXPR, ksiz))){ + free(kbuf); + if(!vlcurnext(evilla)) break; + continue; + } + if(!(vbuf = vlcurval(evilla, &vsiz))){ + free(kbuf); + if(!vlcurnext(evilla)) break; + continue; + } + if(vsiz != sizeof(int)){ + free(vbuf); + free(kbuf); + if(!vlcurnext(evilla)) break; + continue; + } + id = *(int *)vbuf; + nid = id + bases[i]; + if(vlput(villa, kbuf, ksiz, (char *)&nid, sizeof(int), VL_DKEEP)){ + if((dbuf = crget(ecuria, (char *)&id, sizeof(int), 0, -1, &dsiz)) != NULL){ + if(crput(curia, (char *)&nid, sizeof(int), dbuf, dsiz, CR_DKEEP)){ + dnum++; + } else { + err = TRUE; + } + free(dbuf); + } else { + err = TRUE; + } + } else if(dpecode != DP_EKEEP){ + err = TRUE; + } + free(vbuf); + free(kbuf); + odeum->dnum++; + if(odotcb && (tnum + 1) % OD_OTPERDOCS == 0){ + sprintf(otmsg, "... (%d/%d)", tnum + 1, crrnum(ecuria)); + odotcb("odmerge", odeum, otmsg); + } + tnum++; + if(!vlcurnext(evilla)) break; + } + } + odeum->dnum = dnum; + odeum->dmax = dnum; + free(bases); + if(odotcb) odotcb("odmerge", odeum, "synchronizing the document index"); + if(!crsync(curia)) err = TRUE; + if(!odclose(odeum)) err = TRUE; + for(i = 0; i < num; i++){ + if(!odclose(elems[i])) err = TRUE; + } + free(elems); + return err ? FALSE : TRUE; +} + + +/* Remove a database directory. */ +int odremove(const char *name){ + char docsname[OD_PATHBUFSIZ], indexname[OD_PATHBUFSIZ], rdocsname[OD_PATHBUFSIZ]; + char path[OD_PATHBUFSIZ]; + const char *file; + struct stat sbuf; + CBLIST *list; + int i; + assert(name); + sprintf(docsname, "%s%c%s", name, MYPATHCHR, OD_DOCSNAME); + sprintf(indexname, "%s%c%s", name, MYPATHCHR, OD_INDEXNAME); + sprintf(rdocsname, "%s%c%s", name, MYPATHCHR, OD_RDOCSNAME); + if(lstat(name, &sbuf) == -1){ + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + return FALSE; + } + if(lstat(docsname, &sbuf) != -1 && !crremove(docsname)) return FALSE; + if(lstat(indexname, &sbuf) != -1 && !crremove(indexname)) return FALSE; + if(lstat(rdocsname, &sbuf) != -1 && !vlremove(rdocsname)) return FALSE; + if((list = cbdirlist(name)) != NULL){ + for(i = 0; i < cblistnum(list); i++){ + file = cblistval(list, i, NULL); + if(!strcmp(file, MYCDIRSTR) || !strcmp(file, MYPDIRSTR)) continue; + sprintf(path, "%s%c%s", name, MYPATHCHR, file); + if(lstat(path, &sbuf) == -1) continue; + if(S_ISDIR(sbuf.st_mode)){ + if(!crremove(path)) return FALSE; + } else { + if(!dpremove(path)) return FALSE; + } + } + cblistclose(list); + } + if(rmdir(name) == -1){ + dpecodeset(DP_ERMDIR, __FILE__, __LINE__); + return FALSE; + } + return TRUE; +} + + +/* Get a document handle. */ +ODDOC *oddocopen(const char *uri){ + ODDOC *doc; + assert(uri); + doc = cbmalloc(sizeof(ODDOC)); + doc->id = -1; + doc->uri = cbmemdup(uri, -1); + doc->attrs = cbmapopenex(OD_MAPPBNUM); + doc->nwords = cblistopen(); + doc->awords = cblistopen(); + return doc; +} + + +/* Close a document handle. */ +void oddocclose(ODDOC *doc){ + assert(doc); + cblistclose(doc->awords); + cblistclose(doc->nwords); + cbmapclose(doc->attrs); + free(doc->uri); + free(doc); +} + + +/* Add an attribute to a document. */ +void oddocaddattr(ODDOC *doc, const char *name, const char *value){ + assert(doc && name && value); + cbmapput(doc->attrs, name, -1, value, -1, TRUE); +} + + +/* Add a word to a document. */ +void oddocaddword(ODDOC *doc, const char *normal, const char *asis){ + assert(doc && normal && asis); + cblistpush(doc->nwords, normal, -1); + cblistpush(doc->awords, asis, -1); +} + + +/* Get the ID number of a document. */ +int oddocid(const ODDOC *doc){ + assert(doc); + return doc->id; +} + + +/* Get the URI of a document. */ +const char *oddocuri(const ODDOC *doc){ + assert(doc); + return doc->uri; +} + + +/* Get the value of an attribute of a document. */ +const char *oddocgetattr(const ODDOC *doc, const char *name){ + assert(doc && name); + return cbmapget(doc->attrs, name, -1, NULL); +} + + +/* Get the list handle contains words in normalized form of a document. */ +const CBLIST *oddocnwords(const ODDOC *doc){ + assert(doc); + return doc->nwords; +} + + +/* Get the list handle contains words in appearance form of a document. */ +const CBLIST *oddocawords(const ODDOC *doc){ + assert(doc); + return doc->awords; +} + + +/* Get the map handle contains keywords in normalized form and their scores. */ +CBMAP *oddocscores(const ODDOC *doc, int max, ODEUM *odeum){ + const CBLIST *nwords; + CBMAP *map, *kwmap; + const char *word, *ctmp; + char numbuf[OD_NUMBUFSIZ]; + ODWORD *owords; + int i, wsiz, wnum, hnum, mnum, nbsiz; + double ival; + assert(doc && max >= 0); + map = cbmapopen(); + nwords = oddocnwords(doc); + for(i = 0; i < cblistnum(nwords); i++){ + word = cblistval(nwords, i, &wsiz); + if(wsiz < 1) continue; + if((ctmp = cbmapget(map, word, wsiz, NULL)) != NULL){ + wnum = *(int *)ctmp + OD_WOCCRPOINT; + } else { + wnum = OD_WOCCRPOINT; + } + cbmapput(map, word, wsiz, (char *)&wnum, sizeof(int), TRUE); + } + mnum = cbmaprnum(map); + owords = cbmalloc(mnum * sizeof(ODWORD) + 1); + cbmapiterinit(map); + for(i = 0; (word = cbmapiternext(map, &wsiz)) != NULL; i++){ + owords[i].word = word; + owords[i].num = *(int *)cbmapget(map, word, wsiz, NULL); + } + qsort(owords, mnum, sizeof(ODWORD), odwordcompare); + if(odeum){ + if(mnum > max * OD_KEYCRATIO) mnum = (int)(max * OD_KEYCRATIO); + for(i = 0; i < mnum; i++){ + if((hnum = odsearchdnum(odeum, owords[i].word)) < 0) hnum = 0; + ival = odlogarithm(hnum); + ival = (ival * ival * ival) / 8.0; + if(ival < 8.0) ival = 8.0; + owords[i].num = (int)(owords[i].num / ival); + } + qsort(owords, mnum, sizeof(ODWORD), odwordcompare); + } + if(mnum > max) mnum = max; + kwmap = cbmapopenex(OD_MAPPBNUM); + for(i = 0; i < mnum; i++){ + nbsiz = sprintf(numbuf, "%d", owords[i].num); + cbmapput(kwmap, owords[i].word, -1, numbuf, nbsiz, TRUE); + } + free(owords); + cbmapclose(map); + return kwmap; +} + + +/* Break a text into words in appearance form. */ +CBLIST *odbreaktext(const char *text){ + const char *word; + CBLIST *elems, *words; + int i, j, dif, wsiz, pv, delim; + assert(text); + words = cblistopen(); + elems = cbsplit(text, -1, OD_SPACECHARS); + for(i = 0; i < cblistnum(elems); i++){ + word = cblistval(elems, i, &wsiz); + delim = FALSE; + j = 0; + pv = 0; + while(TRUE){ + dif = j - pv; + if(j >= wsiz){ + if(dif > 0 && dif <= OD_MAXWORDLEN) cblistpush(words, word + pv, j - pv); + break; + } + if(delim){ + if(!strchr(OD_DELIMCHARS, word[j])){ + if(dif > 0 && dif <= OD_MAXWORDLEN) cblistpush(words, word + pv, j - pv); + pv = j; + delim = FALSE; + } + } else { + if(strchr(OD_DELIMCHARS, word[j])){ + if(dif > 0 && dif <= OD_MAXWORDLEN) cblistpush(words, word + pv, j - pv); + pv = j; + delim = TRUE; + } + } + j++; + } + } + cblistclose(elems); + return words; +} + + +/* Make the normalized form of a word. */ +char *odnormalizeword(const char *asis){ + char *nword; + int i; + assert(asis); + for(i = 0; asis[i] != '\0'; i++){ + if(!strchr(OD_DELIMCHARS, asis[i])) break; + } + if(asis[i] == '\0') return cbmemdup("", 0); + nword = cbmemdup(asis, -1); + for(i = 0; nword[i] != '\0'; i++){ + if(nword[i] >= 'A' && nword[i] <= 'Z') nword[i] += 'a' - 'A'; + } + while(i >= 0){ + if(strchr(OD_GLUECHARS, nword[i])){ + nword[i] = '\0'; + } else { + break; + } + i--; + } + return nword; +} + + +/* Get the common elements of two sets of documents. */ +ODPAIR *odpairsand(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np){ + CBMAP *map; + ODPAIR *result; + const char *tmp; + int i, rnum; + assert(apairs && anum >= 0 && bpairs && bnum >= 0); + map = odpairsmap(bpairs, bnum); + result = cbmalloc(sizeof(ODPAIR) * anum + 1); + rnum = 0; + for(i = 0; i < anum; i++){ + if(!(tmp = cbmapget(map, (char *)&(apairs[i].id), sizeof(int), NULL))) continue; + result[rnum].id = apairs[i].id; + result[rnum].score = apairs[i].score + *(int *)tmp; + rnum++; + } + cbmapclose(map); + qsort(result, rnum, sizeof(ODPAIR), odsortcompare); + *np = rnum; + return result; +} + + +/* Get the sum of elements of two sets of documents. */ +ODPAIR *odpairsor(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np){ + CBMAP *map; + ODPAIR *result; + const char *tmp; + int i, score, rnum; + assert(apairs && anum >= 0 && bpairs && bnum >= 0); + map = odpairsmap(bpairs, bnum); + for(i = 0; i < anum; i++){ + score = 0; + if((tmp = cbmapget(map, (char *)&(apairs[i].id), sizeof(int), NULL)) != NULL) + score = *(int *)tmp; + score += apairs[i].score; + cbmapput(map, (char *)&(apairs[i].id), sizeof(int), + (char *)&score, sizeof(int), TRUE); + } + rnum = cbmaprnum(map); + result = cbmalloc(rnum * sizeof(ODPAIR) + 1); + cbmapiterinit(map); + for(i = 0; (tmp = cbmapiternext(map, NULL)) != NULL; i++){ + result[i].id = *(int *)tmp; + result[i].score = *(int *)cbmapget(map, tmp, sizeof(int), NULL); + } + cbmapclose(map); + qsort(result, rnum, sizeof(ODPAIR), odsortcompare); + *np = rnum; + return result; +} + + +/* Get the difference set of documents. */ +ODPAIR *odpairsnotand(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np){ + CBMAP *map; + ODPAIR *result; + const char *tmp; + int i, rnum; + assert(apairs && anum >= 0 && bpairs && bnum >= 0); + map = odpairsmap(bpairs, bnum); + result = cbmalloc(sizeof(ODPAIR) * anum + 1); + rnum = 0; + for(i = 0; i < anum; i++){ + if((tmp = cbmapget(map, (char *)&(apairs[i].id), sizeof(int), NULL)) != NULL) continue; + result[rnum].id = apairs[i].id; + result[rnum].score = apairs[i].score; + rnum++; + } + cbmapclose(map); + qsort(result, rnum, sizeof(ODPAIR), odsortcompare); + *np = rnum; + return result; +} + + +/* Sort a set of documents in descending order of scores. */ +void odpairssort(ODPAIR *pairs, int pnum){ + assert(pairs && pnum >= 0); + qsort(pairs, pnum, sizeof(ODPAIR), odsortcompare); +} + + +/* Get the natural logarithm of a number. */ +double odlogarithm(double x){ + int i; + if(x <= 1.0) return 0.0; + x = x * x * x * x * x * x * x * x * x * x; + for(i = 0; x > 1.0; i++){ + x /= 2.718281828459; + } + return (double)i / 10.0; +} + + +/* Get the cosine of the angle of two vectors. */ +double odvectorcosine(const int *avec, const int *bvec, int vnum){ + double rv; + assert(avec && bvec && vnum >= 0); + rv = odvecinnerproduct(avec, bvec, vnum) / + ((odvecabsolute(avec, vnum) * odvecabsolute(bvec, vnum))); + return rv > 0.0 ? rv : 0.0; +} + + +/* Set the global tuning parameters. */ +void odsettuning(int ibnum, int idnum, int cbnum, int csiz){ + if(ibnum > 0) odindexbnum = ibnum; + if(idnum > 0) odindexdnum = idnum; + if(cbnum > 0) odcachebnum = dpprimenum(cbnum); + if(csiz > 0) odcachesiz = csiz; +} + + +/* Break a text into words and store appearance forms and normalized form into lists. */ +void odanalyzetext(ODEUM *odeum, const char *text, CBLIST *awords, CBLIST *nwords){ + char aword[OD_MAXWORDLEN+1], *wp; + int lev, wsiz; + assert(odeum && text && awords); + lev = OD_EVSPACE; + wsiz = 0; + for(; *text != '\0'; text++){ + switch(odeum->statechars[*(unsigned char *)text]){ + case OD_EVWORD: + if(wsiz > 0 && lev == OD_EVDELIM){ + cblistpush(awords, aword, wsiz); + if(nwords) cblistpush(nwords, "", 0); + wsiz = 0; + } + if(wsiz <= OD_MAXWORDLEN){ + aword[wsiz++] = *text; + } + lev = OD_EVWORD; + break; + case OD_EVGLUE: + if(wsiz > 0 && lev == OD_EVDELIM){ + cblistpush(awords, aword, wsiz); + if(nwords) cblistpush(nwords, "", 0); + wsiz = 0; + } + if(wsiz <= OD_MAXWORDLEN){ + aword[wsiz++] = *text; + } + lev = OD_EVGLUE; + break; + case OD_EVDELIM: + if(wsiz > 0 && lev != OD_EVDELIM){ + cblistpush(awords, aword, wsiz); + if(nwords){ + wp = aword; + aword[wsiz] = '\0'; + while(*wp != '\0'){ + if(*wp >= 'A' && *wp <= 'Z') *wp += 'a' - 'A'; + wp++; + } + wp--; + while(wp >= aword && odeum->statechars[*(unsigned char *)wp] == OD_EVGLUE){ + wsiz--; + wp--; + } + cblistpush(nwords, aword, wsiz); + } + wsiz = 0; + } + if(wsiz <= OD_MAXWORDLEN){ + aword[wsiz++] = *text; + } + lev = OD_EVDELIM; + break; + default: + if(wsiz > 0){ + cblistpush(awords, aword, wsiz); + if(nwords){ + if(lev == OD_EVDELIM){ + cblistpush(nwords, "", 0); + } else { + wp = aword; + aword[wsiz] = '\0'; + while(*wp != '\0'){ + if(*wp >= 'A' && *wp <= 'Z') *wp += 'a' - 'A'; + wp++; + } + wp--; + while(wp >= aword && odeum->statechars[*(unsigned char *)wp] == OD_EVGLUE){ + wsiz--; + wp--; + } + cblistpush(nwords, aword, wsiz); + } + } + wsiz = 0; + } + lev = OD_EVSPACE; + break; + } + } + if(wsiz > 0){ + cblistpush(awords, aword, wsiz); + if(nwords){ + if(lev == OD_EVDELIM){ + cblistpush(nwords, "", 0); + } else { + wp = aword; + aword[wsiz] = '\0'; + while(*wp != '\0'){ + if(*wp >= 'A' && *wp <= 'Z') *wp += 'a' - 'A'; + wp++; + } + wp--; + while(wp >= aword && odeum->statechars[*(unsigned char *)wp] == OD_EVGLUE){ + wsiz--; + wp--; + } + cblistpush(nwords, aword, wsiz); + } + } + wsiz = 0; + } +} + + +/* Set the classes of characters used by `odanalyzetext'. */ +void odsetcharclass(ODEUM *odeum, const char *spacechars, const char *delimchars, + const char *gluechars){ + assert(odeum && spacechars && delimchars && gluechars); + memset(odeum->statechars, OD_EVWORD, sizeof(odeum->statechars)); + for(; *spacechars != '\0'; spacechars++){ + odeum->statechars[*(unsigned char *)spacechars] = OD_EVSPACE; + } + for(; *delimchars != '\0'; delimchars++){ + odeum->statechars[*(unsigned char *)delimchars] = OD_EVDELIM; + } + for(; *gluechars != '\0'; gluechars++){ + odeum->statechars[*(unsigned char *)gluechars] = OD_EVGLUE; + } +} + + +/* Query a database using a small boolean query language. */ +ODPAIR *odquery(ODEUM *odeum, const char *query, int *np, CBLIST *errors){ + CBLIST *tokens = cblistopen(); + CBLIST *nwords = cblistopen(); + ODPAIR *results = NULL; + assert(odeum && query && np); + odanalyzetext(odeum, query, tokens, nwords); + odcleannormalized(odeum, nwords); + odfixtokens(odeum, tokens); + results = odparseexpr(odeum, tokens, nwords, np, errors); + cblistclose(tokens); + cblistclose(nwords); + return results; +} + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Get the internal database handle for documents. */ +CURIA *odidbdocs(ODEUM *odeum){ + assert(odeum); + return odeum->docsdb; +} + + +/* Get the internal database handle for the inverted index. */ +CURIA *odidbindex(ODEUM *odeum){ + assert(odeum); + return odeum->indexdb; +} + + +/* Get the internal database handle for the reverse dictionary. */ +VILLA *odidbrdocs(ODEUM *odeum){ + assert(odeum); + return odeum->rdocsdb; +} + + +/* Set the call back function called in merging. */ +void odsetotcb(void (*otcb)(const char *, ODEUM *, const char *)){ + odotcb = otcb; +} + + +/* Get the positive one of square roots of a number. */ +double odsquareroot(double x){ + double c, rv; + if(x <= 0.0) return 0.0; + c = x > 1.0 ? x : 1; + do { + rv = c; + c = (x / c + c) * 0.5; + } while(c < rv); + return rv; +} + + +/* Get the absolute of a vector. */ +double odvecabsolute(const int *vec, int vnum){ + double rv; + int i; + assert(vec && vnum >= 0); + rv = 0; + for(i = 0; i < vnum; i++){ + rv += (double)vec[i] * (double)vec[i]; + } + return odsquareroot(rv); +} + + +/* Get the inner product of two vectors. */ +double odvecinnerproduct(const int *avec, const int *bvec, int vnum){ + double rv; + int i; + assert(avec && bvec && vnum >= 0); + rv = 0; + for(i = 0; i < vnum; i++){ + rv += (double)avec[i] * (double)bvec[i]; + } + return rv; +} + + + +/************************************************************************************************* + * private objects + *************************************************************************************************/ + + +/* Get a database handle. + `name' specifies the name of a database directory. + `omode' specifies the connection mode. + `docsbnum` specifies the number of buckets of the document database. + `indexbnum` specifies the number of buckets of the index database. + `fname' specifies the name of caller function. + The return value is the database handle or `NULL' if it is not successful. */ +static ODEUM *odopendb(const char *name, int omode, int docsbnum, int indexbnum, + const char *fname){ + int cromode, vlomode, inode, dmax, dnum; + char docsname[OD_PATHBUFSIZ], indexname[OD_PATHBUFSIZ], rdocsname[OD_PATHBUFSIZ], *tmp; + struct stat sbuf; + CURIA *docsdb, *indexdb; + VILLA *rdocsdb; + CBMAP *cachemap; + CBMAP *sortmap; + ODEUM *odeum; + assert(name); + if(strlen(name) > OD_NAMEMAX){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return NULL; + } + cromode = CR_OREADER; + vlomode = VL_OREADER; + if(omode & OD_OWRITER){ + cromode = CR_OWRITER; + vlomode = VL_OWRITER | VL_OZCOMP | VL_OYCOMP; + if(omode & OD_OCREAT){ + cromode |= CR_OCREAT; + vlomode |= VL_OCREAT; + } + if(omode & OD_OTRUNC){ + cromode |= CR_OTRUNC; + vlomode |= VL_OTRUNC; + } + } + if(omode & OD_ONOLCK){ + cromode |= CR_ONOLCK; + vlomode |= VL_ONOLCK; + } + if(omode & OD_OLCKNB){ + cromode |= CR_OLCKNB; + vlomode |= VL_OLCKNB; + } + sprintf(docsname, "%s%c%s", name, MYPATHCHR, OD_DOCSNAME); + sprintf(indexname, "%s%c%s", name, MYPATHCHR, OD_INDEXNAME); + sprintf(rdocsname, "%s%c%s", name, MYPATHCHR, OD_RDOCSNAME); + docsdb = NULL; + indexdb = NULL; + rdocsdb = NULL; + if((omode & OD_OWRITER) && (omode & OD_OCREAT)){ + if(mkdir(name, OD_DIRMODE) == -1 && errno != EEXIST){ + dpecodeset(DP_EMKDIR, __FILE__, __LINE__); + return NULL; + } + } + if(lstat(name, &sbuf) == -1){ + dpecodeset(DP_ESTAT, __FILE__, __LINE__); + return NULL; + } + inode = sbuf.st_ino; + if(!(docsdb = cropen(docsname, cromode, docsbnum, OD_DOCSDNUM))) return NULL; + if(!(indexdb = cropen(indexname, cromode, indexbnum, odindexdnum))){ + crclose(docsdb); + return NULL; + } + if(omode & OD_OWRITER){ + if(!crsetalign(docsdb, OD_DOCSALIGN) || !crsetfbpsiz(docsdb, OD_DOCSFBP) || + !crsetalign(indexdb, OD_INDEXALIGN) || !crsetfbpsiz(indexdb, OD_INDEXFBP)){ + crclose(indexdb); + crclose(docsdb); + return NULL; + } + } + if(!(rdocsdb = vlopen(rdocsname, vlomode, VL_CMPLEX))){ + crclose(indexdb); + crclose(docsdb); + return NULL; + } + vlsettuning(rdocsdb, OD_RDOCSLRM, OD_RDOCSNIM, OD_RDOCSLCN, OD_RDOCSNCN); + if(omode & OD_OWRITER){ + cachemap = cbmapopenex(odcachebnum); + sortmap = cbmapopenex(odcachebnum); + } else { + cachemap = NULL; + sortmap = NULL; + } + if(vlrnum(rdocsdb) > 0){ + dmax = -1; + dnum = -1; + if((tmp = vlget(rdocsdb, OD_DMAXEXPR, sizeof(OD_DMAXEXPR), NULL)) != NULL){ + dmax = atoi(tmp); + free(tmp); + } + if((tmp = vlget(rdocsdb, OD_DNUMEXPR, sizeof(OD_DNUMEXPR), NULL)) != NULL){ + dnum = atoi(tmp); + free(tmp); + } + if(dmax < 0 || dnum < 0){ + if(sortmap) cbmapclose(sortmap); + if(cachemap) cbmapclose(cachemap); + vlclose(rdocsdb); + crclose(indexdb); + crclose(docsdb); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + } else { + dmax = 0; + dnum = 0; + } + odeum = cbmalloc(sizeof(ODEUM)); + odeum->name = cbmemdup(name, -1); + odeum->wmode = omode & OD_OWRITER; + odeum->fatal = FALSE; + odeum->inode = inode; + odeum->docsdb = docsdb; + odeum->indexdb = indexdb; + odeum->rdocsdb = rdocsdb; + odeum->cachemap = cachemap; + odeum->cacheasiz = 0; + odeum->sortmap = sortmap; + odeum->dmax = dmax; + odeum->dnum = dnum; + odeum->ldid = -1; + odsetcharclass(odeum, OD_SPACECHARS, OD_DELIMCHARS, OD_GLUECHARS); + if(odotcb) odotcb(fname, odeum, "the connection was established"); + return odeum; +} + + +/* Flush the cache for dirty buffer of words. + `odeum' specifies a database handle. + `fname' specifies the name of caller function. + If successful, the return value is true, else, it is false. */ +static int odcacheflush(ODEUM *odeum, const char *fname){ + const char *kbuf, *vbuf; + char otmsg[OD_OTCBBUFSIZ]; + int i, rnum, ksiz, vsiz; + assert(odeum); + if((rnum = cbmaprnum(odeum->cachemap)) < 1) return TRUE; + if(odotcb) odotcb(fname, odeum, "flushing caches"); + cbmapiterinit(odeum->cachemap); + for(i = 0; (kbuf = cbmapiternext(odeum->cachemap, &ksiz)) != NULL; i++){ + vbuf = cbmapget(odeum->cachemap, kbuf, ksiz, &vsiz); + if(!crput(odeum->indexdb, kbuf, ksiz, vbuf, vsiz, CR_DCAT)){ + odeum->fatal = TRUE; + return FALSE; + } + if(odotcb && (i + 1) % OD_OTPERWORDS == 0){ + sprintf(otmsg, "... (%d/%d)", i + 1, rnum); + odotcb(fname, odeum, otmsg); + } + } + cbmapclose(odeum->cachemap); + odeum->cachemap = cbmapopenex(odcachebnum); + odeum->cacheasiz = 0; + return TRUE; +} + + +/* Flush all frequent words in the cache for dirty buffer of words. + `odeum' specifies a database handle. + `fname' specifies the name of caller function. + `min' specifies the minimum size of frequent words. + If successful, the return value is true, else, it is false. */ +static int odcacheflushfreq(ODEUM *odeum, const char *fname, int min){ + const char *kbuf, *vbuf; + char otmsg[OD_OTCBBUFSIZ]; + int rnum, ksiz, vsiz; + assert(odeum); + if((rnum = cbmaprnum(odeum->cachemap)) < 1) return TRUE; + if(odotcb){ + sprintf(otmsg, "flushing frequent words: min=%d asiz=%d rnum=%d)", + min, odeum->cacheasiz, rnum); + odotcb(fname, odeum, otmsg); + } + cbmapiterinit(odeum->cachemap); + while((kbuf = cbmapiternext(odeum->cachemap, &ksiz)) != NULL){ + vbuf = cbmapget(odeum->cachemap, kbuf, ksiz, &vsiz); + if(vsiz >= sizeof(ODPAIR) * min){ + if(!crput(odeum->indexdb, kbuf, ksiz, vbuf, vsiz, CR_DCAT)){ + odeum->fatal = TRUE; + return FALSE; + } + cbmapout(odeum->cachemap, kbuf, ksiz); + odeum->cacheasiz -= vsiz; + } + } + if(odotcb){ + sprintf(otmsg, "... (done): min=%d asiz=%d rnum=%d)", + min, odeum->cacheasiz, cbmaprnum(odeum->cachemap)); + odotcb(fname, odeum, otmsg); + } + return TRUE; +} + + +/* Flush the half of rare words in the cache for dirty buffer of words. + `odeum' specifies a database handle. + `fname' specifies the name of caller function. + `ratio' specifies the ratio of rare words. + If successful, the return value is true, else, it is false. */ +static int odcacheflushrare(ODEUM *odeum, const char *fname, double ratio){ + const char *kbuf, *vbuf; + char otmsg[OD_OTCBBUFSIZ]; + int i, rnum, limit, ksiz, vsiz; + assert(odeum); + if((rnum = cbmaprnum(odeum->cachemap)) < 1) return TRUE; + if(odotcb){ + sprintf(otmsg, "flushing rare words: ratio=%.2f asiz=%d rnum=%d)", + ratio, odeum->cacheasiz, rnum); + odotcb(fname, odeum, otmsg); + } + cbmapiterinit(odeum->cachemap); + limit = (int)(rnum * ratio); + for(i = 0; i < limit && (kbuf = cbmapiternext(odeum->cachemap, &ksiz)) != NULL; i++){ + vbuf = cbmapget(odeum->cachemap, kbuf, ksiz, &vsiz); + if(!crput(odeum->indexdb, kbuf, ksiz, vbuf, vsiz, CR_DCAT)){ + odeum->fatal = TRUE; + return FALSE; + } + cbmapout(odeum->cachemap, kbuf, ksiz); + odeum->cacheasiz -= vsiz; + } + if(odotcb){ + sprintf(otmsg, "... (done): ratio=%.2f asiz=%d rnum=%d)", + ratio, odeum->cacheasiz, cbmaprnum(odeum->cachemap)); + odotcb(fname, odeum, otmsg); + } + return TRUE; +} + + +/* Sort the records of inverted index. + `odeum' specifies a database handle. + `fname' specifies the name of caller function. + If successful, the return value is true, else, it is false. */ +static int odsortindex(ODEUM *odeum, const char *fname){ + const char *word; + char *tmp, otmsg[OD_OTCBBUFSIZ]; + int i, rnum, wsiz, tsiz; + ODPAIR *pairs; + assert(odeum); + if((rnum = cbmaprnum(odeum->sortmap)) < 1) return TRUE; + if(odotcb) odotcb(fname, odeum, "sorting the inverted index"); + cbmapiterinit(odeum->sortmap); + for(i = 0; (word = cbmapiternext(odeum->sortmap, &wsiz)) != NULL; i++){ + if((tmp = crget(odeum->indexdb, word, wsiz, 0, -1, &tsiz)) != NULL){ + if(tsiz > sizeof(ODPAIR)){ + pairs = (ODPAIR *)tmp; + qsort(pairs, tsiz / sizeof(ODPAIR), sizeof(ODPAIR), odsortcompare); + if(!crput(odeum->indexdb, word, wsiz, tmp, tsiz, CR_DOVER)){ + free(tmp); + return FALSE; + } + } + free(tmp); + } else if(dpecode != DP_ENOITEM){ + return FALSE; + } + if(odotcb && (i + 1) % OD_OTPERWORDS == 0){ + sprintf(otmsg, "... (%d/%d)", i + 1, rnum); + odotcb(fname, odeum, otmsg); + } + } + cbmapclose(odeum->sortmap); + odeum->sortmap = cbmapopenex(odcachebnum); + return TRUE; +} + + +/* Compare two pairs of structures of a search result. + `a' specifies the pointer to the region of one pair. + `b' specifies the pointer to the region of the other pair. + The return value is positive if the former is big, negative if the latter is big, 0 if both + are equivalent. */ +static int odsortcompare(const void *a, const void *b){ + ODPAIR *ap, *bp; + int rv; + assert(a && b); + ap = (ODPAIR *)a; + bp = (ODPAIR *)b; + rv = bp->score - ap->score; + if(rv != 0) return rv; + return ap->id - bp->id; +} + + +/* Purge the elements of the deleted documents from the inverted index. + `odeum' specifies a database handle. + `fname' specifies the name of caller function. + If successful, the return value is true, else, it is false. */ +static int odpurgeindex(ODEUM *odeum, const char *fname){ + ODPAIR *pairs; + char *kbuf, *vbuf, otmsg[OD_OTCBBUFSIZ]; + int i, rnum, tnum, ksiz, vsiz, pnum, wi; + assert(odeum); + if((rnum = crrnum(odeum->indexdb)) < 1) return TRUE; + if(odotcb) odotcb(fname, odeum, "purging dispensable regions"); + if(!criterinit(odeum->indexdb)) return FALSE; + tnum = 0; + while(TRUE){ + if(!(kbuf = criternext(odeum->indexdb, &ksiz))){ + if(dpecode != DP_ENOITEM) return FALSE; + break; + } + if(!(vbuf = crget(odeum->indexdb, kbuf, ksiz, 0, -1, &vsiz))){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + free(kbuf); + return FALSE; + } + pairs = (ODPAIR *)vbuf; + pnum = vsiz / sizeof(ODPAIR); + wi = 0; + for(i = 0; i < pnum; i++){ + if(crvsiz(odeum->docsdb, (char *)&(pairs[i].id), sizeof(int)) != -1){ + pairs[wi++] = pairs[i]; + } + } + if(wi > 0){ + if(!crput(odeum->indexdb, kbuf, ksiz, vbuf, wi * sizeof(ODPAIR), CR_DOVER)){ + free(vbuf); + free(kbuf); + return FALSE; + } + } else { + if(!crout(odeum->indexdb, kbuf, ksiz)){ + free(vbuf); + free(kbuf); + return FALSE; + } + } + free(vbuf); + free(kbuf); + if(odotcb && (tnum + 1) % OD_OTPERWORDS == 0){ + sprintf(otmsg, "... (%d/%d)", tnum + 1, rnum); + odotcb(fname, odeum, otmsg); + } + tnum++; + } + return TRUE; +} + + +/* Create a map of a document array. + `pairs' specifies the pointer to a document array. + `num' specifies the number of elements of the array. + The return value is a map of the document array. */ +static CBMAP *odpairsmap(const ODPAIR *pairs, int num){ + CBMAP *map; + int i; + assert(pairs && num >= 0); + map = cbmapopen(); + for(i = 0; i < num; i++){ + cbmapput(map, (char *)&(pairs[i].id), sizeof(int), + (char *)&(pairs[i].score), sizeof(int), TRUE); + } + return map; +} + + +/* compare two pairs of structures of words in a document. + `a' specifies the pointer to the region of one word. + `b' specifies the pointer to the region of the other word. + The return value is positive if the former is big, negative if the latter is big, 0 if both + are equivalent. */ +static int odwordcompare(const void *a, const void *b){ + ODWORD *ap, *bp; + int rv; + assert(a && b); + ap = (ODWORD *)a; + bp = (ODWORD *)b; + if((rv = bp->num - ap->num) != 0) return rv; + if((rv = strlen(bp->word) - strlen(ap->word)) != 0) return rv; + return strcmp(ap->word, bp->word); +} + + +/* Match an operator without taking it off the token list. + `odeum' specifies a database handle. + `tokens' specifies a list handle of tokens. + The return value is whether the next token is an operator. */ +static int odmatchoperator(ODEUM *odeum, CBLIST *tokens){ + const char *tk = NULL; + int tk_len = 0; + tk = cblistval(tokens, 0, &tk_len); + if(tk && (tk[0] == '&' || tk[0] == '|' || tk[0] == '!')) return 1; + return 0; +} + + +/* Implements the subexpr part of the grammar. + `odeum' specifies a database handle. + `tokens' specifies a list handle of tokens. + `nwords' specifies a list handle of normalized words. + `np' specifies the pointer to a variable to which the number of the elements of the return + value is assigned. + `errors' specifies a list handle into which error messages are stored. + The return value is the pointer to an array of document IDs. */ +static ODPAIR *odparsesubexpr(ODEUM *odeum, CBLIST *tokens, CBLIST *nwords, int *np, + CBLIST *errors){ + char *tk = NULL; + int tk_len = 0; + char *nword = NULL; /* used to do the actual search, should match with tokens */ + ODPAIR *result = NULL; + int result_num = 0; + int i; + double ival; + if((tk = cblistshift(tokens, &tk_len)) != NULL){ + assert(tk != NULL); + if(tk[0] == '('){ + free(tk); + /* recurse into expr */ + result = odparseexpr(odeum, tokens, nwords, &result_num, errors); + /* match right token RPAREN */ + tk = cblistshift(tokens, &tk_len); + /* print an error if either we didn't get anything or we didn't get a ) */ + if(tk == NULL){ + if(errors) cblistpush(errors, "Expression ended without closing ')'", -1); + } else if(tk[0] != ')'){ + if(errors) cblistpush(errors, "Un-balanced parenthesis.", -1); + } + } else if(odeum->statechars[*(unsigned char *)tk] == 0){ + /* Perform odsearch with the next norm word that isn't an operator. */ + nword = cblistshift(nwords, NULL); + assert(nword != NULL); + if((result = odsearch(odeum, nword, -1, &result_num)) != NULL){ + /* TF-IDF tuning */ + ival = odlogarithm(result_num); + ival = (ival * ival) / 4.0; + if(ival < 4.0) ival = 4.0; + for(i = 0; i < result_num; i++){ + result[i].score = (int)(result[i].score / ival); + } + } + free(nword); + } else { + if(errors) cblistpush(errors, "Invalid sub-expression. Expected '(' or WORD.", -1); + result = cbmalloc(1); + result_num = 0; + } + /* done with the token */ + free(tk); + } + *np = result_num; + return result; +} + + +/* Implements the actual recursive decent parser for the mini query language. + `odeum' specifies a database handle. + `tokens' specifies a list handle of tokens. + `nwords' specifies a list handle of normalized words. + `np' specifies the pointer to a variable to which the number of the elements of the return + value is assigned. + `errors' specifies a list handle into which error messages are stored. + The return value is the pointer to an array of document IDs. + It simply parses an initial subexpr, and then loops over as many (operator subexpr) + sequences as it can find. The odmatchoperator function handles injecting a default & + between consecutive words. */ +static ODPAIR *odparseexpr(ODEUM *odeum, CBLIST *tokens, CBLIST *nwords, int *np, + CBLIST *errors){ + ODPAIR *left = NULL; + ODPAIR *right = NULL; + ODPAIR *temp = NULL; + int left_num = 0; + int right_num = 0; + int temp_num = 0; + char *op = NULL; + int op_len = 0; + if(!(left = odparsesubexpr(odeum, tokens, nwords, &left_num, errors))) return NULL; + /* expr ::= subexpr ( op subexpr )* */ + while(odmatchoperator(odeum, tokens)){ + op = cblistshift(tokens, &op_len); + if(!(right = odparsesubexpr(odeum, tokens, nwords, &right_num, errors))){ + free(op); + free(left); + return NULL; + } + switch(op[0]){ + case '&': + temp = odpairsand(left, left_num, right, right_num, &temp_num); + break; + case '|': + temp = odpairsor(left, left_num, right, right_num, &temp_num); + break; + case '!': + temp = odpairsnotand(left, left_num, right, right_num, &temp_num); + break; + default: + if(errors) cblistpush(errors, "Invalid operator. Expected '&', '|', or '!'.", -1); + break; + } + if(temp){ + /* an operator was done so we must swap it with the left */ + free(left); left = NULL; + left = temp; + left_num = temp_num; + } + free(op); + if(right) free(right); + } + *np = left_num; + return left; +} + + +/* Processes the tokens in order to break them up further. + `odeum' specifies a database handle. + `tokens' specifies a list handle of tokens. */ +static void odfixtokens(ODEUM *odeum, CBLIST *tokens){ + const char *tk = NULL; + int tk_len = 0; + int i = 0; + int lastword = 0; + for(i = 0; i < cblistnum(tokens); i++){ + tk = cblistval(tokens, i, &tk_len); + assert(tk); + if(tk[0] == '&' || tk[0] == '|' || tk[0] == '!' || tk[0] == '(' || tk[0] == ')'){ + lastword = 0; + if(tk_len > 1){ + /* need to break it up for the next loop around */ + tk = cblistremove(tokens, i, &tk_len); + cblistinsert(tokens, i, tk, 1); + cblistinsert(tokens, i+1, tk+1, tk_len-1); + free((char *)tk); + } + } else if(odeum->statechars[*(unsigned char *)tk] == 0){ + /* if the last one was a word and this is a word then we need a default & between them */ + if(lastword){ + cblistinsert(tokens, i, "&", 1); + i++; + } + lastword = 1; + } + } +} + + +/* Cleans out the parts of the normalized word list that are not considered words. + `odeum' specifies a database handle. + `tokens' specifies a list handle of tokens. */ +static void odcleannormalized(ODEUM *odeum, CBLIST *nwords){ + char *tk = NULL; + int tk_len = 0; + int i = 0; + for(i = 0; i < cblistnum(nwords); i++){ + tk = (char *)cblistval(nwords, i, &tk_len); + if(tk_len == 0 || (!odeum->statechars[*(unsigned char *)tk] == 0)){ + /* not a word so delete it */ + tk = cblistremove(nwords, i, &tk_len); + free(tk); + i--; + } + } +} + + + +/* END OF FILE */ diff --git a/qdbm/odeum.h b/qdbm/odeum.h new file mode 100644 index 00000000..62def9ee --- /dev/null +++ b/qdbm/odeum.h @@ -0,0 +1,590 @@ +/************************************************************************************************* + * The inverted API of QDBM + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#ifndef _ODEUM_H /* duplication check */ +#define _ODEUM_H + +#if defined(__cplusplus) /* export for C++ */ +extern "C" { +#endif + + +#include +#include +#include +#include +#include +#include + + +#if defined(_MSC_VER) && !defined(QDBM_INTERNAL) && !defined(QDBM_STATIC) +#define MYEXTERN extern __declspec(dllimport) +#else +#define MYEXTERN extern +#endif + + + +/************************************************************************************************* + * API + *************************************************************************************************/ + + +typedef struct { /* type of structure for a database handle */ + char *name; /* name of the database directory */ + int wmode; /* whether to be writable */ + int fatal; /* whether a fatal error occured */ + int inode; /* inode of the database directory */ + CURIA *docsdb; /* database handle for documents */ + CURIA *indexdb; /* database handle for the inverted index */ + VILLA *rdocsdb; /* database handle for the reverse dictionary */ + CBMAP *cachemap; /* cache for dirty buffers of words */ + int cacheasiz; /* total allocated size of dirty buffers */ + CBMAP *sortmap; /* map handle for candidates of sorting */ + int dmax; /* max number of the document ID */ + int dnum; /* number of the documents */ + int ldid; /* ID number of the last registered document */ + char statechars[256]; /* state of single byte characters */ +} ODEUM; + +typedef struct { /* type of structure for a document handle */ + int id; /* ID number */ + char *uri; /* uniform resource identifier */ + CBMAP *attrs; /* map handle for attrubutes */ + CBLIST *nwords; /* list handle for words in normalized form */ + CBLIST *awords; /* list handle for words in appearance form */ +} ODDOC; + +typedef struct { /* type of structure for an element of search result */ + int id; /* ID number of the document */ + int score; /* score of the document */ +} ODPAIR; + +enum { /* enumeration for open modes */ + OD_OREADER = 1 << 0, /* open as a reader */ + OD_OWRITER = 1 << 1, /* open as a writer */ + OD_OCREAT = 1 << 2, /* a writer creating */ + OD_OTRUNC = 1 << 3, /* a writer truncating */ + OD_ONOLCK = 1 << 4, /* open without locking */ + OD_OLCKNB = 1 << 5 /* lock without blocking */ +}; + + +/* Get a database handle. + `name' specifies the name of a database directory. + `omode' specifies the connection mode: `OD_OWRITER' as a writer, `OD_OREADER' as a reader. + If the mode is `OD_OWRITER', the following may be added by bitwise or: `OD_OCREAT', which + means it creates a new database if not exist, `OD_OTRUNC', which means it creates a new + database regardless if one exists. Both of `OD_OREADER' and `OD_OWRITER' can be added to by + bitwise or: `OD_ONOLCK', which means it opens a database directory without file locking, or + `OD_OLCKNB', which means locking is performed without blocking. + The return value is the database handle or `NULL' if it is not successful. + While connecting as a writer, an exclusive lock is invoked to the database directory. + While connecting as a reader, a shared lock is invoked to the database directory. + The thread blocks until the lock is achieved. If `OD_ONOLCK' is used, the application is + responsible for exclusion control. */ +ODEUM *odopen(const char *name, int omode); + + +/* Close a database handle. + `odeum' specifies a database handle. + If successful, the return value is true, else, it is false. + Because the region of a closed handle is released, it becomes impossible to use the handle. + Updating a database is assured to be written when the handle is closed. If a writer opens + a database but does not close it appropriately, the database will be broken. */ +int odclose(ODEUM *odeum); + + +/* Store a document. + `odeum' specifies a database handle connected as a writer. + `doc' specifies a document handle. + `wmax' specifies the max number of words to be stored in the document database. If it is + negative, the number is unlimited. + `over' specifies whether the data of the duplicated document is overwritten or not. If it + is false and the URI of the document is duplicated, the function returns as an error. + If successful, the return value is true, else, it is false. */ +int odput(ODEUM *odeum, ODDOC *doc, int wmax, int over); + + +/* Delete a document specified by a URI. + `odeum' specifies a database handle connected as a writer. + `uri' specifies the string of the URI of a document. + If successful, the return value is true, else, it is false. False is returned when no + document corresponds to the specified URI. */ +int odout(ODEUM *odeum, const char *uri); + + +/* Delete a document specified by an ID number. + `odeum' specifies a database handle connected as a writer. + `id' specifies the ID number of a document. + If successful, the return value is true, else, it is false. False is returned when no + document corresponds to the specified ID number. */ +int odoutbyid(ODEUM *odeum, int id); + + +/* Retrieve a document specified by a URI. + `odeum' specifies a database handle. + `uri' specifies the string the URI of a document. + If successful, the return value is the handle of the corresponding document, else, it is + `NULL'. `NULL' is returned when no document corresponds to the specified URI. + Because the handle of the return value is opened with the function `oddocopen', it should + be closed with the function `oddocclose'. */ +ODDOC *odget(ODEUM *odeum, const char *uri); + + +/* Retrieve a document by an ID number. + `odeum' specifies a database handle. + `id' specifies the ID number of a document. + If successful, the return value is the handle of the corresponding document, else, it is + `NULL'. `NULL' is returned when no document corresponds to the specified ID number. + Because the handle of the return value is opened with the function `oddocopen', it should + be closed with the function `oddocclose'. */ +ODDOC *odgetbyid(ODEUM *odeum, int id); + + +/* Retrieve the ID of the document specified by a URI. + `odeum' specifies a database handle. + `uri' specifies the string the URI of a document. + If successful, the return value is the ID number of the document, else, it is -1. -1 is + returned when no document corresponds to the specified URI. */ +int odgetidbyuri(ODEUM *odeum, const char *uri); + + +/* Check whether the document specified by an ID number exists. + `odeum' specifies a database handle. + `id' specifies the ID number of a document. + The return value is true if the document exists, else, it is false. */ +int odcheck(ODEUM *odeum, int id); + + +/* Search the inverted index for documents including a particular word. + `odeum' specifies a database handle. + `word' specifies a searching word. + `max' specifies the max number of documents to be retrieve. + `np' specifies the pointer to a variable to which the number of the elements of the return + value is assigned. + If successful, the return value is the pointer to an array, else, it is `NULL'. Each + element of the array is a pair of the ID number and the score of a document, and sorted in + descending order of their scores. Even if no document corresponds to the specified word, + it is not error but returns an dummy array. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. Note that each element of the array + of the return value can be data of a deleted document. */ +ODPAIR *odsearch(ODEUM *odeum, const char *word, int max, int *np); + + +/* Get the number of documents including a word. + `odeum' specifies a database handle. + `word' specifies a searching word. + If successful, the return value is the number of documents including the word, else, it is -1. + Because this function does not read the entity of the inverted index, it is faster than + `odsearch'. */ +int odsearchdnum(ODEUM *odeum, const char *word); + + +/* Initialize the iterator of a database handle. + `odeum' specifies a database handle. + If successful, the return value is true, else, it is false. + The iterator is used in order to access every document stored in a database. */ +int oditerinit(ODEUM *odeum); + + +/* Get the next key of the iterator. + `odeum' specifies a database handle. + If successful, the return value is the handle of the next document, else, it is `NULL'. + `NULL' is returned when no document is to be get out of the iterator. + It is possible to access every document by iteration of calling this function. However, + it is not assured if updating the database is occurred while the iteration. Besides, the + order of this traversal access method is arbitrary, so it is not assured that the order of + string matches the one of the traversal access. Because the handle of the return value is + opened with the function `oddocopen', it should be closed with the function `oddocclose'. */ +ODDOC *oditernext(ODEUM *odeum); + + +/* Synchronize updating contents with the files and the devices. + `odeum' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. + This function is useful when another process uses the connected database directory. */ +int odsync(ODEUM *odeum); + + +/* Optimize a database. + `odeum' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. + Elements of the deleted documents in the inverted index are purged. */ +int odoptimize(ODEUM *odeum); + + +/* Get the name of a database. + `odeum' specifies a database handle. + If successful, the return value is the pointer to the region of the name of the database, + else, it is `NULL'. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *odname(ODEUM *odeum); + + +/* Get the total size of database files. + `odeum' specifies a database handle. + If successful, the return value is the total size of the database files, else, it is -1.0. */ +double odfsiz(ODEUM *odeum); + + +/* Get the total number of the elements of the bucket arrays in the inverted index. + `odeum' specifies a database handle. + If successful, the return value is the total number of the elements of the bucket arrays, + else, it is -1. */ +int odbnum(ODEUM *odeum); + + +/* Get the total number of the used elements of the bucket arrays in the inverted index. + `odeum' specifies a database handle. + If successful, the return value is the total number of the used elements of the bucket + arrays, else, it is -1. */ +int odbusenum(ODEUM *odeum); + + +/* Get the number of the documents stored in a database. + `odeum' specifies a database handle. + If successful, the return value is the number of the documents stored in the database, else, + it is -1. */ +int oddnum(ODEUM *odeum); + + +/* Get the number of the words stored in a database. + `odeum' specifies a database handle. + If successful, the return value is the number of the words stored in the database, else, + it is -1. + Because of the I/O buffer, the return value may be less than the hard number. */ +int odwnum(ODEUM *odeum); + + +/* Check whether a database handle is a writer or not. + `odeum' specifies a database handle. + The return value is true if the handle is a writer, false if not. */ +int odwritable(ODEUM *odeum); + + +/* Check whether a database has a fatal error or not. + `odeum' specifies a database handle. + The return value is true if the database has a fatal error, false if not. */ +int odfatalerror(ODEUM *odeum); + + +/* Get the inode number of a database directory. + `odeum' specifies a database handle. + The return value is the inode number of the database directory. */ +int odinode(ODEUM *odeum); + + +/* Get the last modified time of a database. + `odeum' specifies a database handle. + The return value is the last modified time of the database. */ +time_t odmtime(ODEUM *odeum); + + +/* Merge plural database directories. + `name' specifies the name of a database directory to create. + `elemnames' specifies a list of names of element databases. + If successful, the return value is true, else, it is false. + If two or more documents which have the same URL come in, the first one is adopted and the + others are ignored. */ +int odmerge(const char *name, const CBLIST *elemnames); + + +/* Remove a database directory. + `name' specifies the name of a database directory. + If successful, the return value is true, else, it is false. + A database directory can contain databases of other APIs of QDBM, they are also removed by + this function. */ +int odremove(const char *name); + + +/* Get a document handle. + `uri' specifies the URI of a document. + The return value is a document handle. + The ID number of a new document is not defined. It is defined when the document is stored + in a database. */ +ODDOC *oddocopen(const char *uri); + + +/* Close a document handle. + `doc' specifies a document handle. + Because the region of a closed handle is released, it becomes impossible to use the handle. */ +void oddocclose(ODDOC *doc); + + +/* Add an attribute to a document. + `doc' specifies a document handle. + `name' specifies the string of the name of an attribute. + `value' specifies the string of the value of the attribute. */ +void oddocaddattr(ODDOC *doc, const char *name, const char *value); + + +/* Add a word to a document. + `doc' specifies a document handle. + `normal' specifies the string of the normalized form of a word. Normalized forms are + treated as keys of the inverted index. If the normalized form of a word is an empty + string, the word is not reflected in the inverted index. + `asis' specifies the string of the appearance form of the word. Appearance forms are used + after the document is retrieved by an application. */ +void oddocaddword(ODDOC *doc, const char *normal, const char *asis); + + +/* Get the ID number of a document. + `doc' specifies a document handle. + The return value is the ID number of a document. */ +int oddocid(const ODDOC *doc); + + +/* Get the URI of a document. + `doc' specifies a document handle. + The return value is the string of the URI of a document. */ +const char *oddocuri(const ODDOC *doc); + + +/* Get the value of an attribute of a document. + `doc' specifies a document handle. + `name' specifies the string of the name of an attribute. + The return value is the string of the value of the attribute, or `NULL' if no attribute + corresponds. */ +const char *oddocgetattr(const ODDOC *doc, const char *name); + + +/* Get the list handle contains words in normalized form of a document. + `doc' specifies a document handle. + The return value is the list handle contains words in normalized form. */ +const CBLIST *oddocnwords(const ODDOC *doc); + + +/* Get the list handle contains words in appearance form of a document. + `doc' specifies a document handle. + The return value is the list handle contains words in appearance form. */ +const CBLIST *oddocawords(const ODDOC *doc); + + +/* Get the map handle contains keywords in normalized form and their scores. + `doc' specifies a document handle. + `max' specifies the max number of keywords to get. + `odeum' specifies a database handle with which the IDF for weighting is calculate. + If it is `NULL', it is not used. + The return value is the map handle contains keywords and their scores. Scores are expressed + as decimal strings. + Because the handle of the return value is opened with the function `cbmapopen', it should + be closed with the function `cbmapclose' if it is no longer in use. */ +CBMAP *oddocscores(const ODDOC *doc, int max, ODEUM *odeum); + + +/* Break a text into words in appearance form. + `text' specifies the string of a text. + The return value is the list handle contains words in appearance form. + Words are separated with space characters and such delimiters as period, comma and so on. + Because the handle of the return value is opened with the function `cblistopen', it should + be closed with the function `cblistclose' if it is no longer in use. */ +CBLIST *odbreaktext(const char *text); + + +/* Make the normalized form of a word. + `asis' specifies the string of the appearance form of a word. + The return value is is the string of the normalized form of the word. + Alphabets of the ASCII code are unified into lower cases. Words composed of only delimiters + are treated as empty strings. Because the region of the return value is allocated with the + `malloc' call, it should be released with the `free' call if it is no longer in use. */ +char *odnormalizeword(const char *asis); + + +/* Get the common elements of two sets of documents. + `apairs' specifies the pointer to the former document array. + `anum' specifies the number of the elements of the former document array. + `bpairs' specifies the pointer to the latter document array. + `bnum' specifies the number of the elements of the latter document array. + `np' specifies the pointer to a variable to which the number of the elements of the return + value is assigned. + The return value is the pointer to a new document array whose elements commonly belong to + the specified two sets. + Elements of the array are sorted in descending order of their scores. Because the region of + the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +ODPAIR *odpairsand(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np); + + +/* Get the sum of elements of two sets of documents. + `apairs' specifies the pointer to the former document array. + `anum' specifies the number of the elements of the former document array. + `bpairs' specifies the pointer to the latter document array. + `bnum' specifies the number of the elements of the latter document array. + `np' specifies the pointer to a variable to which the number of the elements of the return + value is assigned. + The return value is the pointer to a new document array whose elements belong to both or + either of the specified two sets. + Elements of the array are sorted in descending order of their scores. Because the region of + the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +ODPAIR *odpairsor(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np); + + +/* Get the difference set of documents. + `apairs' specifies the pointer to the former document array. + `anum' specifies the number of the elements of the former document array. + `bpairs' specifies the pointer to the latter document array of the sum of elements. + `bnum' specifies the number of the elements of the latter document array. + `np' specifies the pointer to a variable to which the number of the elements of the return + value is assigned. + The return value is the pointer to a new document array whose elements belong to the former + set but not to the latter set. + Elements of the array are sorted in descending order of their scores. Because the region of + the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +ODPAIR *odpairsnotand(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np); + + +/* Sort a set of documents in descending order of scores. + `pairs' specifies the pointer to a document array. + `pnum' specifies the number of the elements of the document array. */ +void odpairssort(ODPAIR *pairs, int pnum); + + +/* Get the natural logarithm of a number. + `x' specifies a number. + The return value is the natural logarithm of the number. If the number is equal to or less + than 1.0, the return value is 0.0. + This function is useful when an application calculates the IDF of search results. */ +double odlogarithm(double x); + + +/* Get the cosine of the angle of two vectors. + `avec' specifies the pointer to one array of numbers. + `bvec' specifies the pointer to the other array of numbers. + `vnum' specifies the number of elements of each array. + The return value is the cosine of the angle of two vectors. + This function is useful when an application calculates similarity of documents. */ +double odvectorcosine(const int *avec, const int *bvec, int vnum); + + +/* Set the global tuning parameters. + `ibnum' specifies the number of buckets for inverted indexes. + `idnum' specifies the division number of inverted index. + `cbnum' specifies the number of buckets for dirty buffers. + `csiz' specifies the maximum bytes to use memory for dirty buffers. + The default setting is equivalent to `odsettuning(32749, 7, 262139, 8388608)'. This function + should be called before opening a handle. */ +void odsettuning(int ibnum, int idnum, int cbnum, int csiz); + + +/* Break a text into words and store appearance forms and normalized form into lists. + `odeum' specifies a database handle. + `text' specifies the string of a text. + `awords' specifies a list handle into which appearance form is store. + `nwords' specifies a list handle into which normalized form is store. If it is `NULL', it is + ignored. + Words are separated with space characters and such delimiters as period, comma and so on. */ +void odanalyzetext(ODEUM *odeum, const char *text, CBLIST *awords, CBLIST *nwords); + + +/* Set the classes of characters used by `odanalyzetext'. + `odeum' specifies a database handle. + `spacechars' spacifies a string contains space characters. + `delimchars' spacifies a string contains delimiter characters. + `gluechars' spacifies a string contains glue characters. */ +void odsetcharclass(ODEUM *odeum, const char *spacechars, const char *delimchars, + const char *gluechars); + + +/* Query a database using a small boolean query language. + `odeum' specifies a database handle. + 'query' specifies the text of the query. + `np' specifies the pointer to a variable to which the number of the elements of the return + value is assigned. + `errors' specifies a list handle into which error messages are stored. If it is `NULL', it + is ignored. + If successful, the return value is the pointer to an array, else, it is `NULL'. Each + element of the array is a pair of the ID number and the score of a document, and sorted in + descending order of their scores. Even if no document corresponds to the specified condition, + it is not error but returns an dummy array. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. Note that each element of the array + of the return value can be data of a deleted document. */ +ODPAIR *odquery(ODEUM *odeum, const char *query, int *np, CBLIST *errors); + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Get the internal database handle for documents. + `odeum' specifies a database handle. + The return value is the internal database handle for documents. + Note that the the returned handle should not be updated. */ +CURIA *odidbdocs(ODEUM *odeum); + + +/* Get the internal database handle for the inverted index. + `odeum' specifies a database handle. + The return value is the internal database handle for the inverted index. + Note that the the returned handle should not be updated. */ +CURIA *odidbindex(ODEUM *odeum); + + +/* Get the internal database handle for the reverse dictionary. + `odeum' specifies a database handle. + The return value is the internal database handle for the reverse dictionary. + Note that the the returned handle should not be updated. */ +VILLA *odidbrdocs(ODEUM *odeum); + + +/* Set the call back function called in merging. + `otcb' specifires the pointer to a function to report outturn. Its first argument is the name + of processing function. Its second argument is the handle of the database being processed. + Its third argument is ths string of a log message. If it is `NULL', the call back function is + cleared. */ +void odsetotcb(void (*otcb)(const char *, ODEUM *, const char *)); + + +/* Get the positive one of square roots of a number. + `x' specifies a number. + The return value is the positive one of square roots of a number. If the number is equal to + or less than 0.0, the return value is 0.0. */ +double odsquareroot(double x); + + +/* Get the absolute of a vector. + `vec' specifies the pointer to an array of numbers. + `vnum' specifies the number of elements of the array. + The return value is the absolute of a vector. */ +double odvecabsolute(const int *vec, int vnum); + + +/* Get the inner product of two vectors. + `avec' specifies the pointer to one array of numbers. + `bvec' specifies the pointer to the other array of numbers. + `vnum' specifies the number of elements of each array. + The return value is the inner product of two vectors. */ +double odvecinnerproduct(const int *avec, const int *bvec, int vnum); + + + +#undef MYEXTERN + +#if defined(__cplusplus) /* export for C++ */ +} +#endif + +#endif /* duplication check */ + + +/* END OF FILE */ diff --git a/qdbm/odidx.c b/qdbm/odidx.c new file mode 100644 index 00000000..a4b5b406 --- /dev/null +++ b/qdbm/odidx.c @@ -0,0 +1,890 @@ +/************************************************************************************************* + * Utility for indexing document files into a database of Odeum + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define PATHCHR '/' /* delimiter character of path */ +#define EXTCHR '.' /* delimiter character of extension */ +#define CDIRSTR "." /* string of current directory */ +#define PDIRSTR ".." /* string of parent directory */ +#define MTDBNAME "_mtime" /* name of the database for last modified times */ +#define MTDBLRM 81 /* records in a leaf node of time database */ +#define MTDBNIM 192 /* records in a non-leaf node of time database */ +#define MTDBLCN 64 /* number of leaf cache of time database */ +#define MTDBNCN 32 /* number of non-leaf cache of time database */ +#define SCDBNAME "_score" /* name of the database for scores */ +#define SCDBBNUM 32749 /* bucket number of the score database */ +#define SCDBALIGN -3 /* alignment of the score database */ +#define PATHBUFSIZ 2048 /* size of a path buffer */ +#define MAXLOAD 0.85 /* max ratio of bucket loading */ +#define KEYNUM 32 /* number of keywords to store */ + + +/* for Win32 and RISC OS */ +#if defined(_WIN32) +#undef PATHCHR +#define PATHCHR '\\' +#undef EXTCHR +#define EXTCHR '.' +#undef CDIRSTR +#define CDIRSTR "." +#undef PDIRSTR +#define PDIRSTR ".." +#elif defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#undef PATHCHR +#define PATHCHR '.' +#undef EXTCHR +#define EXTCHR '/' +#undef CDIRSTR +#define CDIRSTR "@" +#undef PDIRSTR +#define PDIRSTR "^" +#endif + + +/* global variables */ +const char *progname; /* program name */ +int sigterm; /* flag for termination signal */ + + +/* function prototypes */ +int main(int argc, char **argv); +void setsignals(void); +void sigtermhandler(int num); +void usage(void); +int runregister(int argc, char **argv); +int runrelate(int argc, char **argv); +int runpurge(int argc, char **argv); +int bwimatchlist(const char *str, const CBLIST *keys); +char *fgetl(FILE *ifp); +void otcb(const char *fname, ODEUM *odeum, const char *msg); +void pdperror(const char *name); +void printferror(const char *format, ...); +void printfinfo(const char *format, ...); +const char *datestr(time_t t); +int proclist(const char *name, const char *lfile, int wmax, + const CBLIST *tsuflist, const CBLIST *hsuflist); +int procdir(const char *name, const char *dir, int wmax, + const CBLIST *tsuflist, const CBLIST *hsuflist); +int indexdir(ODEUM *odeum, VILLA *mtdb, const char *name, const char *dir, int wmax, + const CBLIST *tsuflist, const CBLIST *hsuflist); +int indexfile(ODEUM *odeum, VILLA *mtdb, const char *name, const char *file, int wmax, + const CBLIST *tsuflist, const CBLIST *hsuflist); +char *filetouri(const char *file); +ODDOC *makedocplain(const char *uri, const char *text, const char *date); +ODDOC *makedochtml(const char *uri, const char *html, const char *date); +CBMAP *htmlescpairs(void); +int procrelate(const char *name); +int procpurge(const char *name); + + +/* main routine */ +int main(int argc, char **argv){ + int rv; + cbstdiobin(); + progname = argv[0]; + sigterm = FALSE; + setsignals(); + if(argc < 2) usage(); + odsetotcb(otcb); + rv = 0; + if(!strcmp(argv[1], "register")){ + rv = runregister(argc, argv); + } else if(!strcmp(argv[1], "relate")){ + rv = runrelate(argc, argv); + } else if(!strcmp(argv[1], "purge")){ + rv = runpurge(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* set signal handlers */ +void setsignals(void){ + signal(1, sigtermhandler); + signal(2, sigtermhandler); + signal(3, sigtermhandler); + signal(13, sigtermhandler); + signal(15, sigtermhandler); +} + + +/* handler of termination signal */ +void sigtermhandler(int num){ + signal(num, SIG_DFL); + sigterm = TRUE; + printfinfo("the termination signal %d catched", num); +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: indexer of document files\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s register [-l file] [-wmax num] [-tsuf sufs] [-hsuf sufs] name [dir]\n", + progname); + fprintf(stderr, " %s relate name\n", progname); + fprintf(stderr, " %s purge name\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of register command */ +int runregister(int argc, char **argv){ + char *name, *dir, *lfile, *tsuf, *hsuf, path[PATHBUFSIZ]; + int i, wmax, plen, rv; + CBLIST *tsuflist, *hsuflist; + name = NULL; + dir = NULL; + lfile = NULL; + tsuf = NULL; + hsuf = NULL; + wmax = -1; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-l")){ + if(++i >= argc) usage(); + lfile = argv[i]; + } else if(!strcmp(argv[i], "-wmax")){ + if(++i >= argc) usage(); + wmax = atoi(argv[i]); + } else if(!strcmp(argv[i], "-tsuf")){ + if(++i >= argc) usage(); + tsuf = argv[i]; + } else if(!strcmp(argv[i], "-hsuf")){ + if(++i >= argc) usage(); + hsuf = argv[i]; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!dir){ + dir = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + if(!dir) dir = CDIRSTR; + plen = sprintf(path, "%s", dir); + if(plen > 1 && path[plen-1] == PATHCHR) path[plen-1] = '\0'; + tsuflist = cbsplit(tsuf ? tsuf : ".txt,.text", -1, ","); + hsuflist = cbsplit(hsuf ? hsuf : ".html,.htm", -1, ","); + if(lfile){ + rv = proclist(name, lfile, wmax, tsuflist, hsuflist); + } else { + rv = procdir(name, path, wmax, tsuflist, hsuflist); + } + cblistclose(hsuflist); + cblistclose(tsuflist); + return rv; +} + + +/* parse arguments of relate command */ +int runrelate(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = procrelate(name); + return rv; +} + + +/* parse arguments of purge command */ +int runpurge(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = procpurge(name); + return rv; +} + + +/* case insensitive backward matching with a list */ +int bwimatchlist(const char *str, const CBLIST *keys){ + int i; + for(i = 0; i < cblistnum(keys); i++){ + if(cbstrbwimatch(str, cblistval(keys, i, NULL))) return TRUE; + } + return FALSE; +} + + +/* read a line */ +char *fgetl(FILE *ifp){ + char *buf; + int c, len, blen; + buf = NULL; + len = 0; + blen = 256; + while((c = fgetc(ifp)) != EOF){ + if(blen <= len) blen *= 2; + buf = cbrealloc(buf, blen + 1); + if(c == '\n') c = '\0'; + buf[len++] = c; + if(c == '\0') break; + } + if(!buf) return NULL; + buf[len] = '\0'; + return buf; +} + + +/* report the outturn */ +void otcb(const char *fname, ODEUM *odeum, const char *msg){ + char *name; + name = odname(odeum); + printf("%s: %s: %s: %s\n", progname, fname, name, msg); + free(name); +} + + +/* print an error message */ +void pdperror(const char *name){ + printf("%s: ERROR: %s: %s\n", progname, name, dperrmsg(dpecode)); + fflush(stdout); +} + + +/* print formatted error string and flush the buffer */ +void printferror(const char *format, ...){ + va_list ap; + va_start(ap, format); + printf("%s: ERROR: ", progname); + vprintf(format, ap); + putchar('\n'); + fflush(stdout); + va_end(ap); +} + + +/* print formatted information string and flush the buffer */ +void printfinfo(const char *format, ...){ + va_list ap; + va_start(ap, format); + printf("%s: INFO: ", progname); + vprintf(format, ap); + putchar('\n'); + fflush(stdout); + va_end(ap); +} + + +/* get static string of the date */ +const char *datestr(time_t t){ + static char buf[32]; + struct tm *stp; + if(!(stp = localtime(&t))) return "0000/00/00 00:00:00"; + sprintf(buf, "%04d/%02d/%02d %02d:%02d:%02d", + stp->tm_year + 1900, stp->tm_mon + 1, stp->tm_mday, + stp->tm_hour, stp->tm_min, stp->tm_sec); + return buf; +} + + +/* processing with finding files in a list file */ +int proclist(const char *name, const char *lfile, int wmax, + const CBLIST *tsuflist, const CBLIST *hsuflist){ + ODEUM *odeum; + VILLA *mtdb; + FILE *ifp; + char *line, path[PATHBUFSIZ]; + int err, fatal; + if(!strcmp(lfile, "-")){ + ifp = stdin; + } else { + if(!(ifp = fopen(lfile, "rb"))){ + printferror("%s: file cannot be opened", lfile); + return 1; + } + } + printfinfo("%s: registration started", name); + if(!(odeum = odopen(name, OD_OWRITER | OD_OCREAT))){ + pdperror(name); + if(ifp != stdin) fclose(ifp); + return 1; + } + sprintf(path, "%s%c%s", name, PATHCHR, MTDBNAME); + if(!(mtdb = vlopen(path, VL_OWRITER | VL_OCREAT, VL_CMPLEX))){ + pdperror(name); + odclose(odeum); + if(ifp != stdin) fclose(ifp); + return 1; + } + vlsettuning(mtdb, MTDBLRM, MTDBNIM, MTDBLCN, MTDBNCN); + printfinfo("%s: database opened: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + err = FALSE; + while((line = fgetl(ifp)) != NULL){ + if(sigterm){ + printferror("aborting due to a termination signal"); + free(line); + err = TRUE; + break; + } + if(!indexfile(odeum, mtdb, name, line, wmax, tsuflist, hsuflist)) err = TRUE; + free(line); + } + fatal = odfatalerror(odeum); + printfinfo("%s: database closing: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + if(!vlclose(mtdb)){ + pdperror(name); + err = TRUE; + } + if(!odclose(odeum)){ + pdperror(name); + err = TRUE; + } + if(ifp != stdin) fclose(ifp); + if(err){ + printfinfo("%s: registration was over%s", name, fatal ? " with fatal error" : ""); + } else { + printfinfo("%s: registration completed successfully", name); + } + return err ? 1 : 0; +} + + +/* processing with finding files in a directory */ +int procdir(const char *name, const char *dir, int wmax, + const CBLIST *tsuflist, const CBLIST *hsuflist){ + ODEUM *odeum; + VILLA *mtdb; + char path[PATHBUFSIZ]; + int err, fatal; + printfinfo("%s: registration started", name); + if(!(odeum = odopen(name, OD_OWRITER | OD_OCREAT))){ + pdperror(name); + return 1; + } + sprintf(path, "%s%c%s", name, PATHCHR, MTDBNAME); + if(!(mtdb = vlopen(path, VL_OWRITER | VL_OCREAT, VL_CMPLEX))){ + pdperror(name); + odclose(odeum); + return 1; + } + vlsettuning(mtdb, MTDBLRM, MTDBNIM, MTDBLCN, MTDBNCN); + printfinfo("%s: database opened: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + err = FALSE; + if(!indexdir(odeum, mtdb, name, dir, wmax, tsuflist, hsuflist)) err = TRUE; + fatal = odfatalerror(odeum); + printfinfo("%s: database closing: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + if(!vlclose(mtdb)){ + pdperror(name); + err = TRUE; + } + if(!odclose(odeum)){ + pdperror(name); + err = TRUE; + } + if(err){ + printfinfo("%s: registration was over%s", name, fatal ? " with fatal error" : ""); + } else { + printfinfo("%s: registration completed successfully", name); + } + return err ? 1 : 0; +} + + +/* find and index files in a directory */ +int indexdir(ODEUM *odeum, VILLA *mtdb, const char *name, const char *dir, int wmax, + const CBLIST *tsuflist, const CBLIST *hsuflist){ + CBLIST *files; + const char *file; + char path[PATHBUFSIZ]; + int i, isroot, isdir, err; + if(!(files = cbdirlist(dir))){ + printferror("%s: directory cannot be opened", dir); + return FALSE; + } + isroot = dir[0] == PATHCHR && dir[1] == '\0'; + err = FALSE; + for(i = 0; i < cblistnum(files); i++){ + if(sigterm){ + printferror("aborting due to a termination signal"); + cblistclose(files); + return FALSE; + } + file = cblistval(files, i, NULL); + if(!strcmp(file, CDIRSTR) || !strcmp(file, PDIRSTR)) continue; + if(isroot){ + sprintf(path, "%s%s", dir, file); + } else { + sprintf(path, "%s%c%s", dir, PATHCHR, file); + } + if(!cbfilestat(path, &isdir, NULL, NULL)){ + printferror("%s: file does not exist", file); + err = TRUE; + continue; + } + if(isdir){ + if(!indexdir(odeum, mtdb, name, path, wmax, tsuflist, hsuflist)) err = TRUE; + } else { + if(!indexfile(odeum, mtdb, name, path, wmax, tsuflist, hsuflist)) err = TRUE; + } + } + cblistclose(files); + return err ? FALSE : TRUE; +} + + +/* index a file into the database */ +int indexfile(ODEUM *odeum, VILLA *mtdb, const char *name, const char *file, int wmax, + const CBLIST *tsuflist, const CBLIST *hsuflist){ + static int cnt = 0; + char *vbuf, *buf, *uri; + const char *title; + int size, hot, vsiz, wnum, bnum; + time_t mtime; + ODDOC *doc; + if(!cbfilestat(file, NULL, &size, &mtime)){ + printferror("%s: file does not exist", file); + return FALSE; + } + hot = TRUE; + if((vbuf = vlget(mtdb, file, -1, &vsiz)) != NULL){ + if(vsiz == sizeof(int) && mtime <= *(int *)vbuf) hot = FALSE; + free(vbuf); + } + if(!hot){ + printfinfo("%s: passed", file); + return TRUE; + } + doc = NULL; + uri = filetouri(file); + if(bwimatchlist(file, tsuflist)){ + if(!(buf = cbreadfile(file, NULL))){ + printferror("%s: file cannot be opened", file); + return FALSE; + } + doc = makedocplain(uri, buf, datestr(mtime)); + free(buf); + } else if(bwimatchlist(file, hsuflist)){ + if(!(buf = cbreadfile(file, NULL))){ + printferror("%s: file cannot be opened", file); + return FALSE; + } + doc = makedochtml(uri, buf, datestr(mtime)); + free(buf); + } + free(uri); + if(doc){ + if(!(title = oddocgetattr(doc, "title")) || strlen(title) < 1){ + if((title = strrchr(file, PATHCHR)) != NULL){ + title++; + } else { + title = file; + } + oddocaddattr(doc, "title", title); + } + if(odput(odeum, doc, wmax, TRUE) && + vlput(mtdb, file, -1, (char *)&mtime, sizeof(int), VL_DOVER)){ + printfinfo("%s: registered: id=%d wnum=%d", + file, oddocid(doc), cblistnum(oddocnwords(doc))); + cnt++; + } else { + pdperror(file); + } + oddocclose(doc); + } + wnum = odwnum(odeum); + bnum = odbnum(odeum); + if(wnum != -1 && bnum != -1 && (double)wnum / (double)bnum > MAXLOAD){ + printfinfo("%s: optimizing started: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + if(!odoptimize(odeum)){ + pdperror(file); + return FALSE; + } + printfinfo("%s: optimizing completed: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + } + if(cnt >= 256){ + printfinfo("%s: database status: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + cnt = 0; + } + return TRUE; +} + + +/* make the url from file path */ +char *filetouri(const char *file){ + CBLIST *list; + char str[PATHBUFSIZ], *wp, *enc; + const char *name; + int i, nsiz; + sprintf(str, "%c", PATHCHR); + list = cbsplit(file, -1, str); + wp = str; + for(i = 0; i < cblistnum(list); i++){ + if(i > 0) *(wp++) = '/'; + name = cblistval(list, i, &nsiz); + enc = cburlencode(name, nsiz); + wp += sprintf(wp, "%s", enc); + free(enc); + } + cblistclose(list); + *wp = '\0'; + return cbmemdup(str, -1); +} + + +/* make a document of plain text */ +ODDOC *makedocplain(const char *uri, const char *text, const char *date){ + ODDOC *doc; + CBLIST *awords; + const char *asis; + char *normal; + int i; + doc = oddocopen(uri); + if(date) oddocaddattr(doc, "date", date); + awords = odbreaktext(text); + for(i = 0; i < cblistnum(awords); i++){ + asis = cblistval(awords, i, NULL); + normal = odnormalizeword(asis); + oddocaddword(doc, normal, asis); + free(normal); + } + cblistclose(awords); + return doc; +} + + +/* make a document of HTML */ +ODDOC *makedochtml(const char *uri, const char *html, const char *date){ + ODDOC *doc; + CBMAP *pairs; + CBLIST *elems, *awords; + const char *text, *asis; + char *rtext, *normal; + int i, j, body; + pairs = htmlescpairs(); + doc = oddocopen(uri); + if(date) oddocaddattr(doc, "date", date); + elems = cbxmlbreak(html, TRUE); + body = FALSE; + for(i = 0; i < cblistnum(elems); i++){ + text = cblistval(elems, i, NULL); + if(cbstrfwimatch(text, "= 0){ + if(rtext[j] != ' ') break; + rtext[j] = '\0'; + } + for(j = 0; rtext[j] != '\0'; j++){ + if(rtext[j] != ' ') break; + } + oddocaddattr(doc, "title", rtext + j); + awords = odbreaktext(rtext); + for(j = 0; j < cblistnum(awords); j++){ + asis = cblistval(awords, j, NULL); + normal = odnormalizeword(asis); + oddocaddword(doc, normal, ""); + free(normal); + } + cblistclose(awords); + free(rtext); + } + } else if(cbstrfwimatch(text, ">", "(1/4)", "(1/2)", + "(3/4)", "?", "A", "A", "A", "A", "A", "A", "AE", "C", + "E", "E", "E", "E", "I", "I", "I", "I", "D", "N", + "O", "O", "O", "O", "O", "*", "O", "U", "U", "U", + "U", "Y", "P", "s", "a", "a", "a", "a", "a", "a", + "ae", "c", "e", "e", "e", "e", "i", "i", "i", "i", + "o", "n", "o", "o", "o", "o", "o", "/", "o", "u", + "u", "u", "u", "y", "p", "y", NULL + }; + static CBMAP *pairs = NULL; + char kbuf[8], vbuf[8]; + int i, ksiz, vsiz; + if(pairs) return pairs; + pairs = cbmapopen(); + cbglobalgc(pairs, (void (*)(void *))cbmapclose); + cbmapput(pairs, "&", -1, "&", -1, TRUE); + cbmapput(pairs, "<", -1, "<", -1, TRUE); + cbmapput(pairs, ">", -1, ">", -1, TRUE); + cbmapput(pairs, """, -1, "\"", -1, TRUE); + cbmapput(pairs, "'", -1, "'", -1, TRUE); + cbmapput(pairs, " ", -1, " ", -1, TRUE); + cbmapput(pairs, "©", -1, "(C)", -1, TRUE); + cbmapput(pairs, "®", -1, "(R)", -1, TRUE); + cbmapput(pairs, "™", -1, "(TM)", -1, TRUE); + for(i = 1; i <= 127; i++){ + ksiz = sprintf(kbuf, "&#%d;", i); + vsiz = sprintf(vbuf, "%c", i); + cbmapput(pairs, kbuf, ksiz, vbuf, vsiz, TRUE); + } + cbmapput(pairs, "‚", -1, ",", -1, TRUE); + cbmapput(pairs, "„", -1, ",,", -1, TRUE); + cbmapput(pairs, "…", -1, "...", -1, TRUE); + cbmapput(pairs, "‹", -1, "<", -1, TRUE); + cbmapput(pairs, "‘", -1, "'", -1, TRUE); + cbmapput(pairs, "’", -1, "'", -1, TRUE); + cbmapput(pairs, "“", -1, "\"", -1, TRUE); + cbmapput(pairs, "”", -1, "\"", -1, TRUE); + cbmapput(pairs, "–", -1, "-", -1, TRUE); + cbmapput(pairs, "—", -1, "-", -1, TRUE); + cbmapput(pairs, "˜", -1, "~", -1, TRUE); + cbmapput(pairs, "™", -1, "(TM)", -1, TRUE); + cbmapput(pairs, "›", -1, ">", -1, TRUE); + for(i = 0; latinext[i]; i++){ + ksiz = sprintf(kbuf, "&#%d;", i + 160); + cbmapput(pairs, kbuf, ksiz, latinext[i], -1, TRUE); + } + return pairs; +} + + +/* register scores of documents */ +int procrelate(const char *name){ + ODEUM *odeum; + DEPOT *scdb; + ODDOC *doc; + CBMAP *scores; + const char *file; + char path[PATHBUFSIZ], *mbuf; + int err, fatal, id, msiz; + printfinfo("%s: relating started", name); + if(!(odeum = odopen(name, OD_OWRITER))){ + pdperror(name); + return 1; + } + sprintf(path, "%s%c%s", name, PATHCHR, SCDBNAME); + if(!(scdb = dpopen(path, OD_OWRITER | OD_OCREAT, SCDBBNUM))){ + pdperror(name); + odclose(odeum); + return 1; + } + if(!dpsetalign(scdb, SCDBALIGN)){ + pdperror(name); + dpclose(scdb); + odclose(odeum); + return 1; + } + printfinfo("%s: database opened: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + err = FALSE; + if(!oditerinit(odeum)){ + pdperror(name); + err = TRUE; + } else { + while(TRUE){ + if(sigterm){ + printferror("aborting due to a termination signal"); + err = TRUE; + break; + } + if(!(doc = oditernext(odeum))){ + if(dpecode != DP_ENOITEM){ + pdperror(name); + err = TRUE; + } + break; + } + file = oddocuri(doc); + id = oddocid(doc); + scores = oddocscores(doc, KEYNUM, odeum); + mbuf = cbmapdump(scores, &msiz); + if(!dpput(scdb, (char *)&id, sizeof(int), mbuf, msiz, DP_DOVER)){ + pdperror(name); + err = TRUE; + } else { + printfinfo("%s: related", file); + } + free(mbuf); + cbmapclose(scores); + oddocclose(doc); + if(err) break; + } + } + fatal = odfatalerror(odeum); + printfinfo("%s: database closing: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + if(!dpclose(scdb)){ + pdperror(name); + err = TRUE; + } + if(!odclose(odeum)){ + pdperror(name); + err = TRUE; + } + if(err){ + printfinfo("%s: relating was over%s", name, fatal ? " with fatal error" : ""); + } else { + printfinfo("%s: relating completed successfully", name); + } + return err ? 1 : 0; +} + + +/* purge documents which is not existing. */ +int procpurge(const char *name){ + ODEUM *odeum; + ODDOC *doc; + const char *file; + int err, fatal; + printfinfo("%s: purging started", name); + if(!(odeum = odopen(name, OD_OWRITER))){ + pdperror(name); + return 1; + } + printfinfo("%s: database opened: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + err = FALSE; + if(!oditerinit(odeum)){ + pdperror(name); + err = TRUE; + } else { + while(TRUE){ + if(sigterm){ + printferror("aborting due to a termination signal"); + err = TRUE; + break; + } + if(!(doc = oditernext(odeum))){ + if(dpecode != DP_ENOITEM){ + pdperror(name); + err = TRUE; + } + break; + } + file = oddocuri(doc); + if(cbfilestat(file, NULL, NULL, NULL)){ + printfinfo("%s: passed", file); + } else { + if(!odout(odeum, file)){ + pdperror(file); + err = TRUE; + } + printfinfo("%s: purged", file); + } + oddocclose(doc); + } + } + fatal = odfatalerror(odeum); + printfinfo("%s: database closing: fsiz=%.0f dnum=%d wnum=%d bnum=%d", + name, odfsiz(odeum), oddnum(odeum), odwnum(odeum), odbnum(odeum)); + if(!odclose(odeum)){ + pdperror(name); + err = TRUE; + } + if(err){ + printfinfo("%s: purging was over%s", name, fatal ? " with fatal error" : ""); + } else { + printfinfo("%s: purging completed successfully", name); + } + return err ? 1 : 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/odmgr.c b/qdbm/odmgr.c new file mode 100644 index 00000000..7b688280 --- /dev/null +++ b/qdbm/odmgr.c @@ -0,0 +1,1085 @@ +/************************************************************************************************* + * Utility for debugging Odeum and its applications + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define MAXSRCHWORDS 256 /* max number of search words */ +#define WOCCRPOINT 10000 /* points per occurence */ +#define MAXKEYWORDS 8 /* max number of keywords */ +#define SUMMARYWIDTH 16 /* width of each phrase in a summary */ +#define MAXSUMMARY 128 /* max number of words in a summary */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +char *readstdin(int *sp); +void otcb(const char *fname, ODEUM *odeum, const char *msg); +int runcreate(int argc, char **argv); +int runput(int argc, char **argv); +int runout(int argc, char **argv); +int runget(int argc, char **argv); +int runsearch(int argc, char **argv); +int runlist(int argc, char **argv); +int runoptimize(int argc, char **argv); +int runinform(int argc, char **argv); +int runmerge(int argc, char **argv); +int runremove(int argc, char **argv); +int runbreak(int argc, char **argv); +void pdperror(const char *name); +void printdoc(const ODDOC *doc, int tb, int hb, int score, ODEUM *odeum, const CBLIST *skeys); +char *docsummary(const ODDOC *doc, const CBLIST *kwords, int num, int hilight); +CBMAP *listtomap(const CBLIST *list); +int docreate(const char *name); +int doput(const char *name, const char *text, const char *uri, const char *title, + const char *author, const char *date, int wmax, int keep); +int doout(const char *name, const char *uri, int id); +int doget(const char *name, const char *uri, int id, int tb, int hb); +int dosearch(const char *name, const char *text, int max, int or, int idf, int ql, + int tb, int hb, int nb); +int dolist(const char *name, int tb, int hb); +int dooptimize(const char *name); +int doinform(const char *name); +int domerge(const char *name, const CBLIST *elems); +int doremove(const char *name); +int dobreak(const char *text, int hb, int kb, int sb); + + +/* main routine */ +int main(int argc, char **argv){ + char *env; + int rv; + cbstdiobin(); + progname = argv[0]; + if((env = getenv("QDBMDBGFD")) != NULL) dpdbgfd = atoi(env); + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "create")){ + odsetotcb(otcb); + rv = runcreate(argc, argv); + } else if(!strcmp(argv[1], "put")){ + odsetotcb(otcb); + rv = runput(argc, argv); + } else if(!strcmp(argv[1], "out")){ + odsetotcb(otcb); + rv = runout(argc, argv); + } else if(!strcmp(argv[1], "get")){ + rv = runget(argc, argv); + } else if(!strcmp(argv[1], "search")){ + rv = runsearch(argc, argv); + } else if(!strcmp(argv[1], "list")){ + rv = runlist(argc, argv); + } else if(!strcmp(argv[1], "optimize")){ + odsetotcb(otcb); + rv = runoptimize(argc, argv); + } else if(!strcmp(argv[1], "inform")){ + rv = runinform(argc, argv); + } else if(!strcmp(argv[1], "merge")){ + odsetotcb(otcb); + rv = runmerge(argc, argv); + } else if(!strcmp(argv[1], "remove")){ + rv = runremove(argc, argv); + } else if(!strcmp(argv[1], "break")){ + rv = runbreak(argc, argv); + } else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){ + printf("Powered by QDBM version %s\n", dpversion); + printf("Copyright (c) 2000-2007 Mikio Hirabayashi\n"); + rv = 0; + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: administration utility for Odeum\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s create name\n", progname); + fprintf(stderr, " %s put [-uri str] [-title str] [-author str] [-date str]" + " [-wmax num] [-keep] name [file]\n", progname); + fprintf(stderr, " %s out [-id] name expr\n", progname); + fprintf(stderr, " %s get [-id] [-t|-h] name expr\n", progname); + fprintf(stderr, " %s search [-max num] [-or] [-idf] [-t|-h|-n] name words...\n", progname); + fprintf(stderr, " %s list [-t|-h] name\n", progname); + fprintf(stderr, " %s optimize name\n", progname); + fprintf(stderr, " %s inform name\n", progname); + fprintf(stderr, " %s merge name elems...\n", progname); + fprintf(stderr, " %s remove name\n", progname); + fprintf(stderr, " %s break [-h|-k|-s] [file]\n", progname); + fprintf(stderr, " %s version\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* read the standard input */ +char *readstdin(int *sp){ + char *buf; + int i, blen, c; + blen = 256; + buf = cbmalloc(blen); + for(i = 0; (c = getchar()) != EOF; i++){ + if(i >= blen - 1) buf = cbrealloc(buf, blen *= 2); + buf[i] = c; + } + buf[i] = '\0'; + *sp = i; + return buf; +} + + +/* report the outturn */ +void otcb(const char *fname, ODEUM *odeum, const char *msg){ + char *name; + name = odname(odeum); + printf("%s: %s: %s: %s\n", progname, fname, name, msg); + free(name); +} + + +/* parse arguments of create command */ +int runcreate(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = docreate(name); + return rv; +} + + +/* parse arguments of put command */ +int runput(int argc, char **argv){ + char *name, *file, *uri, *title, *author, *date, *text; + int i, wmax, keep, size, rv; + name = NULL; + file = NULL; + uri = NULL; + title = NULL; + author = NULL; + date = NULL; + wmax = -1; + keep = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-uri")){ + if(++i >= argc) usage(); + uri = argv[i]; + } else if(!strcmp(argv[i], "-uri")){ + if(++i >= argc) usage(); + uri = argv[i]; + } else if(!strcmp(argv[i], "-title")){ + if(++i >= argc) usage(); + title = argv[i]; + } else if(!strcmp(argv[i], "-author")){ + if(++i >= argc) usage(); + author = argv[i]; + } else if(!strcmp(argv[i], "-date")){ + if(++i >= argc) usage(); + date = argv[i]; + } else if(!strcmp(argv[i], "-wmax")){ + if(++i >= argc) usage(); + wmax = atoi(argv[i]); + } else if(!strcmp(argv[i], "-keep")){ + keep = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + if(!uri) uri = file; + if(!uri) usage(); + if(file){ + if(!(text = cbreadfile(file, &size))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + text = readstdin(&size); + } + rv = doput(name, text, uri, title, author, date, wmax, keep); + free(text); + return rv; +} + + +/* parse arguments of out command */ +int runout(int argc, char **argv){ + char *name, *expr; + int i, ib, id, rv; + name = NULL; + expr = NULL; + ib = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-id")){ + ib = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!expr){ + expr = argv[i]; + } else { + usage(); + } + } + if(!name || !expr) usage(); + id = -1; + if(ib){ + id = atoi(expr); + if(id < 1) usage(); + } + rv = doout(name, expr, id); + return rv; +} + + +/* parse arguments of get command */ +int runget(int argc, char **argv){ + char *name, *expr; + int i, ib, tb, hb, id, rv; + name = NULL; + expr = NULL; + ib = FALSE; + tb = FALSE; + hb = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-id")){ + ib = TRUE; + } else if(!strcmp(argv[i], "-t")){ + tb = TRUE; + } else if(!strcmp(argv[i], "-h")){ + hb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!expr){ + expr = argv[i]; + } else { + usage(); + } + } + if(!name || !expr) usage(); + id = -1; + if(ib){ + id = atoi(expr); + if(id < 1) usage(); + } + rv = doget(name, expr, id, tb, hb); + return rv; +} + + +/* parse arguments of search command */ +int runsearch(int argc, char **argv){ + char *name, *srchwords[MAXSRCHWORDS]; + int i, wnum, max, or, idf, ql, tb, hb, nb, rv; + CBDATUM *text; + name = NULL; + wnum = 0; + max = -1; + or = FALSE; + idf = FALSE; + ql = FALSE; + tb = FALSE; + hb = FALSE; + nb = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-max")){ + if(++i >= argc) usage(); + max = atoi(argv[i]); + } else if(!strcmp(argv[i], "-or")){ + or = TRUE; + } else if(!strcmp(argv[i], "-idf")){ + idf = TRUE; + } else if(!strcmp(argv[i], "-ql")){ + ql = TRUE; + } else if(!strcmp(argv[i], "-t")){ + tb = TRUE; + } else if(!strcmp(argv[i], "-h")){ + hb = TRUE; + } else if(!strcmp(argv[i], "-n")){ + nb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(wnum < MAXSRCHWORDS){ + srchwords[wnum++] = argv[i]; + } + } + if(!name) usage(); + text = cbdatumopen(NULL, -1); + for(i = 0; i < wnum; i++){ + if(i > 0) cbdatumcat(text, " ", 1); + cbdatumcat(text, srchwords[i], -1); + } + rv = dosearch(name, cbdatumptr(text), max, or, idf, ql, tb, hb, nb); + cbdatumclose(text); + return rv; +} + + +/* parse arguments of list command */ +int runlist(int argc, char **argv){ + char *name; + int i, tb, hb, rv; + name = NULL; + tb = FALSE; + hb = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-t")){ + tb = TRUE; + } else if(!strcmp(argv[i], "-h")){ + hb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dolist(name, tb, hb); + return rv; +} + + +/* parse arguments of optimize command */ +int runoptimize(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dooptimize(name); + return rv; +} + + +/* parse arguments of inform command */ +int runinform(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doinform(name); + return rv; +} + + +/* parse arguments of merge command */ +int runmerge(int argc, char **argv){ + char *name; + CBLIST *elems; + int i, rv; + name = NULL; + elems = cblistopen(); + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + cblistpush(elems, argv[i], -1); + } + } + if(!name) usage(); + if(cblistnum(elems) < 1){ + cblistclose(elems); + usage(); + } + rv = domerge(name, elems); + cblistclose(elems); + return rv; +} + + +/* parse arguments of remove command */ +int runremove(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doremove(name); + return rv; +} + + +/* parse arguments of break command */ +int runbreak(int argc, char **argv){ + char *file, *text; + int i, hb, kb, sb, size, rv; + file = NULL; + hb = FALSE; + kb = FALSE; + sb = FALSE; + for(i = 2; i < argc; i++){ + if(!file && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-h")){ + hb = TRUE; + } else if(!strcmp(argv[i], "-k")){ + kb = TRUE; + } else if(!strcmp(argv[i], "-s")){ + sb = TRUE; + } else { + usage(); + } + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + if(file){ + if(!(text = cbreadfile(file, &size))){ + fprintf(stderr, "%s: %s: cannot open\n", progname, file); + return 1; + } + } else { + text = readstdin(&size); + } + rv = dobreak(text, hb, kb, sb); + free(text); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* print the contents of a document */ +void printdoc(const ODDOC *doc, int tb, int hb, int score, ODEUM *odeum, const CBLIST *skeys){ + const CBLIST *words; + CBMAP *scores; + CBLIST *kwords; + const char *title, *author, *word, *date; + char *summary; + int i, wsiz; + title = oddocgetattr(doc, "title"); + author = oddocgetattr(doc, "author"); + date = oddocgetattr(doc, "date"); + if(hb){ + printf("ID: %d\n", oddocid(doc)); + printf("URI: %s\n", oddocuri(doc)); + if(title) printf("TITLE: %s\n", title); + if(author) printf("AUTHOR: %s\n", author); + if(date) printf("DATE: %s\n", date); + if(score >= 0) printf("SCORE: %d\n", score); + scores = oddocscores(doc, MAXKEYWORDS, odeum); + kwords = cblistopen(); + printf("KEYWORDS: "); + cbmapiterinit(scores); + while((word = cbmapiternext(scores, &wsiz)) != NULL){ + if(cblistnum(kwords) > 0) printf(", "); + printf("%s (%s)", word, cbmapget(scores, word, wsiz, NULL)); + cblistpush(kwords, word, wsiz); + } + putchar('\n'); + summary = docsummary(doc, skeys ? skeys : kwords, MAXSUMMARY, skeys != NULL); + printf("SUMMARY: %s\n", summary); + free(summary); + cblistclose(kwords); + cbmapclose(scores); + printf("\n\n"); + } else if(tb){ + printf("%d\t%s\t%s\t%s\t%s\t%d\n", oddocid(doc), oddocuri(doc), + title ? title : "", author ? author : "", date ? date : "", score); + words = oddocnwords(doc); + for(i = 0; i < cblistnum(words); i++){ + word = cblistval(words, i, &wsiz); + if(i > 0) putchar('\t'); + printf("%s", word); + } + putchar('\n'); + words = oddocawords(doc); + for(i = 0; i < cblistnum(words); i++){ + word = cblistval(words, i, &wsiz); + if(i > 0) putchar('\t'); + printf("%s", word); + } + putchar('\n'); + } else { + printf("%d\t%s\t%d\n", oddocid(doc), oddocuri(doc), score); + } +} + + +/* get a list handle contains summary of a document */ +char *docsummary(const ODDOC *doc, const CBLIST *kwords, int num, int hilight){ + const CBLIST *nwords, *awords; + CBMAP *kmap, *map; + const char *normal, *asis; + char *sbuf; + int i, j, bsiz, ssiz, lnum, nwsiz, awsiz, pv, bi, first; + bsiz = 256; + sbuf = cbmalloc(bsiz); + ssiz = 0; + nwords = oddocnwords(doc); + awords = oddocawords(doc); + kmap = listtomap(kwords); + map = listtomap(kwords); + lnum = cblistnum(nwords); + first = TRUE; + for(i = 0; i < lnum && i < SUMMARYWIDTH; i++){ + normal = cblistval(nwords, i, &nwsiz); + asis = cblistval(awords, i, &awsiz); + if(awsiz < 1) continue; + cbmapout(map, normal, nwsiz); + if(ssiz + awsiz + 16 >= bsiz){ + bsiz = bsiz * 2 + awsiz; + sbuf = cbrealloc(sbuf, bsiz); + } + if(!first) ssiz += sprintf(sbuf + ssiz, " "); + if(hilight && normal[0] != '\0' && cbmapget(kmap, normal, nwsiz, NULL)){ + ssiz += sprintf(sbuf + ssiz, "<<%s>>", asis); + } else { + ssiz += sprintf(sbuf + ssiz, "%s", asis); + } + first = FALSE; + num--; + } + ssiz += sprintf(sbuf + ssiz, " ..."); + pv = i; + while(i < lnum){ + if(cbmaprnum(map) < 1){ + cbmapclose(map); + map = listtomap(kwords); + } + normal = cblistval(nwords, i, &nwsiz); + if(cbmapget(map, normal, nwsiz, NULL)){ + bi = i - SUMMARYWIDTH / 2; + bi = bi > pv ? bi : pv; + for(j = bi; j < lnum && j <= bi + SUMMARYWIDTH; j++){ + normal = cblistval(nwords, j, &nwsiz); + asis = cblistval(awords, j, &awsiz); + if(awsiz < 1) continue; + cbmapout(map, normal, nwsiz); + if(ssiz + awsiz + 16 >= bsiz){ + bsiz = bsiz * 2 + awsiz; + sbuf = cbrealloc(sbuf, bsiz); + } + ssiz += sprintf(sbuf + ssiz, " "); + if(hilight && normal[0] != '\0' && cbmapget(kmap, normal, nwsiz, NULL)){ + ssiz += sprintf(sbuf + ssiz, "<<%s>>", asis); + } else { + ssiz += sprintf(sbuf + ssiz, "%s", asis); + } + num--; + } + ssiz += sprintf(sbuf + ssiz, " ..."); + i = j; + pv = i; + } else { + i++; + } + if(num <= 0) break; + } + cbmapclose(map); + cbmapclose(kmap); + return sbuf; +} + + +/* get a map made from a list */ +CBMAP *listtomap(const CBLIST *list){ + CBMAP *map; + const char *tmp; + int i, tsiz; + map = cbmapopen(); + for(i = 0; i < cblistnum(list); i++){ + tmp = cblistval(list, i, &tsiz); + cbmapput(map, tmp, tsiz, "", 0, FALSE); + } + return map; +} + + +/* perform create command */ +int docreate(const char *name){ + ODEUM *odeum; + if(!(odeum = odopen(name, OD_OWRITER | OD_OCREAT | OD_OTRUNC))){ + pdperror(name); + return 1; + } + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform put command */ +int doput(const char *name, const char *text, const char *uri, const char *title, + const char *author, const char *date, int wmax, int keep){ + ODEUM *odeum; + ODDOC *doc; + CBLIST *awords; + const char *asis; + char *normal; + int i; + if(!(odeum = odopen(name, OD_OWRITER))){ + pdperror(name); + return 1; + } + doc = oddocopen(uri); + if(title) oddocaddattr(doc, "title", title); + if(author) oddocaddattr(doc, "author", author); + if(date) oddocaddattr(doc, "date", date); + awords = odbreaktext(text); + for(i = 0; i < cblistnum(awords); i++){ + asis = cblistval(awords, i, NULL); + normal = odnormalizeword(asis); + oddocaddword(doc, normal, asis); + free(normal); + } + cblistclose(awords); + if(!odput(odeum, doc, wmax, keep ? FALSE : TRUE)){ + pdperror(name); + oddocclose(doc); + odclose(odeum); + return 1; + } + oddocclose(doc); + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform out command */ +int doout(const char *name, const char *uri, int id){ + ODEUM *odeum; + if(!(odeum = odopen(name, OD_OWRITER))){ + pdperror(name); + return 1; + } + if(id > 0){ + if(!odoutbyid(odeum, id)){ + pdperror(name); + odclose(odeum); + return 1; + } + } else { + if(!odout(odeum, uri)){ + pdperror(name); + odclose(odeum); + return 1; + } + } + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform get command */ +int doget(const char *name, const char *uri, int id, int tb, int hb){ + ODEUM *odeum; + ODDOC *doc; + if(!(odeum = odopen(name, OD_OREADER))){ + pdperror(name); + return 1; + } + if(id > 0){ + if(!(doc = odgetbyid(odeum, id))){ + pdperror(name); + odclose(odeum); + return 1; + } + } else { + if(!(doc = odget(odeum, uri))){ + pdperror(name); + odclose(odeum); + return 1; + } + } + printdoc(doc, tb, hb, -1, odeum, NULL); + oddocclose(doc); + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform search command */ +int dosearch(const char *name, const char *text, int max, int or, int idf, int ql, + int tb, int hb, int nb){ + ODEUM *odeum; + CBLIST *awords, *nwords, *uris, *hits; + ODPAIR *pairs, *last, *tmp; + ODDOC *doc; + const char *asis; + char *normal, numbuf[32]; + int i, j, pnum, lnum, hnum, tnum, shows; + double ival; + if(!(odeum = odopen(name, OD_OREADER))){ + pdperror(name); + return 1; + } + awords = odbreaktext(text); + nwords = cblistopen(); + uris = cblistopen(); + hits = cblistopen(); + last = NULL; + lnum = 0; + if(ql){ + last= odquery(odeum, text, &lnum, NULL); + } else { + for(i = 0; i < cblistnum(awords); i++){ + asis = cblistval(awords, i, NULL); + normal = odnormalizeword(asis); + cblistpush(nwords, normal, -1); + if(strlen(normal) < 1){ + free(normal); + continue; + } + if(!(pairs = odsearch(odeum, normal, or ? max : -1, &pnum))){ + pdperror(name); + free(normal); + continue; + } + if((hnum = odsearchdnum(odeum, normal)) < 0) hnum = 0; + if(idf){ + ival = odlogarithm(hnum); + ival = (ival * ival) / 4.0; + if(ival < 4.0) ival = 4.0; + for(j = 0; j < pnum; j++){ + pairs[j].score = (int)(pairs[j].score / ival); + } + } + cblistpush(uris, normal, -1); + sprintf(numbuf, "%d", hnum); + cblistpush(hits, numbuf, -1); + if(last){ + if(or){ + tmp = odpairsor(last, lnum, pairs, pnum, &tnum); + } else { + tmp = odpairsand(last, lnum, pairs, pnum, &tnum); + } + free(last); + free(pairs); + last = tmp; + lnum = tnum; + } else { + last = pairs; + lnum = pnum; + } + free(normal); + } + } + if(hb){ + printf("TOTAL: %d\n", lnum); + printf("EACHWORD: "); + } else { + printf("%d", lnum); + } + for(i = 0; i < cblistnum(uris); i++){ + if(hb){ + if(i > 0) printf(", "); + printf("%s(%s)", cblistval(uris, i, NULL), cblistval(hits, i, NULL)); + } else { + printf("\t%s\t%s", cblistval(uris, i, NULL), cblistval(hits, i, NULL)); + } + } + putchar('\n'); + if(hb) putchar('\n'); + if(last){ + if(max < 0) max = lnum; + shows = 0; + for(i = 0; i < lnum && shows < max; i++){ + if(nb){ + printf("%d\t%d\n", last[i].id, last[i].score); + shows++; + } else { + if(!(doc = odgetbyid(odeum, last[i].id))) continue; + printdoc(doc, tb, hb, last[i].score, odeum, nwords); + oddocclose(doc); + shows++; + } + } + free(last); + } + cblistclose(uris); + cblistclose(hits); + cblistclose(nwords); + cblistclose(awords); + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform list command */ +int dolist(const char *name, int tb, int hb){ + ODEUM *odeum; + ODDOC *doc; + if(!(odeum = odopen(name, OD_OREADER))){ + pdperror(name); + return 1; + } + if(!oditerinit(odeum)){ + odclose(odeum); + pdperror(name); + return 1; + } + while(TRUE){ + if(!(doc = oditernext(odeum))){ + if(dpecode == DP_ENOITEM) break; + odclose(odeum); + pdperror(name); + return 1; + } + printdoc(doc, tb, hb, -1, odeum, NULL); + oddocclose(doc); + } + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform optimize command */ +int dooptimize(const char *name){ + ODEUM *odeum; + if(!(odeum = odopen(name, OD_OWRITER))){ + pdperror(name); + return 1; + } + if(!odoptimize(odeum)){ + pdperror(name); + odclose(odeum); + return 1; + } + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform inform command */ +int doinform(const char *name){ + ODEUM *odeum; + char *tmp; + if(!(odeum = odopen(name, OD_OREADER))){ + pdperror(name); + return 1; + } + tmp = odname(odeum); + printf("name: %s\n", tmp ? tmp : "(null)"); + free(tmp); + printf("file size: %.0f\n", odfsiz(odeum)); + printf("index buckets: %d\n", odbnum(odeum)); + printf("used buckets: %d\n", odbusenum(odeum)); + printf("all documents: %d\n", oddnum(odeum)); + printf("all words: %d\n", odwnum(odeum)); + printf("inode number: %d\n", odinode(odeum)); + printf("modified time: %.0f\n", (double)odmtime(odeum)); + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform merge command */ +int domerge(const char *name, const CBLIST *elems){ + if(!odmerge(name, elems)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform remove command */ +int doremove(const char *name){ + if(!odremove(name)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform break command */ +int dobreak(const char *text, int hb, int kb, int sb){ + CBLIST *awords, *kwords; + CBMAP *scores; + ODDOC *doc; + const char *asis; + char *normal, *summary; + int i, first; + awords = odbreaktext(text); + if(kb || sb){ + doc = oddocopen(""); + for(i = 0; i < cblistnum(awords); i++){ + asis = cblistval(awords, i, NULL); + normal = odnormalizeword(asis); + oddocaddword(doc, normal, asis); + free(normal); + } + scores = oddocscores(doc, MAXKEYWORDS, NULL); + cbmapiterinit(scores); + kwords = cbmapkeys(scores); + if(kb){ + for(i = 0; i < cblistnum(kwords); i++){ + if(i > 0) putchar('\t'); + printf("%s", cblistval(kwords, i, NULL)); + } + putchar('\n'); + } else { + summary = docsummary(doc, kwords, MAXSUMMARY, FALSE); + printf("%s\n", summary); + free(summary); + } + cblistclose(kwords); + cbmapclose(scores); + oddocclose(doc); + } else if(hb){ + printf("NWORDS: "); + first = TRUE; + for(i = 0; i < cblistnum(awords); i++){ + asis = cblistval(awords, i, NULL); + normal = odnormalizeword(asis); + if(normal[0] == '\0'){ + free(normal); + continue; + } + if(!first) putchar(' '); + first = FALSE; + printf("%s", normal); + free(normal); + } + putchar('\n'); + printf("AWORDS: "); + first = TRUE; + for(i = 0; i < cblistnum(awords); i++){ + asis = cblistval(awords, i, NULL); + if(asis[0] == '\0') continue; + if(!first) putchar(' '); + first = FALSE; + printf("%s", asis); + } + putchar('\n'); + } else { + for(i = 0; i < cblistnum(awords); i++){ + asis = cblistval(awords, i, NULL); + normal = odnormalizeword(asis); + printf("%s\t%s\n", normal, asis); + free(normal); + } + } + cblistclose(awords); + return 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/odtest.c b/qdbm/odtest.c new file mode 100644 index 00000000..41f9ac12 --- /dev/null +++ b/qdbm/odtest.c @@ -0,0 +1,694 @@ +/************************************************************************************************* + * Test cases of Odeum + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define DOCBUFSIZ 256 /* buffer for documents */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +int runwrite(int argc, char **argv); +int runread(int argc, char **argv); +int runcombo(int argc, char **argv); +int runwicked(int argc, char **argv); +int printfflush(const char *format, ...); +void pdperror(const char *name); +int myrand(void); +ODDOC *makedoc(int id, int wnum, int pnum); +int dowrite(const char *name, int dnum, int wnum, int pnum, + int ibnum, int idnum, int cbnum, int csiz); +int doread(const char *name); +int docombo(const char *name); +int dowicked(const char *name, int dnum); + + +/* main routine */ +int main(int argc, char **argv){ + char *env; + int rv; + cbstdiobin(); + if((env = getenv("QDBMDBGFD")) != NULL) dpdbgfd = atoi(env); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "write")){ + rv = runwrite(argc, argv); + } else if(!strcmp(argv[1], "read")){ + rv = runread(argc, argv); + } else if(!strcmp(argv[1], "combo")){ + rv = runcombo(argc, argv); + } else if(!strcmp(argv[1], "wicked")){ + rv = runwicked(argc, argv); + } else { + usage(); + } + return 0; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: test cases for Odeum\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s write [-tune ibnum idnum cbnum csiz] name dnum wnum pnum\n", progname); + fprintf(stderr, " %s read name\n", progname); + fprintf(stderr, " %s combo name\n", progname); + fprintf(stderr, " %s wicked name dnum\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of write command */ +int runwrite(int argc, char **argv){ + char *name, *dstr, *wstr, *pstr; + int i, dnum, wnum, pnum, ibnum, idnum, cbnum, csiz, rv; + name = NULL; + dstr = NULL; + wstr = NULL; + pstr = NULL; + dnum = 0; + wnum = 0; + pnum = 0; + ibnum = -1; + idnum = -1; + cbnum = -1; + csiz = -1; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-tune")){ + if(++i >= argc) usage(); + ibnum = atoi(argv[i]); + if(++i >= argc) usage(); + idnum = atoi(argv[i]); + if(++i >= argc) usage(); + cbnum = atoi(argv[i]); + if(++i >= argc) usage(); + csiz = atoi(argv[i]); + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!dstr){ + dstr = argv[i]; + } else if(!wstr){ + wstr = argv[i]; + } else if(!pstr){ + pstr = argv[i]; + } else { + usage(); + } + } + if(!name || !dstr || !wstr || !pstr) usage(); + dnum = atoi(dstr); + wnum = atoi(wstr); + pnum = atoi(pstr); + if(dnum < 1 || wnum < 1 || pnum < 1) usage(); + rv = dowrite(name, dnum, wnum, pnum, ibnum, idnum, cbnum, csiz); + return rv; +} + + +/* parse arguments of read command */ +int runread(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doread(name); + return rv; +} + + +/* parse arguments of combo command */ +int runcombo(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = docombo(name); + return rv; +} + + +/* parse arguments of wicked command */ +int runwicked(int argc, char **argv){ + char *name, *dstr; + int i, dnum, rv; + name = NULL; + dstr = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else if(!dstr){ + dstr = argv[i]; + } else { + usage(); + } + } + if(!name || !dstr) usage(); + dnum = atoi(dstr); + if(dnum < 1) usage(); + rv = dowicked(name, dnum); + return rv; +} + + +/* print formatted string and flush the buffer */ +int printfflush(const char *format, ...){ + va_list ap; + int rv; + va_start(ap, format); + rv = vprintf(format, ap); + if(fflush(stdout) == EOF) rv = -1; + va_end(ap); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* pseudo random number generator */ +int myrand(void){ + static int cnt = 0; + if(cnt == 0) srand(time(NULL)); + return (rand() * rand() + (rand() >> (sizeof(int) * 4)) + (cnt++)) & INT_MAX; +} + + +/* create a document */ +ODDOC *makedoc(int id, int wnum, int pnum){ + ODDOC *doc; + char buf[DOCBUFSIZ]; + int i; + sprintf(buf, "%08d", id); + doc = oddocopen(buf); + oddocaddattr(doc, "title", buf); + oddocaddattr(doc, "author", buf); + oddocaddattr(doc, "date", buf); + for(i = 0; i < wnum; i++){ + sprintf(buf, "%08d", myrand() % pnum); + oddocaddword(doc, buf, buf); + } + return doc; +} + + +/* perform write command */ +int dowrite(const char *name, int dnum, int wnum, int pnum, + int ibnum, int idnum, int cbnum, int csiz){ + ODEUM *odeum; + ODDOC *doc; + int i, err; + printfflush("\n name=%s dnum=%d wnum=%d pnum=%d" + " ibnum=%d idnum=%d cbnum=%d csiz=%d\n\n", + name, dnum, wnum, pnum, ibnum, idnum, cbnum, csiz); + /* open a database */ + if(ibnum > 0) odsettuning(ibnum, idnum, cbnum, csiz); + if(!(odeum = odopen(name, OD_OWRITER | OD_OCREAT | OD_OTRUNC))){ + pdperror(name); + return 1; + } + err = FALSE; + /* loop for each document */ + for(i = 1; i <= dnum; i++){ + /* store a document */ + doc = makedoc(i, wnum, pnum); + if(!odput(odeum, doc, -1, FALSE)){ + pdperror(name); + oddocclose(doc); + err = TRUE; + break; + } + oddocclose(doc); + /* print progression */ + if(dnum > 250 && i % (dnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == dnum || i % (dnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform read command */ +int doread(const char *name){ + ODEUM *odeum; + ODDOC *doc; + char buf[DOCBUFSIZ]; + int i, dnum, err; + printfflush("\n name=%s\n\n", name); + /* open a database */ + if(!(odeum = odopen(name, OD_OREADER))){ + pdperror(name); + return 1; + } + /* get the number of documents */ + dnum = oddnum(odeum); + err = FALSE; + /* loop for each document */ + for(i = 1; i <= dnum; i++){ + /* retrieve a document */ + sprintf(buf, "%08d", i); + if(!(doc = odget(odeum, buf))){ + pdperror(name); + err = TRUE; + break; + } + oddocclose(doc); + /* print progression */ + if(dnum > 250 && i % (dnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == dnum || i % (dnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform combo command */ +int docombo(const char *name){ + ODEUM *odeum; + ODDOC *doc; + const CBLIST *nwords, *awords; + CBLIST *tawords, *tnwords, *oawords; + ODPAIR *pairs; + const char *asis; + char buf[DOCBUFSIZ], *normal; + int i, j, pnum; + printfflush("\n name=%s\n\n", name); + printfflush("Creating a database with ... "); + if(!(odeum = odopen(name, OD_OWRITER | OD_OCREAT | OD_OTRUNC))){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 20 documents including about 200 words ... "); + for(i = 1; i <= 20; i++){ + sprintf(buf, "%08d", i); + doc = makedoc(i, 120 + myrand() % 160, myrand() % 500 + 500); + if(!odput(odeum, doc, 180 + myrand() % 40, FALSE)){ + pdperror(name); + oddocclose(doc); + odclose(odeum); + return 1; + } + oddocclose(doc); + } + printfflush("ok\n"); + printfflush("Checking documents ... "); + for(i = 1; i <= 20; i++){ + sprintf(buf, "%08d", i); + if(!(doc = odget(odeum, buf))){ + pdperror(name); + return 1; + } + nwords = oddocnwords(doc); + awords = oddocawords(doc); + if(!oddocuri(doc) || !oddocgetattr(doc, "title") || cblistnum(nwords) != cblistnum(awords)){ + fprintf(stderr, "%s: %s: invalid document\n", progname, name); + oddocclose(doc); + odclose(odeum); + return 1; + } + for(j = 0; j < cblistnum(nwords); j++){ + if(strcmp(cblistval(nwords, j, NULL), cblistval(nwords, j, NULL))){ + fprintf(stderr, "%s: %s: invalid words\n", progname, name); + oddocclose(doc); + odclose(odeum); + return 1; + } + } + oddocclose(doc); + } + printfflush("ok\n"); + printfflush("Syncing the database ... "); + if(!odsync(odeum)){ + pdperror(name); + odclose(odeum); + return 1; + } + printfflush("ok\n"); + printfflush("Overwriting 1 - 10 documents ... "); + for(i = 1; i <= 10; i++){ + sprintf(buf, "%08d", i); + doc = makedoc(i, 120 + myrand() % 160, myrand() % 500 + 500); + if(!odput(odeum, doc, 180 + myrand() % 40, TRUE)){ + pdperror(name); + oddocclose(doc); + odclose(odeum); + return 1; + } + oddocclose(doc); + } + printfflush("ok\n"); + printfflush("Deleting 11 - 20 documents ... "); + for(i = 11; i <= 20; i++){ + sprintf(buf, "%08d", i); + if(!odout(odeum, buf)){ + pdperror(name); + odclose(odeum); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking documents ... "); + for(i = 1; i <= 10; i++){ + sprintf(buf, "%08d", i); + if(!(doc = odget(odeum, buf))){ + pdperror(name); + return 1; + } + nwords = oddocnwords(doc); + awords = oddocawords(doc); + if(!oddocuri(doc) || !oddocgetattr(doc, "title") || cblistnum(nwords) != cblistnum(awords)){ + fprintf(stderr, "%s: %s: invalid document\n", progname, name); + oddocclose(doc); + odclose(odeum); + return 1; + } + for(j = 0; j < cblistnum(nwords); j++){ + if(strcmp(cblistval(nwords, j, NULL), cblistval(nwords, j, NULL))){ + fprintf(stderr, "%s: %s: invalid words\n", progname, name); + oddocclose(doc); + odclose(odeum); + return 1; + } + } + oddocclose(doc); + } + if(oddnum(odeum) != 10){ + fprintf(stderr, "%s: %s: invalid document number\n", progname, name); + odclose(odeum); + return 1; + } + printfflush("ok\n"); + printfflush("Optimizing the database ... "); + if(!odoptimize(odeum)){ + pdperror(name); + odclose(odeum); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 10 documents including about 200 words ... "); + for(i = 11; i <= 20; i++){ + sprintf(buf, "%08d", i); + doc = makedoc(i, 120 + myrand() % 160, myrand() % 500 + 500); + if(!odput(odeum, doc, 180 + myrand() % 40, FALSE)){ + pdperror(name); + oddocclose(doc); + odclose(odeum); + return 1; + } + oddocclose(doc); + } + printfflush("ok\n"); + printfflush("Deleting 6 - 15 documents ... "); + for(i = 6; i <= 15; i++){ + sprintf(buf, "%08d", i); + if(!odout(odeum, buf)){ + pdperror(name); + odclose(odeum); + return 1; + } + } + printfflush("ok\n"); + printfflush("Retrieving documents 100 times ... "); + for(i = 1; i <= 100; i++){ + sprintf(buf, "%08d", myrand() % 1000 + 1); + if((pairs = odsearch(odeum, buf, -1, &pnum)) != NULL){ + for(j = 0; j < pnum; j++){ + if((doc = odgetbyid(odeum, pairs[j].id)) != NULL){ + oddocclose(doc); + } else if(dpecode != DP_ENOITEM){ + pdperror(name); + odclose(odeum); + return 1; + } + } + free(pairs); + } else if(dpecode != DP_ENOITEM){ + pdperror(name); + odclose(odeum); + return 1; + } + } + printfflush("ok\n"); + printfflush("Analyzing text ... "); + tawords = cblistopen(); + tnwords = cblistopen(); + odanalyzetext(odeum, "I'd like to ++see++ Mr. X-men tomorrow.", tawords, tnwords); + odanalyzetext(odeum, "=== :-) SMILE . @ . SAD :-< ===", tawords, tnwords); + for(i = 0; i < DOCBUFSIZ - 1; i++){ + buf[i] = myrand() % 255 + 1; + } + buf[DOCBUFSIZ-1] = '\0'; + cblistclose(tnwords); + cblistclose(tawords); + for(i = 0; i < 1000; i++){ + for(j = 0; j < DOCBUFSIZ - 1; j++){ + if((j + 1) % 32 == 0){ + buf[j] = ' '; + } else { + buf[j] = myrand() % 255 + 1; + } + } + buf[DOCBUFSIZ-1] = '\0'; + tawords = cblistopen(); + tnwords = cblistopen(); + odanalyzetext(odeum, buf, tawords, tnwords); + oawords = odbreaktext(buf); + if(cblistnum(tawords) != cblistnum(oawords) || cblistnum(tnwords) != cblistnum(oawords)){ + fprintf(stderr, "%s: %s: invalid analyzing\n", progname, name); + cblistclose(oawords); + cblistclose(tnwords); + cblistclose(tawords); + odclose(odeum); + return 1; + } + for(j = 0; j < cblistnum(oawords); j++){ + asis = cblistval(oawords, j, NULL); + normal = odnormalizeword(asis); + if(strcmp(asis, cblistval(oawords, j, NULL)) || strcmp(normal, cblistval(tnwords, j, NULL))){ + fprintf(stderr, "%s: %s: invalid analyzing\n", progname, name); + free(normal); + cblistclose(oawords); + cblistclose(tnwords); + cblistclose(tawords); + odclose(odeum); + return 1; + } + free(normal); + } + cblistclose(oawords); + cblistclose(tnwords); + cblistclose(tawords); + } + printfflush("ok\n"); + printfflush("Closing the database ... "); + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("all ok\n\n"); + return 0; +} + + +/* perform wicked command */ +int dowicked(const char *name, int dnum){ + ODEUM *odeum; + ODDOC *doc; + ODPAIR *pairs; + char buf[DOCBUFSIZ]; + int i, j, pnum, err; + printfflush("\n name=%s dnum=%d\n\n", name, dnum); + err = FALSE; + if(!(odeum = odopen(name, OD_OWRITER | OD_OCREAT | OD_OTRUNC))){ + pdperror(name); + return 1; + } + for(i = 1; i <= dnum; i++){ + switch(myrand() % 8){ + case 1: + putchar('K'); + doc = makedoc(myrand() % dnum + 1, myrand() % 10 + 10, myrand() % dnum + 500); + if(!odput(odeum, doc, 5, FALSE) && dpecode != DP_EKEEP) err = TRUE; + oddocclose(doc); + break; + case 3: + putchar('D'); + if(!odoutbyid(odeum, myrand() % dnum + 1) && dpecode != DP_ENOITEM) err = TRUE; + break; + case 4: + putchar('R'); + sprintf(buf, "%08d", myrand() % (dnum + 500) + 1); + if((pairs = odsearch(odeum, buf, 5, &pnum)) != NULL){ + if(myrand() % 5 == 0){ + for(j = 0; j < pnum; j++){ + if((doc = odgetbyid(odeum, pairs[j].id)) != NULL){ + oddocclose(doc); + } else if(dpecode != DP_ENOITEM){ + err = TRUE; + break; + } + } + } + free(pairs); + } else if(dpecode != DP_ENOITEM){ + err = TRUE; + } + break; + default: + putchar('O'); + doc = makedoc(myrand() % dnum + 1, myrand() % 10 + 10, myrand() % dnum + 500); + if(!odput(odeum, doc, 5, TRUE)) err = TRUE; + oddocclose(doc); + break; + } + if(i % 50 == 0) printfflush(" (%08d)\n", i); + if(err){ + pdperror(name); + break; + } + } + if(!odoptimize(odeum)){ + pdperror(name); + err = TRUE; + } + for(i = 1; i <= dnum; i++){ + doc = makedoc(i, 5, 5); + if(!odput(odeum, doc, 5, FALSE) && dpecode != DP_EKEEP){ + pdperror(name); + oddocclose(doc); + err = TRUE; + break; + } + oddocclose(doc); + putchar(':'); + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + if(!odoptimize(odeum)){ + pdperror(name); + err = TRUE; + } + for(i = 1; i <= dnum; i++){ + sprintf(buf, "%08d", i); + if(!(doc = odget(odeum, buf))){ + pdperror(name); + err = TRUE; + break; + } + oddocclose(doc); + putchar('='); + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + if(!oditerinit(odeum)){ + pdperror(name); + err = TRUE; + } + for(i = 1; i <= dnum; i++){ + if(!(doc = oditernext(odeum))){ + pdperror(name); + err = TRUE; + break; + } + oddocclose(doc); + putchar('@'); + if(i % 50 == 0) printfflush(" (%08d)\n", i); + } + if(!odclose(odeum)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/qdbm.def b/qdbm/qdbm.def new file mode 100644 index 00000000..4c10e49e --- /dev/null +++ b/qdbm/qdbm.def @@ -0,0 +1,424 @@ +EXPORTS + VL_CMPDEC = VL_CMPDEC DATA + VL_CMPINT = VL_CMPINT DATA + VL_CMPLEX = VL_CMPLEX DATA + VL_CMPNUM = VL_CMPNUM DATA + VST_CMPDEC = VST_CMPDEC DATA + VST_CMPINT = VST_CMPINT DATA + VST_CMPLEX = VST_CMPLEX DATA + VST_CMPNUM = VST_CMPNUM DATA + cbfatalfunc = cbfatalfunc DATA + dpdbgfd = dpdbgfd DATA + dpisreentrant = dpisreentrant DATA + dpsysname = dpsysname DATA + dpversion = dpversion DATA + gdbm_version = gdbm_version DATA + odcachebnum = odcachebnum DATA + odcachesiz = odcachesiz DATA + odindexbnum = odindexbnum DATA + odindexdnum = odindexdnum DATA + odotcb = odotcb DATA + cbbasedecode = cbbasedecode + cbbaseencode = cbbaseencode + cbbzdecode = cbbzdecode + cbbzencode = cbbzencode + cbcalendar = cbcalendar + cbcsvcells = cbcsvcells + cbcsvescape = cbcsvescape + cbcsvrows = cbcsvrows + cbcsvunescape = cbcsvunescape + cbdatestrhttp = cbdatestrhttp + cbdatestrwww = cbdatestrwww + cbdatumcat = cbdatumcat + cbdatumclose = cbdatumclose + cbdatumdup = cbdatumdup + cbdatumopen = cbdatumopen + cbdatumopenbuf = cbdatumopenbuf + cbdatumprintf = cbdatumprintf + cbdatumptr = cbdatumptr + cbdatumsetbuf = cbdatumsetbuf + cbdatumsetsize = cbdatumsetsize + cbdatumsize = cbdatumsize + cbdatumtomalloc = cbdatumtomalloc + cbdayofweek = cbdayofweek + cbdeflate = cbdeflate + cbdirlist = cbdirlist + cbencname = cbencname + cbfilestat = cbfilestat + cbfree = cbfree + cbgetcrc = cbgetcrc + cbggcsweep = cbggcsweep + cbglobalgc = cbglobalgc + cbgzdecode = cbgzdecode + cbgzencode = cbgzencode + cbheapclose = cbheapclose + cbheapdup = cbheapdup + cbheapinsert = cbheapinsert + cbheapnum = cbheapnum + cbheapopen = cbheapopen + cbheaptomalloc = cbheaptomalloc + cbheapval = cbheapval + cbhsort = cbhsort + cbiconv = cbiconv + cbinflate = cbinflate + cbisort = cbisort + cbjetlag = cbjetlag + cblistbsearch = cblistbsearch + cblistclose = cblistclose + cblistdump = cblistdump + cblistdup = cblistdup + cblistinsert = cblistinsert + cblistload = cblistload + cblistlsearch = cblistlsearch + cblistnum = cblistnum + cblistopen = cblistopen + cblistover = cblistover + cblistpop = cblistpop + cblistpush = cblistpush + cblistpushbuf = cblistpushbuf + cblistremove = cblistremove + cblistshift = cblistshift + cblistsort = cblistsort + cblistunshift = cblistunshift + cblistval = cblistval + cblzodecode = cblzodecode + cblzoencode = cblzoencode + cbmalloc = cbmalloc + cbmapclose = cbmapclose + cbmapdump = cbmapdump + cbmapdup = cbmapdup + cbmapget = cbmapget + cbmapiterinit = cbmapiterinit + cbmapiternext = cbmapiternext + cbmapiterval = cbmapiterval + cbmapkeys = cbmapkeys + cbmapload = cbmapload + cbmaploadone = cbmaploadone + cbmapmove = cbmapmove + cbmapopen = cbmapopen + cbmapopenex = cbmapopenex + cbmapout = cbmapout + cbmapput = cbmapput + cbmapputcat = cbmapputcat + cbmaprnum = cbmaprnum + cbmapvals = cbmapvals + cbmemdup = cbmemdup + cbmimebreak = cbmimebreak + cbmimedecode = cbmimedecode + cbmimeencode = cbmimeencode + cbmimeparts = cbmimeparts + cbmyfatal = cbmyfatal + cbproctime = cbproctime + cbqsort = cbqsort + cbquotedecode = cbquotedecode + cbquoteencode = cbquoteencode + cbreadfile = cbreadfile + cbreadlines = cbreadlines + cbrealloc = cbrealloc + cbremove = cbremove + cbreplace = cbreplace + cbsplit = cbsplit + cbsprintf = cbsprintf + cbssort = cbssort + cbstdiobin = cbstdiobin + cbstrbwimatch = cbstrbwimatch + cbstrbwmatch = cbstrbwmatch + cbstrcountutf = cbstrcountutf + cbstrcututf = cbstrcututf + cbstrfwimatch = cbstrfwimatch + cbstrfwmatch = cbstrfwmatch + cbstricmp = cbstricmp + cbstrmktime = cbstrmktime + cbstrsqzspc = cbstrsqzspc + cbstrstrbm = cbstrstrbm + cbstrstrkmp = cbstrstrkmp + cbstrtolower = cbstrtolower + cbstrtoupper = cbstrtoupper + cbstrtrim = cbstrtrim + cburlbreak = cburlbreak + cburldecode = cburldecode + cburlencode = cburlencode + cburlresolve = cburlresolve + cbvmemavail = cbvmemavail + cbwritefile = cbwritefile + cbxmlattrs = cbxmlattrs + cbxmlbreak = cbxmlbreak + cbxmlescape = cbxmlescape + cbxmlunescape = cbxmlunescape + crbnum = crbnum + crbusenum = crbusenum + crclose = crclose + crexportdb = crexportdb + crfatalerror = crfatalerror + crfsiz = crfsiz + crfsizd = crfsizd + crget = crget + crgetflags = crgetflags + crgetlob = crgetlob + crgetlobfd = crgetlobfd + crgetwb = crgetwb + crimportdb = crimportdb + crinode = crinode + criterinit = criterinit + criternext = criternext + crmemflush = crmemflush + crmemsync = crmemsync + crmtime = crmtime + crname = crname + cropen = cropen + croptimize = croptimize + crout = crout + croutlob = croutlob + crput = crput + crputlob = crputlob + crremove = crremove + crrepair = crrepair + crrnum = crrnum + crrnumlob = crrnumlob + crsetalign = crsetalign + crsetfbpsiz = crsetfbpsiz + crsetflags = crsetflags + crsnaffle = crsnaffle + crsync = crsync + crvsiz = crvsiz + crvsizlob = crvsizlob + crwritable = crwritable + dbm_clearerr = dbm_clearerr + dbm_close = dbm_close + dbm_delete = dbm_delete + dbm_dirfno = dbm_dirfno + dbm_error = dbm_error + dbm_fetch = dbm_fetch + dbm_firstkey = dbm_firstkey + dbm_nextkey = dbm_nextkey + dbm_open = dbm_open + dbm_pagfno = dbm_pagfno + dbm_rdonly = dbm_rdonly + dbm_store = dbm_store + dpbnum = dpbnum + dpbusenum = dpbusenum + dpclose = dpclose + dpecodeptr = dpecodeptr + dpecodeset = dpecodeset + dperrmsg = dperrmsg + dpexportdb = dpexportdb + dpfatalerror = dpfatalerror + dpfdesc = dpfdesc + dpfsiz = dpfsiz + dpget = dpget + dpgetflags = dpgetflags + dpgetwb = dpgetwb + dpimportdb = dpimportdb + dpinnerhash = dpinnerhash + dpinode = dpinode + dpiterinit = dpiterinit + dpiternext = dpiternext + dpmemflush = dpmemflush + dpmemsync = dpmemsync + dpmtime = dpmtime + dpname = dpname + dpopen = dpopen + dpoptimize = dpoptimize + dpout = dpout + dpouterhash = dpouterhash + dpprimenum = dpprimenum + dpput = dpput + dpremove = dpremove + dprepair = dprepair + dprnum = dprnum + dpsetalign = dpsetalign + dpsetfbpsiz = dpsetfbpsiz + dpsetflags = dpsetflags + dpsnaffle = dpsnaffle + dpsync = dpsync + dpvsiz = dpvsiz + dpwritable = dpwritable + gdbm_close = gdbm_close + gdbm_delete = gdbm_delete + gdbm_errnoptr = gdbm_errnoptr + gdbm_exists = gdbm_exists + gdbm_fdesc = gdbm_fdesc + gdbm_fetch = gdbm_fetch + gdbm_firstkey = gdbm_firstkey + gdbm_nextkey = gdbm_nextkey + gdbm_open = gdbm_open + gdbm_open2 = gdbm_open2 + gdbm_reorganize = gdbm_reorganize + gdbm_setopt = gdbm_setopt + gdbm_store = gdbm_store + gdbm_strerror = gdbm_strerror + gdbm_sync = gdbm_sync + odanalyzetext = odanalyzetext + odbnum = odbnum + odbreaktext = odbreaktext + odbusenum = odbusenum + odcheck = odcheck + odclose = odclose + oddnum = oddnum + oddocaddattr = oddocaddattr + oddocaddword = oddocaddword + oddocawords = oddocawords + oddocclose = oddocclose + oddocgetattr = oddocgetattr + oddocid = oddocid + oddocnwords = oddocnwords + oddocopen = oddocopen + oddocscores = oddocscores + oddocuri = oddocuri + odfatalerror = odfatalerror + odfsiz = odfsiz + odget = odget + odgetbyid = odgetbyid + odgetidbyuri = odgetidbyuri + odidbdocs = odidbdocs + odidbindex = odidbindex + odidbrdocs = odidbrdocs + odinode = odinode + oditerinit = oditerinit + oditernext = oditernext + odlogarithm = odlogarithm + odmerge = odmerge + odmtime = odmtime + odname = odname + odnormalizeword = odnormalizeword + odopen = odopen + odoptimize = odoptimize + odout = odout + odoutbyid = odoutbyid + odpairsand = odpairsand + odpairsnotand = odpairsnotand + odpairsor = odpairsor + odpairssort = odpairssort + odput = odput + odquery = odquery + odremove = odremove + odsearch = odsearch + odsearchdnum = odsearchdnum + odsetcharclass = odsetcharclass + odsetotcb = odsetotcb + odsettuning = odsettuning + odsquareroot = odsquareroot + odsync = odsync + odvecabsolute = odvecabsolute + odvecinnerproduct = odvecinnerproduct + odvectorcosine = odvectorcosine + odwnum = odwnum + odwritable = odwritable + vlclose = vlclose + vlcrdnumptr = vlcrdnumptr + vlcurfirst = vlcurfirst + vlcurjump = vlcurjump + vlcurkey = vlcurkey + vlcurkeycache = vlcurkeycache + vlcurlast = vlcurlast + vlcurnext = vlcurnext + vlcurout = vlcurout + vlcurprev = vlcurprev + vlcurput = vlcurput + vlcurval = vlcurval + vlcurvalcache = vlcurvalcache + vlexportdb = vlexportdb + vlfatalerror = vlfatalerror + vlfsiz = vlfsiz + vlget = vlget + vlgetcache = vlgetcache + vlgetcat = vlgetcat + vlgetflags = vlgetflags + vlgetlist = vlgetlist + vlimportdb = vlimportdb + vlinode = vlinode + vllnum = vllnum + vlmemflush = vlmemflush + vlmemsync = vlmemsync + vlmtime = vlmtime + vlmulcurclose = vlmulcurclose + vlmulcurfirst = vlmulcurfirst + vlmulcurjump = vlmulcurjump + vlmulcurkey = vlmulcurkey + vlmulcurkeycache = vlmulcurkeycache + vlmulcurlast = vlmulcurlast + vlmulcurnext = vlmulcurnext + vlmulcuropen = vlmulcuropen + vlmulcurprev = vlmulcurprev + vlmulcurval = vlmulcurval + vlmulcurvalcache = vlmulcurvalcache + vlname = vlname + vlnnum = vlnnum + vlopen = vlopen + vloptimize = vloptimize + vlout = vlout + vloutlist = vloutlist + vlput = vlput + vlputlist = vlputlist + vlremove = vlremove + vlrepair = vlrepair + vlrnum = vlrnum + vlsetfbpsiz = vlsetfbpsiz + vlsetflags = vlsetflags + vlsettuning = vlsettuning + vlsync = vlsync + vltranabort = vltranabort + vltranbegin = vltranbegin + vltrancommit = vltrancommit + vlvnum = vlvnum + vlvsiz = vlvsiz + vlwritable = vlwritable + vstclose = vstclose + vstcrdnumptr = vstcrdnumptr + vstcurfirst = vstcurfirst + vstcurjump = vstcurjump + vstcurkey = vstcurkey + vstcurkeycache = vstcurkeycache + vstcurlast = vstcurlast + vstcurnext = vstcurnext + vstcurout = vstcurout + vstcurprev = vstcurprev + vstcurput = vstcurput + vstcurval = vstcurval + vstcurvalcache = vstcurvalcache + vstexportdb = vstexportdb + vstfatalerror = vstfatalerror + vstfsiz = vstfsiz + vstget = vstget + vstgetcache = vstgetcache + vstgetcat = vstgetcat + vstgetflags = vstgetflags + vstgetlist = vstgetlist + vstimportdb = vstimportdb + vstinode = vstinode + vstlnum = vstlnum + vstmemflush = vstmemflush + vstmemsync = vstmemsync + vstmtime = vstmtime + vstmulcurclose = vstmulcurclose + vstmulcurfirst = vstmulcurfirst + vstmulcurjump = vstmulcurjump + vstmulcurkey = vstmulcurkey + vstmulcurkeycache = vstmulcurkeycache + vstmulcurlast = vstmulcurlast + vstmulcurnext = vstmulcurnext + vstmulcuropen = vstmulcuropen + vstmulcurprev = vstmulcurprev + vstmulcurval = vstmulcurval + vstmulcurvalcache = vstmulcurvalcache + vstname = vstname + vstnnum = vstnnum + vstopen = vstopen + vstoptimize = vstoptimize + vstout = vstout + vstoutlist = vstoutlist + vstput = vstput + vstputlist = vstputlist + vstremove = vstremove + vstrepair = vstrepair + vstrnum = vstrnum + vstsetfbpsiz = vstsetfbpsiz + vstsetflags = vstsetflags + vstsettuning = vstsettuning + vstsync = vstsync + vsttranabort = vsttranabort + vsttranbegin = vsttranbegin + vsttrancommit = vsttrancommit + vstvnum = vstvnum + vstvsiz = vstvsiz + vstwritable = vstwritable diff --git a/qdbm/qdbm.pc.in b/qdbm/qdbm.pc.in new file mode 100644 index 00000000..fae04061 --- /dev/null +++ b/qdbm/qdbm.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +libdir=@libdir@ +libexecdir=@libexecdir@ +includedir=@includedir@ +datadir=@datadir@ + +Name: QDBM +Description: a high performance embedded database library +Version: @PACKAGE_VERSION@ +Requires: +Libs: -L${libdir} -lqdbm @LIBS@ +Cflags: -I${includedir} diff --git a/qdbm/qdbm.spec.in b/qdbm/qdbm.spec.in new file mode 100644 index 00000000..9fecddbb --- /dev/null +++ b/qdbm/qdbm.spec.in @@ -0,0 +1,218 @@ +#================================================================ +# RPM Specification for QDBM +#================================================================ + + + +%define name @PACKAGE_NAME@ +%define version @PACKAGE_VERSION@ +%define release 1 +%define libver @LIBVER@ +%define librev @LIBREV@ +%define disturl http://qdbm.sourceforge.net/ +%define homeurl http://qdbm.sourceforge.net/ + +Summary: Quick Database Manager +Name: %{name} +Version: %{version} +Release: %{release} +Source: %{disturl}%{name}-%{version}.tar.gz +Copyright: LGPL +Group: Development/Libraries +Packager: Mikio Hirabayashi +Distribution: Private +Vendor: Private +Url: %{homeurl} +Requires: zlib +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root + +%description +QDBM is an embeded database library compatible with GDBM and NDBM. +It features hash database and B+ tree database and is developed referring +to GDBM for the purpose of the following three points: higher processing +speed, smaller size of a database file, and simpler API. +This package includes APIs for C, C++, and Java. CGI scripts are also +contained. APIs for Perl and Ruby should be installed with a source package. + +%package devel +Summary: Headers, libraries, utilities and documentation for QDBM +Group: Development/Libraries +Requires: %{name} = %{version} + +%description devel +This package contains header files and libraries needed to develop programs +using the QDBM library. Some utility commands are also provided. + +%package plus +Summary: C++ libraries for QDBM +Group: Development/Libraries +Requires: %{name} = %{version} + +%description plus +This package contains libraries needed to develop and run programs using the +QDBM C++ bindings. + +%package java +Summary: Java libraries for QDBM +Group: Development/Libraries +Requires: %{name} = %{version} + +%description java +This package contains libraries needed to develop and run programs using the +QDBM Java bindings. + +%package cgi +Summary: CGI scripts with QDBM +Group: Development/Libraries +Requires: %{name} = %{version} + +%description cgi +This package contains CGI scripts with QDBM, for administration of databases, +file uploading, and full-text search. + +%prep +rm -rf $RPM_BUILD_ROOT + +%setup -q + +%build +( cd . ; %{configure} --prefix=%{_usr} --mandir=%{_mandir} \ + --enable-stable --enable-zlib --enable-iconv --enable-pthread ; make ) +( cd plus ; %{configure} --prefix=%{_usr} --mandir=%{_mandir} ; make ) +( cd java ; %{configure} --prefix=%{_usr} --mandir=%{_mandir} ; make ) +( cd cgi ; %{configure} --prefix=%{_usr} --mandir=%{_mandir} ; make ) + +%install +rm -rf $RPM_BUILD_ROOT +( cd . ; make DESTDIR=$RPM_BUILD_ROOT install-strip ) +( cd plus ; make DESTDIR=$RPM_BUILD_ROOT install-strip ) +( cd java ; make DESTDIR=$RPM_BUILD_ROOT install ) +( cd cgi ; make DESTDIR=$RPM_BUILD_ROOT install-strip ) +( mkdir -p $RPM_BUILD_ROOT%{_datadir}/doc/qdbm && \ + cd $RPM_BUILD_ROOT%{_usr}/share/qdbm && \ + cp -Rf spex-ja.html spex.html COPYING ChangeLog NEWS THANKS \ + plus/xspex.html plus/xspex-ja.html plus/xapidoc \ + java/jspex.html java/jspex-ja.html java/japidoc \ + cgi/cgispex-ja.html cgi/cgispex.html $RPM_BUILD_ROOT%{_datadir}/doc/qdbm ) + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root) +%{_libdir}/libqdbm.so.%{libver}.%{librev}.0 +%{_libdir}/libqdbm.so.%{libver} +%{_libdir}/libqdbm.so + +%files devel +%defattr(-,root,root) +%{_includedir}/depot.h +%{_includedir}/curia.h +%{_includedir}/relic.h +%{_includedir}/hovel.h +%{_includedir}/cabin.h +%{_includedir}/villa.h +%{_includedir}/vista.h +%{_includedir}/odeum.h +%{_libdir}/libqdbm.a +%{_bindir}/dpmgr +%{_bindir}/dptest +%{_bindir}/dptsv +%{_bindir}/crmgr +%{_bindir}/crtest +%{_bindir}/crtsv +%{_bindir}/rlmgr +%{_bindir}/rltest +%{_bindir}/hvmgr +%{_bindir}/hvtest +%{_bindir}/cbtest +%{_bindir}/cbcodec +%{_bindir}/vlmgr +%{_bindir}/vltest +%{_bindir}/vltsv +%{_bindir}/odmgr +%{_bindir}/odtest +%{_bindir}/odidx +%{_bindir}/qmttest +%{_mandir}/man1/dpmgr.1.gz +%{_mandir}/man1/dptest.1.gz +%{_mandir}/man1/dptsv.1.gz +%{_mandir}/man1/crmgr.1.gz +%{_mandir}/man1/crtest.1.gz +%{_mandir}/man1/crtsv.1.gz +%{_mandir}/man1/rlmgr.1.gz +%{_mandir}/man1/rltest.1.gz +%{_mandir}/man1/hvmgr.1.gz +%{_mandir}/man1/hvtest.1.gz +%{_mandir}/man1/cbtest.1.gz +%{_mandir}/man1/cbcodec.1.gz +%{_mandir}/man1/vlmgr.1.gz +%{_mandir}/man1/vltest.1.gz +%{_mandir}/man1/vltsv.1.gz +%{_mandir}/man1/odmgr.1.gz +%{_mandir}/man1/odtest.1.gz +%{_mandir}/man1/odidx.1.gz +%{_mandir}/man1/qmttest.1.gz +%{_mandir}/man3/qdbm.3.gz +%{_mandir}/man3/depot.3.gz +%{_mandir}/man3/dpopen.3.gz +%{_mandir}/man3/curia.3.gz +%{_mandir}/man3/cropen.3.gz +%{_mandir}/man3/relic.3.gz +%{_mandir}/man3/hovel.3.gz +%{_mandir}/man3/cabin.3.gz +%{_mandir}/man3/villa.3.gz +%{_mandir}/man3/vlopen.3.gz +%{_mandir}/man3/vista.3.gz +%{_mandir}/man3/odeum.3.gz +%{_mandir}/man3/odopen.3.gz +%{_datadir}/doc/qdbm/spex.html +%{_datadir}/doc/qdbm/spex-ja.html +%{_datadir}/doc/qdbm/COPYING +%{_datadir}/doc/qdbm/ChangeLog +%{_datadir}/doc/qdbm/NEWS +%{_datadir}/doc/qdbm/THANKS +%{_libdir}/pkgconfig/qdbm.pc + +%files plus +%defattr(-,root,root) +%{_includedir}/xqdbm.h +%{_includedir}/xadbm.h +%{_includedir}/xdepot.h +%{_includedir}/xcuria.h +%{_includedir}/xvilla.h +%{_libdir}/libxqdbm.a +%{_libdir}/libxqdbm.so.3.0.0 +%{_libdir}/libxqdbm.so.3 +%{_libdir}/libxqdbm.so +%{_bindir}/xdptest +%{_bindir}/xcrtest +%{_bindir}/xvltest +%{_datadir}/doc/qdbm/xspex.html +%{_datadir}/doc/qdbm/xspex-ja.html +%{_datadir}/doc/qdbm/xapidoc/ + +%files java +%defattr(-,root,root) +%{_libdir}/qdbm.jar +%{_libdir}/libjqdbm.so.1.0.0 +%{_libdir}/libjqdbm.so.1 +%{_libdir}/libjqdbm.so +%{_datadir}/doc/qdbm/jspex.html +%{_datadir}/doc/qdbm/jspex-ja.html +%{_datadir}/doc/qdbm/japidoc/ + +%files cgi +%defattr(-,root,root) +%{_libexecdir}/qadm.cgi +%{_libexecdir}/qupl.cgi +%{_libexecdir}/qfts.cgi +%{_datadir}/qdbm/cgi/qadm.conf +%{_datadir}/qdbm/cgi/qupl.conf +%{_datadir}/qdbm/cgi/qfts.conf +%{_datadir}/doc/qdbm/cgispex.html +%{_datadir}/doc/qdbm/cgispex-ja.html + + + +# END OF FILE diff --git a/qdbm/qmttest.c b/qdbm/qmttest.c new file mode 100644 index 00000000..afc8b361 --- /dev/null +++ b/qdbm/qmttest.c @@ -0,0 +1,300 @@ +/************************************************************************************************* + * Test cases for thread-safety + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(MYPTHREAD) +#include +#include +#endif + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define PATHBUFSIZ 1024 /* buffer for paths */ +#define RECBUFSIZ 32 /* buffer for records */ + +typedef struct { /* type of structure of thread arguments */ + int id; /* ID of the thread */ + const char *name; /* prefix of the database */ + int rnum; /* number of records */ + int alive; /* alive or not */ +} MYARGS; + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +void pdperror(const char *name); +void *procthread(void *args); +int dotest(const char *name, int rnum, int tnum); + + +/* main routine */ +int main(int argc, char **argv){ + char *env, *name; + int rv, rnum, tnum; + cbstdiobin(); + if((env = getenv("QDBMDBGFD")) != NULL) dpdbgfd = atoi(env); + progname = argv[0]; + srand(time(NULL)); + if(argc < 4) usage(); + name = argv[1]; + if((rnum = atoi(argv[2])) < 1) usage(); + if((tnum = atoi(argv[3])) < 1) usage(); + rv = dotest(name, rnum, tnum); + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: test cases for thread-safety\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s name rnum tnum\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* print formatted string and flush the buffer */ +int printfflush(const char *format, ...){ +#if defined(MYPTHREAD) + static pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER; + va_list ap; + int rv; + if(pthread_mutex_lock(&mymutex) != 0) return -1; + va_start(ap, format); + rv = vprintf(format, ap); + if(fflush(stdout) == EOF) rv = -1; + va_end(ap); + pthread_mutex_unlock(&mymutex); + return rv; +#else + va_list ap; + int rv; + va_start(ap, format); + rv = vprintf(format, ap); + if(fflush(stdout) == EOF) rv = -1; + va_end(ap); + return rv; +#endif +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* pseudo random number generator */ +int myrand(void){ + static int cnt = 0; + return (rand() * rand() + (rand() >> (sizeof(int) * 4)) + (cnt++)) & INT_MAX; +} + + +/* process the test */ +void *procthread(void *args){ + MYARGS *myargs; + DEPOT *depot; + CURIA *curia; + VILLA *villa; + CBLIST *list; + CBMAP *map; + char name[PATHBUFSIZ], buf[RECBUFSIZ]; + int i, err, len; + myargs = (MYARGS *)args; + err = FALSE; + sprintf(name, "%s-%04d", myargs->name, myargs->id); + dpremove(name); + crremove(name); + vlremove(name); + switch(myrand() % 4){ + case 0: + printfflush("\n[Depot Test] name=%s rnum=%d\n", name, myargs->rnum); + if(!(depot = dpopen(name, DP_OWRITER | DP_OCREAT | DP_OTRUNC, -1))){ + pdperror(name); + return "error"; + } + for(i = 1; i <= myargs->rnum; i++){ + len = sprintf(buf, "%d", myrand() % i + 1); + if(!dpput(depot, buf, len, buf, len, i % 2 == 0 ? DP_DOVER : DP_DCAT)){ + pdperror(name); + err = TRUE; + } + if(myargs->rnum > 250 && i % (myargs->rnum / 250) == 0){ + printfflush("."); + if(i == myargs->rnum || i % (myargs->rnum / 10) == 0){ + printfflush("\n%s: (%d)\n", name, i); + } + } + } + if(!dpclose(depot)){ + pdperror(name); + err = TRUE; + } + printfflush("\n%s: finished\n", name); + break; + case 1: + printfflush("\n[Curia Test] name=%s rnum=%d\n", name, myargs->rnum); + if(!(curia = cropen(name, CR_OWRITER | CR_OCREAT | CR_OTRUNC, -1, -1))){ + pdperror(name); + return "error"; + } + for(i = 1; i <= myargs->rnum; i++){ + len = sprintf(buf, "%d", myrand() % i + 1); + if(!crput(curia, buf, len, buf, len, i % 2 == 0 ? CR_DOVER : CR_DCAT)){ + pdperror(name); + err = TRUE; + } + if(myargs->rnum > 250 && i % (myargs->rnum / 250) == 0){ + printfflush("."); + if(i == myargs->rnum || i % (myargs->rnum / 10) == 0){ + printfflush("\n%s: (%d)\n", name, i); + } + } + } + if(!crclose(curia)){ + pdperror(name); + err = TRUE; + } + printfflush("\n%s: finished\n", name); + break; + case 2: + printfflush("\n[Villa Test] name=%s rnum=%d\n", name, myargs->rnum); + if(!(villa = vlopen(name, VL_OWRITER | VL_OCREAT | VL_OTRUNC, VL_CMPLEX))){ + pdperror(name); + return "error"; + } + for(i = 1; i <= myargs->rnum; i++){ + len = sprintf(buf, "%d", myrand() % i + 1); + if(!vlput(villa, buf, len, buf, len, i % 2 == 0 ? VL_DOVER : VL_DDUP)){ + pdperror(name); + err = TRUE; + } + if(myargs->rnum > 250 && i % (myargs->rnum / 250) == 0){ + printfflush("."); + if(i == myargs->rnum || i % (myargs->rnum / 10) == 0){ + printfflush("\n%s: (%d)\n", name, i); + } + } + } + if(!vlclose(villa)){ + pdperror(name); + err = TRUE; + } + printfflush("\n%s: finished\n", name); + break; + case 3: + printfflush("\n[Cabin Test] name=%s rnum=%d\n", name, myargs->rnum); + list = cblistopen(); + map = cbmapopen(); + for(i = 1; i <= myargs->rnum; i++){ + len = sprintf(buf, "%d", myrand() % i + 1); + cblistpush(list, buf, len); + cbmapput(map, buf, len, buf, len, i % 2 == 0 ? TRUE : FALSE); + if(myargs->rnum > 250 && i % (myargs->rnum / 250) == 0){ + printfflush("."); + if(i == myargs->rnum || i % (myargs->rnum / 10) == 0){ + printfflush("\n%s: (%d)\n", name, i); + } + } + } + cbmapclose(map); + cblistclose(list); + printfflush("\n%s: finished\n", name); + break; + } + return err ? "error" : NULL; +} + + +/* drive the test */ +int dotest(const char *name, int rnum, int tnum){ +#if defined(MYPTHREAD) + pthread_t *thary; + MYARGS *argsary; + char *rv; + int i, err; + printfflush("\n name=%s rnum=%d tnum=%d\n", name, rnum, tnum); + err = FALSE; + thary = cbmalloc(tnum * sizeof(pthread_t)); + argsary = cbmalloc(tnum * sizeof(MYARGS)); + for(i = 0; i < tnum; i++){ + argsary[i].id = i + 1; + argsary[i].name = name; + argsary[i].rnum = rnum; + argsary[i].alive = TRUE; + if(pthread_create(thary + i, NULL, procthread, argsary + i) != 0){ + argsary[i].alive = FALSE; + err = TRUE; + } + } + for(i = 0; i < tnum; i++){ + if(!argsary[i].alive) continue; + if(pthread_join(thary[i], (void *)&rv) != 0 || rv) err = TRUE; + } + free(argsary); + free(thary); + if(!err) printfflush("\nall ok\n"); + return err ? 1 : 0; +#else + MYARGS *argsary; + int i, err; + printfflush("\n name=%s rnum=%d tnum=%d\n", name, rnum, tnum); + err = FALSE; + argsary = cbmalloc(tnum * sizeof(MYARGS)); + for(i = 0; i < tnum; i++){ + argsary[i].id = i + 1; + argsary[i].name = name; + argsary[i].rnum = rnum; + argsary[i].alive = TRUE; + if(procthread(argsary + i)) err = TRUE; + } + free(argsary); + if(!err) printfflush("\nall ok\n"); + return err ? 1 : 0; +#endif +} + + + +/* END OF FILE */ diff --git a/qdbm/relic.c b/qdbm/relic.c new file mode 100644 index 00000000..31bbbde2 --- /dev/null +++ b/qdbm/relic.c @@ -0,0 +1,266 @@ +/************************************************************************************************* + * Implementation of Relic + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#define QDBM_INTERNAL 1 + +#include "relic.h" +#include "myconf.h" + +#define RL_NAMEMAX 512 /* max size of a database name */ +#define RL_DIRFSUF MYEXTSTR "dir" /* suffix of a directory file */ +#define RL_DATAFSUF MYEXTSTR "pag" /* suffix of a page file */ +#define RL_PATHBUFSIZ 1024 /* size of a path buffer */ +#define RL_INITBNUM 1913 /* initial bucket number */ +#define RL_ALIGNSIZ 16 /* size of alignment */ +#define RL_MAXLOAD 1.25 /* max ratio of bucket loading */ +#define RL_DIRMAGIC "[depot]\0\v" /* magic number of a directory file */ + + +/* private function prototypes */ +static void dbm_writedummy(int fd); +static int dbm_writestr(int fd, const char *str); + + + +/************************************************************************************************* + * public objects + *************************************************************************************************/ + + +/* Get a database handle. */ +DBM *dbm_open(char *name, int flags, int mode){ + DBM *db; + DEPOT *depot; + int dpomode; + char path[RL_PATHBUFSIZ]; + int dfd, fd; + assert(name); + if(strlen(name) > RL_NAMEMAX) return NULL; + dpomode = DP_OREADER; + if((flags & O_WRONLY) || (flags & O_RDWR)){ + dpomode = DP_OWRITER; + if(flags & O_CREAT) dpomode |= DP_OCREAT; + if(flags & O_TRUNC) dpomode |= DP_OTRUNC; + } + mode |= 00600; + sprintf(path, "%s%s", name, RL_DIRFSUF); + if((dfd = open(path, flags, mode)) == -1) return NULL; + dbm_writedummy(dfd); + sprintf(path, "%s%s", name, RL_DATAFSUF); + if((fd = open(path, flags, mode)) == -1 || close(fd) == -1){ + close(dfd); + return NULL; + } + if(!(depot = dpopen(path, dpomode, RL_INITBNUM))){ + close(dfd); + return NULL; + } + if(dpomode & DP_OWRITER){ + if(!dpsetalign(depot, RL_ALIGNSIZ)){ + close(dfd); + dpclose(depot); + return NULL; + } + } + if(!(db = malloc(sizeof(DBM)))){ + close(dfd); + dpclose(depot); + return NULL; + } + db->depot = depot; + db->dfd = dfd; + db->dbm_fetch_vbuf = NULL; + db->dbm_nextkey_kbuf = NULL; + return db; +} + + +/* Close a database handle. */ +void dbm_close(DBM *db){ + assert(db); + free(db->dbm_fetch_vbuf); + free(db->dbm_nextkey_kbuf); + close(db->dfd); + dpclose(db->depot); + free(db); +} + + +/* Store a record. */ +int dbm_store(DBM *db, datum key, datum content, int flags){ + int dmode; + int bnum, rnum; + assert(db); + if(!key.dptr || key.dsize < 0 || !content.dptr || content.dsize < 0) return -1; + dmode = (flags == DBM_INSERT) ? DP_DKEEP : DP_DOVER; + if(!dpput(db->depot, key.dptr, key.dsize, content.dptr, content.dsize, dmode)){ + if(dpecode == DP_EKEEP) return 1; + return -1; + } + bnum = dpbnum(db->depot); + rnum = dprnum(db->depot); + if(bnum > 0 && rnum > 0 && ((double)rnum / (double)bnum > RL_MAXLOAD)){ + if(!dpoptimize(db->depot, -1)) return -1; + } + return 0; +} + + +/* Delete a record. */ +int dbm_delete(DBM *db, datum key){ + assert(db); + if(!key.dptr || key.dsize < 0) return -1; + if(!dpout(db->depot, key.dptr, key.dsize)) return -1; + return 0; +} + + +/* Retrieve a record. */ +datum dbm_fetch(DBM *db, datum key){ + datum content; + char *vbuf; + int vsiz; + assert(db); + if(!key.dptr || key.dsize < 0 || + !(vbuf = dpget(db->depot, key.dptr, key.dsize, 0, -1, &vsiz))){ + content.dptr = NULL; + content.dsize = 0; + return content; + } + free(db->dbm_fetch_vbuf); + db->dbm_fetch_vbuf = vbuf; + content.dptr = vbuf; + content.dsize = vsiz; + return content; +} + + +/* Get the first key of a database. */ +datum dbm_firstkey(DBM *db){ + assert(db); + dpiterinit(db->depot); + return dbm_nextkey(db); +} + + +/* Get the next key of a database. */ +datum dbm_nextkey(DBM *db){ + datum key; + char *kbuf; + int ksiz; + if(!(kbuf = dpiternext(db->depot, &ksiz))){ + key.dptr = NULL; + key.dsize = 0; + return key; + } + free(db->dbm_nextkey_kbuf); + db->dbm_nextkey_kbuf = kbuf; + key.dptr = kbuf; + key.dsize = ksiz; + return key; +} + + +/* Check whether a database has a fatal error or not. */ +int dbm_error(DBM *db){ + assert(db); + return dpfatalerror(db->depot) ? TRUE : FALSE; +} + + +/* No effect. */ +int dbm_clearerr(DBM *db){ + assert(db); + return 0; +} + + +/* Check whether a handle is read-only or not. */ +int dbm_rdonly(DBM *db){ + assert(db); + return dpwritable(db->depot) ? FALSE : TRUE; +} + + +/* Get the file descriptor of a directory file. */ +int dbm_dirfno(DBM *db){ + assert(db); + return db->dfd; +} + + +/* Get the file descriptor of a data file. */ +int dbm_pagfno(DBM *db){ + assert(db); + return dpfdesc(db->depot); +} + + + +/************************************************************************************************* + * private objects + *************************************************************************************************/ + + +/* Write dummy data into a dummy file. + `fd' specifies a file descriptor. */ +static void dbm_writedummy(int fd){ + struct stat sbuf; + if(fstat(fd, &sbuf) == -1 || sbuf.st_size > 0) return; + write(fd, RL_DIRMAGIC, sizeof(RL_DIRMAGIC) - 1); + dbm_writestr(fd, "\n\n"); + dbm_writestr(fd, "\x20\x20\xa2\xca\xa1\xb2\xa2\xca\x20\x20\x20\x20\x20\xa1\xbf\xa1"); + dbm_writestr(fd, "\xb1\xa1\xb1\xa1\xb1\xa1\xb1\xa1\xb1\xa1\xb1\xa1\xb1\xa1\xb1\xa1"); + dbm_writestr(fd, "\xb1\x0a\xa1\xca\x20\xa1\xad\xa2\xcf\xa1\xae\xa1\xcb\xa1\xe3\x20"); + dbm_writestr(fd, "\x20\x4e\x44\x42\x4d\x20\x43\x6f\x6d\x70\x61\x74\x69\x62\x69\x6c"); + dbm_writestr(fd, "\x69\x74\x79\x0a\xa1\xca\x20\x20\x20\x20\x20\x20\x20\xa1\xcb\x20"); + dbm_writestr(fd, "\x20\xa1\xc0\xa1\xb2\xa1\xb2\xa1\xb2\xa1\xb2\xa1\xb2\xa1\xb2\xa1"); + dbm_writestr(fd, "\xb2\xa1\xb2\xa1\xb2\x0a\x20\xa1\xc3\x20\x20\xa1\xc3\x20\xa1\xc3"); + dbm_writestr(fd, "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"); + dbm_writestr(fd, "\x20\x20\x20\x20\x20\x20\x20\x0a\xa1\xca\x5f\x5f\xa1\xb2\xa1\xcb"); + dbm_writestr(fd, "\x5f\xa1\xcb\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"); + dbm_writestr(fd, "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x0a"); +} + + +/* Write a string into a file. + `fd' specifies a file descriptor. + `str' specifies a string. */ +static int dbm_writestr(int fd, const char *str){ + const char *lbuf; + int size, rv, wb; + assert(fd >= 0 && str); + lbuf = str; + size = strlen(str); + rv = 0; + do { + wb = write(fd, lbuf, size); + switch(wb){ + case -1: if(errno != EINTR) return -1; + case 0: break; + default: + lbuf += wb; + size -= wb; + rv += wb; + break; + } + } while(size > 0); + return rv; +} + + + +/* END OF FILE */ diff --git a/qdbm/relic.h b/qdbm/relic.h new file mode 100644 index 00000000..c5b7c51f --- /dev/null +++ b/qdbm/relic.h @@ -0,0 +1,170 @@ +/************************************************************************************************* + * The NDBM-compatible API of QDBM + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#ifndef _RELIC_H /* duplication check */ +#define _RELIC_H + +#if defined(__cplusplus) /* export for C++ */ +extern "C" { +#endif + + +#include +#include +#include +#include +#include + + +#if defined(_MSC_VER) && !defined(QDBM_INTERNAL) && !defined(QDBM_STATIC) +#define MYEXTERN extern __declspec(dllimport) +#else +#define MYEXTERN extern +#endif + + + +/************************************************************************************************* + * API + *************************************************************************************************/ + + +typedef struct { /* type of structure for a database handle */ + DEPOT *depot; /* internal database handle */ + int dfd; /* file descriptor of a dummy file */ + char *dbm_fetch_vbuf; /* buffer for dbm_fetch */ + char *dbm_nextkey_kbuf; /* buffer for dbm_nextkey */ +} DBM; + +typedef struct { /* type of structure for a key or a value */ + void *dptr; /* pointer to the region */ + size_t dsize; /* size of the region */ +} datum; + +enum { /* enumeration for write modes */ + DBM_INSERT, /* keep an existing value */ + DBM_REPLACE /* overwrite an existing value */ +}; + + +/* Get a database handle. + `name' specifies the name of a database. The file names are concatenated with suffixes. + `flags' is the same as the one of `open' call, although `O_WRONLY' is treated as `O_RDWR' + and additional flags except for `O_CREAT' and `O_TRUNC' have no effect. + `mode' specifies the mode of the database file as the one of `open' call does. + The return value is the database handle or `NULL' if it is not successful. */ +DBM *dbm_open(char *name, int flags, int mode); + + +/* Close a database handle. + `db' specifies a database handle. + Because the region of the closed handle is released, it becomes impossible to use the + handle. */ +void dbm_close(DBM *db); + + +/* Store a record. + `db' specifies a database handle. + `key' specifies a structure of a key. + `content' specifies a structure of a value. + `flags' specifies behavior when the key overlaps, by the following values: `DBM_REPLACE', + which means the specified value overwrites the existing one, `DBM_INSERT', which means the + existing value is kept. + The return value is 0 if it is successful, 1 if it gives up because of overlaps of the key, + -1 if other error occurs. */ +int dbm_store(DBM *db, datum key, datum content, int flags); + + +/* Delete a record. + `db' specifies a database handle. + `key' specifies a structure of a key. + The return value is 0 if it is successful, -1 if some errors occur. */ +int dbm_delete(DBM *db, datum key); + + +/* Retrieve a record. + `db' specifies a database handle. + `key' specifies a structure of a key. + The return value is a structure of the result. + If a record corresponds, the member `dptr' of the structure is the pointer to the region of + the value. If no record corresponds or some errors occur, `dptr' is `NULL'. `dptr' points + to the region related with the handle. The region is available until the next time of + calling this function with the same handle. */ +datum dbm_fetch(DBM *db, datum key); + + +/* Get the first key of a database. + `db' specifies a database handle. + The return value is a structure of the result. + If a record corresponds, the member `dptr' of the structure is the pointer to the region of + the first key. If no record corresponds or some errors occur, `dptr' is `NULL'. `dptr' + points to the region related with the handle. The region is available until the next time + of calling this function or the function `dbm_nextkey' with the same handle. */ +datum dbm_firstkey(DBM *db); + + +/* Get the next key of a database. + `db' specifies a database handle. + The return value is a structure of the result. + If a record corresponds, the member `dptr' of the structure is the pointer to the region of + the next key. If no record corresponds or some errors occur, `dptr' is `NULL'. `dptr' + points to the region related with the handle. The region is available until the next time + of calling this function or the function `dbm_firstkey' with the same handle. */ +datum dbm_nextkey(DBM *db); + + +/* Check whether a database has a fatal error or not. + `db' specifies a database handle. + The return value is true if the database has a fatal error, false if not. */ +int dbm_error(DBM *db); + + +/* No effect. + `db' specifies a database handle. + The return value is 0. + The function is only for compatibility. */ +int dbm_clearerr(DBM *db); + + +/* Check whether a handle is read-only or not. + `db' specifies a database handle. + The return value is true if the handle is read-only, or false if not read-only. */ +int dbm_rdonly(DBM *db); + + +/* Get the file descriptor of a directory file. + `db' specifies a database handle. + The return value is the file descriptor of the directory file. */ +int dbm_dirfno(DBM *db); + + +/* Get the file descriptor of a data file. + `db' specifies a database handle. + The return value is the file descriptor of the data file. */ +int dbm_pagfno(DBM *db); + + + +#undef MYEXTERN + +#if defined(__cplusplus) /* export for C++ */ +} +#endif + +#endif /* duplication check */ + + +/* END OF FILE */ diff --git a/qdbm/rlmgr.c b/qdbm/rlmgr.c new file mode 100644 index 00000000..a44bc70a --- /dev/null +++ b/qdbm/rlmgr.c @@ -0,0 +1,465 @@ +/************************************************************************************************* + * Utility for debugging Relic and its applications + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +char *hextoobj(const char *str, int *sp); +int runcreate(int argc, char **argv); +int runstore(int argc, char **argv); +int rundelete(int argc, char **argv); +int runfetch(int argc, char **argv); +int runlist(int argc, char **argv); +void pmyerror(const char *name, const char *msg); +void printobj(const char *obj, int size); +void printobjhex(const char *obj, int size); +int docreate(char *name); +int dostore(char *name, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int ins); +int dodelete(char *name, const char *kbuf, int ksiz); +int dofetch(char *name, const char *kbuf, int ksiz, int ox, int nb); +int dolist(char *name, int ox); + + +/* main routine */ +int main(int argc, char **argv){ + int rv; + cbstdiobin(); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "create")){ + rv = runcreate(argc, argv); + } else if(!strcmp(argv[1], "store")){ + rv = runstore(argc, argv); + } else if(!strcmp(argv[1], "delete")){ + rv = rundelete(argc, argv); + } else if(!strcmp(argv[1], "fetch")){ + rv = runfetch(argc, argv); + } else if(!strcmp(argv[1], "list")){ + rv = runlist(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: administration utility for Relic\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s create name\n", progname); + fprintf(stderr, " %s store [-kx] [-vx|-vf] [-insert] name key val\n", progname); + fprintf(stderr, " %s delete [-kx] name key\n", progname); + fprintf(stderr, " %s fetch [-kx] [-ox] [-n] name key\n", progname); + fprintf(stderr, " %s list [-ox] name\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* create a binary object from a hexadecimal string */ +char *hextoobj(const char *str, int *sp){ + char *buf, mbuf[3]; + int len, i, j; + len = strlen(str); + if(!(buf = malloc(len + 1))) return NULL; + j = 0; + for(i = 0; i < len; i += 2){ + while(strchr(" \n\r\t\f\v", str[i])){ + i++; + } + if((mbuf[0] = str[i]) == '\0') break; + if((mbuf[1] = str[i+1]) == '\0') break; + mbuf[2] = '\0'; + buf[j++] = (char)strtol(mbuf, NULL, 16); + } + buf[j] = '\0'; + *sp = j; + return buf; +} + + +/* parse arguments of create command */ +int runcreate(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = docreate(name); + return rv; +} + + +/* parse arguments of store command */ +int runstore(int argc, char **argv){ + char *name, *key, *val, *kbuf, *vbuf; + int i, kx, vx, vf, ins, ksiz, vsiz, rv; + name = NULL; + kx = FALSE; + vx = FALSE; + vf = FALSE; + ins = FALSE; + key = NULL; + val = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-vx")){ + vx = TRUE; + } else if(!strcmp(argv[i], "-vf")){ + vf = TRUE; + } else if(!strcmp(argv[i], "-insert")){ + ins = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else if(!val){ + val = argv[i]; + } else { + usage(); + } + } + if(!name || !key || !val) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = strlen(kbuf); + } + if(vx){ + vbuf = hextoobj(val, &vsiz); + } else if(vf){ + vbuf = cbreadfile(val, &vsiz); + } else { + vbuf = cbmemdup(val, -1); + vsiz = strlen(vbuf); + } + if(kbuf && vbuf){ + rv = dostore(name, kbuf, ksiz, vbuf, vsiz, ins); + } else { + if(vf){ + fprintf(stderr, "%s: %s: cannot read\n", progname, val); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + } + rv = 1; + } + free(kbuf); + free(vbuf); + return rv; +} + + +/* parse arguments of delete command */ +int rundelete(int argc, char **argv){ + char *name, *key, *kbuf; + int i, kx, ksiz, rv; + name = NULL; + kx = FALSE; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = strlen(kbuf); + } + if(kbuf){ + rv = dodelete(name, kbuf, ksiz); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* parse arguments of fetch command */ +int runfetch(int argc, char **argv){ + char *name, *key, *kbuf; + int i, kx, ox, nb, ksiz, rv; + name = NULL; + kx = FALSE; + ox = FALSE; + nb = FALSE; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else if(!strcmp(argv[i], "-n")){ + nb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = strlen(kbuf); + } + if(kbuf){ + rv = dofetch(name, kbuf, ksiz, ox, nb); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* parse arguments of list command */ +int runlist(int argc, char **argv){ + char *name; + int i, ox, rv; + name = NULL; + ox = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dolist(name, ox); + return rv; +} + + +/* print an error message */ +void pmyerror(const char *name, const char *msg){ + fprintf(stderr, "%s: %s: %s\n", progname, name, msg); +} + + +/* print an object */ +void printobj(const char *obj, int size){ + int i; + for(i = 0; i < size; i++){ + putchar(obj[i]); + } +} + + +/* print an object as a hexadecimal string */ +void printobjhex(const char *obj, int size){ + int i; + for(i = 0; i < size; i++){ + printf("%s%02X", i > 0 ? " " : "", ((const unsigned char *)obj)[i]); + } +} + + +/* perform create command */ +int docreate(char *name){ + DBM *db; + if(!(db = dbm_open(name, O_RDWR | O_CREAT | O_TRUNC, 00644))){ + pmyerror(name, "dbm_open failed"); + return 1; + } + dbm_close(db); + return 0; +} + + +/* perform store command */ +int dostore(char *name, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int ins){ + DBM *db; + datum key, content; + int rv; + if(!(db = dbm_open(name, O_RDWR, 00644))){ + pmyerror(name, "dbm_open failed"); + return 1; + } + key.dptr = (char *)kbuf; + key.dsize = ksiz; + content.dptr = (char *)vbuf; + content.dsize = vsiz; + switch(dbm_store(db, key, content, ins ? DBM_INSERT : DBM_REPLACE)){ + case 0: + rv = 0; + break; + case 1: + pmyerror(name, "dbm_store failed by insert"); + rv = 1; + break; + default: + pmyerror(name, "dbm_store failed"); + rv = 1; + break; + } + dbm_close(db); + return rv; +} + + +/* perform delete command */ +int dodelete(char *name, const char *kbuf, int ksiz){ + DBM *db; + datum key; + int rv; + if(!(db = dbm_open((char *)name, O_RDWR, 00644))){ + pmyerror(name, "dbm_open failed"); + return 1; + } + key.dptr = (char *)kbuf; + key.dsize = ksiz; + if(dbm_delete(db, key) == 0){ + rv = 0; + } else { + pmyerror(name, "dbm_delete failed"); + rv = 1; + } + dbm_close(db); + return rv; +} + + +/* perform fetch command */ +int dofetch(char *name, const char *kbuf, int ksiz, int ox, int nb){ + DBM *db; + datum key, content; + int rv; + if(!(db = dbm_open((char *)name, O_RDONLY, 00644))){ + pmyerror(name, "dbm_open failed"); + return 1; + } + key.dptr = (char *)kbuf; + key.dsize = ksiz; + content = dbm_fetch(db, key); + if(content.dptr){ + if(ox){ + printobjhex(content.dptr, content.dsize); + } else { + printobj(content.dptr, content.dsize); + } + if(!nb) putchar('\n'); + rv = 0; + } else { + pmyerror(name, "dbm_fetch failed"); + rv = 1; + } + dbm_close(db); + return rv; +} + + +/* perform list command */ +int dolist(char *name, int ox){ + DBM *db; + datum key, val; + if(!(db = dbm_open((char *)name, O_RDONLY, 00644))){ + pmyerror(name, "dbm_open failed"); + return 1; + } + for(key = dbm_firstkey(db); key.dptr != NULL; key = dbm_nextkey(db)){ + val = dbm_fetch(db, key); + if(!val.dptr) break; + if(ox){ + printobjhex(key.dptr, key.dsize); + putchar('\t'); + printobjhex(val.dptr, val.dsize); + } else { + printobj(key.dptr, key.dsize); + putchar('\t'); + printobj(val.dptr, val.dsize); + } + putchar('\n'); + } + dbm_close(db); + return 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/rltest.c b/qdbm/rltest.c new file mode 100644 index 00000000..898855fb --- /dev/null +++ b/qdbm/rltest.c @@ -0,0 +1,241 @@ +/************************************************************************************************* + * Test cases of Relic + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define RECBUFSIZ 32 /* buffer for records */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +int runwrite(int argc, char **argv); +int runread(int argc, char **argv); +int printfflush(const char *format, ...); +void pmyerror(const char *name, const char *msg); +int dowrite(char *name, int rnum); +int doread(char *name, int rnum); + + +/* main routine */ +int main(int argc, char **argv){ + int rv; + cbstdiobin(); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "write")){ + rv = runwrite(argc, argv); + } else if(!strcmp(argv[1], "read")){ + rv = runread(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: test cases for Relic\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s write name rnum\n", progname); + fprintf(stderr, " %s read name rnum\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of write command */ +int runwrite(int argc, char **argv){ + char *name, *rstr; + int i, rnum, rv; + name = NULL; + rstr = NULL; + rnum = 0; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = dowrite(name, rnum); + return rv; +} + + +/* parse arguments of read command */ +int runread(int argc, char **argv){ + char *name, *rstr; + int i, rnum, rv; + name = NULL; + rstr = NULL; + rnum = 0; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = doread(name, rnum); + return rv; +} + + +/* print formatted string and flush the buffer */ +int printfflush(const char *format, ...){ + va_list ap; + int rv; + va_start(ap, format); + rv = vprintf(format, ap); + if(fflush(stdout) == EOF) rv = -1; + va_end(ap); + return rv; +} + + +/* print an error message */ +void pmyerror(const char *name, const char *msg){ + fprintf(stderr, "%s: %s: %s\n", progname, name, msg); +} + + +/* perform write command */ +int dowrite(char *name, int rnum){ + DBM *db; + datum key, content; + int i, err, len; + char buf[RECBUFSIZ]; + printfflush("\n name=%s rnum=%d\n\n", name, rnum); + /* open a database */ + if(!(db = dbm_open(name, O_RDWR | O_CREAT | O_TRUNC, 00644))){ + pmyerror(name, "dbm_open failed"); + return 1; + } + err = FALSE; + /* loop for each record */ + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", i); + key.dptr = buf; + key.dsize = len; + content.dptr = buf; + content.dsize = len; + /* store a record */ + if(dbm_store(db, key, content, DBM_REPLACE) < 0){ + pmyerror(name, "dbm_store failed"); + err = TRUE; + break; + } + /* print progression */ + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + dbm_close(db); + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + +/* perform read command */ +int doread(char *name, int rnum){ + DBM *db; + datum key, content; + int i, err, len; + char buf[RECBUFSIZ]; + printfflush("\n name=%s rnum=%d\n\n", name, rnum); + /* open a database */ + if(!(db = dbm_open(name, O_RDONLY, 00644))){ + pmyerror(name, "dbm_open failed"); + return 1; + } + err = FALSE; + /* loop for each record */ + for(i = 1; i <= rnum; i++){ + /* retrieve a record */ + len = sprintf(buf, "%08d", i); + key.dptr = buf; + key.dsize = len; + content = dbm_fetch(db, key); + if(!content.dptr){ + pmyerror(name, "dbm_fetch failed"); + err = TRUE; + break; + } + /* print progression */ + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + dbm_close(db); + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/spex-ja.html b/qdbm/spex-ja.html new file mode 100644 index 00000000..140167bf --- /dev/null +++ b/qdbm/spex-ja.html @@ -0,0 +1,4348 @@ + + + + + + + + + + + + + + + +Specifications of QDBM Version 1 (Japanese) + + + + + +

QDBMãƒãƒ¼ã‚¸ãƒ§ãƒ³ï¼‘基本仕様書

+ +
Copyright (C) 2000-2007 Mikio Hirabayashi
+
Last Update: Thu, 26 Oct 2006 15:00:20 +0900
+ + +
+ +

目次

+ +
    +
  1. 概è¦
  2. +
  3. 特徴
  4. +
  5. インストール
  6. +
  7. Depot: 基本API
  8. +
  9. Depot用コマンド
  10. +
  11. Curia: æ‹¡å¼µAPI
  12. +
  13. Curia用コマンド
  14. +
  15. Relic: NDBM互æ›API
  16. +
  17. Relic用コマンド
  18. +
  19. Hovel: GDBM互æ›API
  20. +
  21. Hovel用コマンド
  22. +
  23. Cabin: ユーティリティAPI
  24. +
  25. Cabin用コマンド
  26. +
  27. Villa: 上級API
  28. +
  29. Villa用コマンド
  30. +
  31. Odeum: 転置API
  32. +
  33. Odeum用コマンド
  34. +
  35. ファイルフォーマット
  36. +
  37. 移æ¤æ–¹æ³•
  38. +
  39. ãƒã‚°
  40. +
  41. よãèžã‹ã‚Œã‚‹è³ªå•
  42. +
  43. ライセンス
  44. +
+ +
+ +

概è¦

+ +

QDBMã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†ãƒ«ãƒ¼ãƒãƒ³ç¾¤ã®ãƒ©ã‚¤ãƒ–ラリã§ã‚る。データベースã¨ã„ã£ã¦ã‚‚å˜ç´”ãªã‚‚ã®ã§ã‚ã‚Šã€ã‚­ãƒ¼ã¨å€¤ã®ãƒšã‚¢ã‹ã‚‰ãªã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ç¾¤ã‚’æ ¼ç´ã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ã§ã‚る。キーã¨å€¤ã¯ä»»æ„ã®é•·ã•ã‚’æŒã¤ä¸€é€£ã®ãƒã‚¤ãƒˆåˆ—ã§ã‚ã‚Šã€æ–‡å­—列ã§ã‚‚ãƒã‚¤ãƒŠãƒªã§ã‚‚扱ã†ã“ã¨ãŒã§ãる。テーブルやデータ型ã®æ¦‚念ã¯ãªã„。レコードã¯ãƒãƒƒã‚·ãƒ¥è¡¨ã¾ãŸã¯B+木ã§ç·¨æˆã•ã‚Œã‚‹ã€‚

+ +

ãƒãƒƒã‚·ãƒ¥è¡¨ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã§ã¯ã€ã‚­ãƒ¼ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹å†…ã§ä¸€æ„ã§ã‚ã‚Šã€ã‚­ãƒ¼ãŒé‡è¤‡ã™ã‚‹è¤‡æ•°ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã™ã‚‹ã“ã¨ã¯ã§ããªã„。ã“ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«å¯¾ã—ã¦ã¯ã€ã‚­ãƒ¼ã¨å€¤ã‚’指定ã—ã¦ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã—ãŸã‚Šã€ã‚­ãƒ¼ã‚’指定ã—ã¦å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã—ãŸã‚Šã€ã‚­ãƒ¼ã‚’指定ã—ã¦å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã—ãŸã‚Šã™ã‚‹ã“ã¨ãŒã§ãる。ã¾ãŸã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã—ã¦ã‚ã‚‹å…¨ã¦ã®ã‚­ãƒ¼ã‚’é †ä¸åŒã«ä¸€ã¤ãšã¤å–り出ã™ã“ã¨ã‚‚ã§ãる。ã“ã®ã‚ˆã†ãªæ“作ã¯ã€UNIX標準ã§å®šç¾©ã•ã‚Œã¦ã„ã‚‹DBMライブラリãŠã‚ˆã³ãã®è¿½å¾“ã§ã‚ã‚‹NDBMã‚„GDBMã«é¡žã™ã‚‹ã‚‚ã®ã§ã‚る。QDBMã¯DBMã®ã‚ˆã‚Šè‰¯ã„代替ã¨ã—ã¦åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ãる。

+ +

B+木ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã§ã¯ã€ã‚­ãƒ¼ãŒé‡è¤‡ã™ã‚‹è¤‡æ•°ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã™ã‚‹ã“ã¨ãŒã§ãる。ã“ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«å¯¾ã—ã¦ã¯ã€ãƒãƒƒã‚·ãƒ¥è¡¨ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¨åŒæ§˜ã«ã€ã‚­ãƒ¼ã‚’指定ã—ã¦ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã—ãŸã‚Šå–り出ã—ãŸã‚Šå‰Šé™¤ã—ãŸã‚Šã™ã‚‹ã“ã¨ãŒã§ãる。レコードã¯ãƒ¦ãƒ¼ã‚¶ãŒæŒ‡ç¤ºã—ãŸæ¯”較関数ã«åŸºã¥ã„ã¦æ•´åˆ—ã•ã‚Œã¦æ ¼ç´ã•ã‚Œã‚‹ã€‚カーソルを用ã„ã¦å„レコードを昇順ã¾ãŸã¯é™é †ã§å‚ç…§ã™ã‚‹ã“ã¨ãŒã§ãる。ã“ã®æ©Ÿæ§‹ã«ã‚ˆã£ã¦ã€æ–‡å­—列ã®å‰æ–¹ä¸€è‡´æ¤œç´¢ã‚„数値ã®ç¯„囲検索ãŒå¯èƒ½ã«ãªã‚‹ã€‚ã¾ãŸã€B+木ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã§ã¯ãƒˆãƒ©ãƒ³ã‚¶ã‚¯ã‚·ãƒ§ãƒ³ãŒåˆ©ç”¨ã§ãる。

+ +

QDBMã¯Cã§è¨˜è¿°ã•ã‚Œã€Cã€C++ã€Javaã€PerlãŠã‚ˆã³Rubyã®APIã¨ã—ã¦æä¾›ã•ã‚Œã‚‹ã€‚QDBMã¯POSIX準拠ã®APIã‚’å‚™ãˆã‚‹ãƒ—ラットフォームã§åˆ©ç”¨ã§ãる。QDBMã¯GNU Lesser General Public Licenseã«åŸºã¥ãフリーソフトウェアã§ã‚る。

+ +
+ +

特徴

+ +

効率的ãªãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å®Ÿè£…

+ +

QDBMã¯GDBMã‚’å‚考ã«æ¬¡ã®ä¸‰ç‚¹ã‚’目標ã¨ã—ã¦é–‹ç™ºã•ã‚ŒãŸã€‚処ç†ãŒã‚ˆã‚Šé«˜é€Ÿã§ã‚ã‚‹ã“ã¨ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ãŒã‚ˆã‚Šå°ã•ã„ã“ã¨ã€APIãŒã‚ˆã‚Šå˜ç´”ã§ã‚ã‚‹ã“ã¨ã€‚ã“れらã®ç›®æ¨™ã¯é”æˆã•ã‚Œã¦ã„る。ã¾ãŸã€GDBMã¨åŒæ§˜ã«ã€ä¼çµ±çš„ãªDBMãŒæŠ±ãˆã‚‹ä¸‰ã¤ã®åˆ¶é™äº‹é …を回é¿ã—ã¦ã„る。ã™ãªã‚ã¡ã€ãƒ—ロセス内ã§è¤‡æ•°ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†ã“ã¨ãŒã§ãã€ã‚­ãƒ¼ã¨å€¤ã®ã‚µã‚¤ã‚ºã«åˆ¶é™ãŒãªãã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ãŒã‚¹ãƒ‘ースã§ã¯ãªã„。

+ +

QDBMã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æŽ¢ç´¢ã«ãƒãƒƒã‚·ãƒ¥ã‚¢ãƒ«ã‚´ãƒªã‚ºãƒ ã‚’用ã„る。ãƒã‚±ãƒƒãƒˆé…列ã«å分ãªè¦ç´ æ•°ãŒã‚ã‚Œã°ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æŽ¢ç´¢ã«ã‹ã‹ã‚‹æ™‚間計算é‡ã¯ O(1) ã§ã‚る。ã™ãªã‚ã¡ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æŽ¢ç´¢ã«å¿…è¦ãªæ™‚é–“ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®è¦æ¨¡ã«é–¢ã‚らãšä¸€å®šã§ã‚る。追加や削除ã«é–¢ã—ã¦ã‚‚åŒæ§˜ã§ã‚る。ãƒãƒƒã‚·ãƒ¥å€¤ã®è¡çªã¯ã‚»ãƒ‘レートãƒã‚§ãƒ¼ãƒ³æ³•ã§ç®¡ç†ã™ã‚‹ã€‚ãƒã‚§ãƒ¼ãƒ³ã®ãƒ‡ãƒ¼ã‚¿æ§‹é€ ã¯äºŒåˆ†æŽ¢ç´¢æœ¨ã§ã‚る。ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ãŒè‘—ã—ãå°‘ãªã„å ´åˆã§ã‚‚ã€æŽ¢ç´¢ç­‰ã®æ™‚間計算é‡ã¯ O(log n) ã«æŠ‘ãˆã‚‰ã‚Œã‚‹ã€‚

+ +

QDBMã¯ãƒã‚±ãƒƒãƒˆé…列を全ã¦RAM上ã«ä¿æŒã™ã‚‹ã“ã¨ã«ã‚ˆã£ã¦ã€å‡¦ç†ã®é«˜é€ŸåŒ–を図る。ãƒã‚±ãƒƒãƒˆé…列ãŒRAM上ã«ã‚ã‚Œã°ã€ã»ã¼1パスã®ãƒ•ã‚¡ã‚¤ãƒ«æ“作ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã«è©²å½“ã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ä¸Šã®é ˜åŸŸã‚’å‚ç…§ã™ã‚‹ã“ã¨ãŒã§ãる。ファイルã«è¨˜éŒ²ã•ã‚ŒãŸãƒã‚±ãƒƒãƒˆé…列㯠`read' コールã§RAM上ã«èª­ã¿è¾¼ã‚€ã®ã§ã¯ãªãã€`mmap' コールã§RAMã«ç›´æŽ¥ãƒžãƒƒãƒ”ングã•ã‚Œã‚‹ã€‚ã—ãŸãŒã£ã¦ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æŽ¥ç¶šã™ã‚‹éš›ã®æº–備時間ãŒæ¥µã‚ã¦çŸ­ãã€ã¾ãŸã€è¤‡æ•°ã®ãƒ—ロセスã§ãƒ¡ãƒ¢ãƒªãƒžãƒƒãƒ—を共有ã™ã‚‹ã“ã¨ãŒã§ãる。

+ +

ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ãŒæ ¼ç´ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã®åŠåˆ†ã»ã©ã§ã‚ã‚Œã°ã€ãƒ‡ãƒ¼ã‚¿ã®æ€§è³ªã«ã‚ˆã£ã¦å¤šå°‘å‰å¾Œã™ã‚‹ãŒã€ãƒãƒƒã‚·ãƒ¥å€¤ã®è¡çªçŽ‡ã¯56.7%ã»ã©ã§ã‚る(等å€ã ã¨36.8%ã€2å€ã ã¨21.3%ã€4å€ã ã¨11.5%ã€8å€ã ã¨6.0%ã»ã©ï¼‰ã€‚ãã®ã‚ˆã†ãªå ´åˆã€å¹³å‡2パス以下ã®ãƒ•ã‚¡ã‚¤ãƒ«æ“作ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’探索ã™ã‚‹ã“ã¨ãŒã§ãる。ã“れを性能指標ã¨ã™ã‚‹ãªã‚‰ã°ã€ä¾‹ãˆã°100万個ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã™ã‚‹ãŸã‚ã«ã¯50万è¦ç´ ã®ãƒã‚±ãƒƒãƒˆé…列ãŒæ±‚ã‚られる。ãƒã‚±ãƒƒãƒˆé…列ã®å„è¦ç´ ã¯4ãƒã‚¤ãƒˆã§ã‚る。ã™ãªã‚ã¡ã€2Mãƒã‚¤ãƒˆã®RAMãŒåˆ©ç”¨ã§ãã‚Œã°100万レコードã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãŒæ§‹ç¯‰ã§ãる。

+ +

QDBMã«ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æŽ¥ç¶šã™ã‚‹ãƒ¢ãƒ¼ãƒ‰ã¨ã—ã¦ã€ã€Œãƒªãƒ¼ãƒ€ã€ã¨ã€Œãƒ©ã‚¤ã‚¿ã€ã®äºŒç¨®é¡žãŒã‚る。リーダã¯èª­ã¿è¾¼ã¿å°‚用ã§ã‚ã‚Šã€ãƒ©ã‚¤ã‚¿ã¯èª­ã¿æ›¸ã両用ã§ã‚る。データベースã«ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãƒ­ãƒƒã‚¯ã«ã‚ˆã£ã¦ãƒ—ロセス間ã§ã®æŽ’他制御ãŒè¡Œã‚れる。ライタãŒæŽ¥ç¶šã—ã¦ã„ã‚‹é–“ã¯ã€ä»–ã®ãƒ—ロセスã¯ãƒªãƒ¼ãƒ€ã¨ã—ã¦ã‚‚ライタã¨ã—ã¦ã‚‚接続ã§ããªã„。リーダãŒæŽ¥ç¶šã—ã¦ã„ã‚‹é–“ã¯ã€ä»–ã®ãƒ—ロセスã®ãƒªãƒ¼ãƒ€ã¯æŽ¥ç¶šã§ãã‚‹ãŒã€ãƒ©ã‚¤ã‚¿ã¯æŽ¥ç¶šã§ããªã„。ã“ã®æ©Ÿæ§‹ã«ã‚ˆã£ã¦ã€ãƒžãƒ«ãƒã‚¿ã‚¹ã‚¯ç’°å¢ƒã§ã®åŒæ™‚接続ã«ä¼´ã†ãƒ‡ãƒ¼ã‚¿ã®æ•´åˆæ€§ãŒä¿è¨¼ã•ã‚Œã‚‹ã€‚

+ +

ä¼çµ±çš„ãªDBMã«ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®è¿½åŠ æ“作ã«é–¢ã—ã¦ã€ŒæŒ¿å…¥ã€ãƒ¢ãƒ¼ãƒ‰ã¨ã€Œç½®æ›ã€ãƒ¢ãƒ¼ãƒ‰ãŒã‚る。å‰è€…ã§ã¯ã€ã‚­ãƒ¼ãŒæ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨é‡è¤‡ã™ã‚‹éš›ã«æ—¢å­˜ã®å€¤ã‚’残ã™ã€‚後者ã§ã¯ã€ã‚­ãƒ¼ãŒæ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨é‡è¤‡ã—ãŸéš›ã«æ–°ã—ã„値ã«ç½®ãæ›ãˆã‚‹ã€‚QDBMã¯ãã®ï¼’ã¤ã«åŠ ãˆã¦ã€Œé€£çµã€ãƒ¢ãƒ¼ãƒ‰ãŒã‚る。既存ã®å€¤ã®æœ«å°¾ã«æŒ‡å®šã•ã‚ŒãŸå€¤ã‚’連çµã—ã¦æ ¼ç´ã™ã‚‹æ“作ã§ã‚る。レコードã®å€¤ã‚’é…列ã¨ã—ã¦æ‰±ã†å ´åˆã€è¦ç´ ã‚’追加ã™ã‚‹ã«ã¯é€£çµãƒ¢ãƒ¼ãƒ‰ãŒå½¹ã«ç«‹ã¤ã€‚ã¾ãŸã€DBMã§ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’å–り出ã™éš›ã«ã¯ãã®å…¨ã¦ã®é ˜åŸŸã‚’処ç†å¯¾è±¡ã«ã™ã‚‹ã—ã‹æ–¹æ³•ãŒãªã„ãŒã€QDBMã§ã¯å€¤ã®é ˜åŸŸã®ä¸€éƒ¨ã®ã¿ã‚’é¸æŠžã—ã¦å–り出ã™ã“ã¨ãŒã§ãる。レコードã®å€¤ã‚’é…列ã¨ã—ã¦æ‰±ã†å ´åˆã«ã¯ã“ã®æ©Ÿèƒ½ã‚‚å½¹ã«ç«‹ã¤ã€‚

+ +

一般的ã«ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ›´æ–°å‡¦ç†ã‚’続ã‘ã‚‹ã¨ãƒ•ã‚¡ã‚¤ãƒ«å†…ã®åˆ©ç”¨å¯èƒ½é ˜åŸŸã®æ–­ç‰‡åŒ–ãŒèµ·ãã€ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºãŒè‚¥å¤§åŒ–ã—ã¦ã—ã¾ã†ã€‚QDBMã¯éš£æŽ¥ã™ã‚‹ä¸è¦é ˜åŸŸã‚’連çµã—ã¦å†åˆ©ç”¨ã—ã€ã¾ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æœ€é©åŒ–機能を備ãˆã‚‹ã“ã¨ã«ã‚ˆã£ã¦ã“ã®å•é¡Œã«å¯¾å‡¦ã™ã‚‹ã€‚既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’より大ããªã‚µã‚¤ã‚ºã®å€¤ã«ä¸Šæ›¸ãã™ã‚‹å ´åˆã€ãã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é ˜åŸŸã‚’ファイル中ã®åˆ¥ã®ä½ç½®ã«ç§»å‹•ã•ã›ã‚‹å¿…è¦ãŒã‚る。ã“ã®å‡¦ç†ã®æ™‚間計算é‡ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚µã‚¤ã‚ºã«ä¾å­˜ã™ã‚‹ã®ã§ã€å€¤ã‚’æ‹¡å¼µã—ã¦ã„ãå ´åˆã«ã¯åŠ¹çŽ‡ãŒæ‚ªã„。ã—ã‹ã—ã€QDBMã¯ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã«ã‚ˆã£ã¦ã“ã®å•é¡Œã«å¯¾å‡¦ã™ã‚‹ã€‚増分ãŒãƒ‘ディングã«åŽã¾ã‚Œã°é ˜åŸŸã‚’移動ã•ã›ã‚‹å¿…è¦ã¯ãªã„。

+ +

多ãã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚·ã‚¹ãƒ†ãƒ ã§ã¯ã€2GBを越ãˆã‚‹ã‚µã‚¤ã‚ºã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚’扱ã†ã“ã¨ãŒã§ããªã„。ã“ã®å•é¡Œã«å¯¾å‡¦ã™ã‚‹ãŸã‚ã«ã€QDBMã¯è¤‡æ•°ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’å«ã‚€ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã‹ã‚‰ãªã‚‹ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†æ©Ÿèƒ½ã‚’æä¾›ã™ã‚‹ã€‚レコードをã©ã®ãƒ•ã‚¡ã‚¤ãƒ«ã«æ ¼ç´ã™ã‚‹ã‹ã¯ã‚­ãƒ¼ã«åˆ¥ã®ãƒãƒƒã‚·ãƒ¥é–¢æ•°ã‚’é©ç”¨ã™ã‚‹ã“ã¨ã«ã‚ˆã£ã¦æ±ºã‚られる。ã“ã®æ©Ÿèƒ½ã«ã‚ˆã£ã¦ã€ç†è«–çš„ã«ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®åˆè¨ˆã‚µã‚¤ã‚ºãŒ1TBã¾ã§ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’構築ã™ã‚‹ã“ã¨ãŒã§ãる。ã¾ãŸã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’複数ã®ãƒ‡ã‚£ã‚¹ã‚¯ã«æŒ¯ã‚Šåˆ†ã‘ã‚‹ã“ã¨ãŒã§ãã‚‹ãŸã‚ã€RAID-0(ストライピング)ã«è¦‹ã‚‰ã‚Œã‚‹ã‚ˆã†ãªæ›´æ–°æ“作ã®é«˜é€ŸåŒ–ãŒæœŸå¾…ã§ãる。NFS等を利用ã™ã‚Œã°è¤‡æ•°ã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚µãƒ¼ãƒã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’分散ã•ã›ã‚‹ã“ã¨ã‚‚ã§ãる。

+ +

便利ãªB+木データベースã®å®Ÿè£…

+ +

B+木データベースã¯ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚ˆã‚Šé…ã„ãŒã€ãƒ¦ãƒ¼ã‚¶ãŒå®šç¾©ã—ãŸé †åºã«åŸºã¥ã„ã¦å„レコードをå‚ç…§ã§ãã‚‹ã“ã¨ãŒç‰¹é•·ã§ã‚る。B+木ã¯è¤‡æ•°ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’整列ã•ã›ãŸçŠ¶æ…‹ã§è«–ç†çš„ãªãƒšãƒ¼ã‚¸ã«ã¾ã¨ã‚ã¦ç®¡ç†ã™ã‚‹ã€‚å„ページã«å¯¾ã—ã¦ã¯B木ã™ãªã‚ã¡å¤šé€²å¹³è¡¡æœ¨ã«ã‚ˆã£ã¦éšŽå±¤åŒ–ã•ã‚ŒãŸç–Žã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ãŒç¶­æŒã•ã‚Œã‚‹ã€‚ã—ãŸãŒã£ã¦ã€å„レコードã®æŽ¢ç´¢ç­‰ã«ã‹ã‹ã‚‹æ™‚間計算é‡ã¯ O(log n) ã§ã‚る。å„レコードを順番ã«å‚ç…§ã™ã‚‹ãŸã‚ã«ã‚«ãƒ¼ã‚½ãƒ«ãŒæä¾›ã•ã‚Œã‚‹ã€‚カーソルã®å ´æ‰€ã¯ã‚­ãƒ¼ã‚’指定ã—ã¦é£›ã°ã™ã“ã¨ãŒã§ãã€ã¾ãŸç¾åœ¨ã®å ´æ‰€ã‹ã‚‰æ¬¡ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«é€²ã‚ãŸã‚Šå‰ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«æˆ»ã—ãŸã‚Šã™ã‚‹ã“ã¨ãŒã§ãる。å„ページã¯åŒæ–¹å‘リンクリストã§ç·¨æˆã•ã‚Œã‚‹ã®ã§ã€ã‚«ãƒ¼ã‚½ãƒ«ã‚’å‰å¾Œã«ç§»å‹•ã•ã›ã‚‹æ™‚間計算é‡ã¯ O(1) ã§ã‚る。

+ +

B+木データベースã¯ä¸Šè¿°ã®ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’基盤ã¨ã—ã¦å®Ÿè£…ã•ã‚Œã‚‹ã€‚B+木ã®å„ページã¯ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã—ã¦è¨˜éŒ²ã•ã‚Œã‚‹ã®ã§ã€ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®è¨˜æ†¶ç®¡ç†ã®åŠ¹çŽ‡æ€§ã‚’継承ã—ã¦ã„る。B+木ã§ã¯å„レコードã®ãƒ˜ãƒƒãƒ€ãŒå°ã•ãã€å„ページã®ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã¯ãƒšãƒ¼ã‚¸ã‚µã‚¤ã‚ºã«å¿œã˜ã¦èª¿æ•´ã•ã‚Œã‚‹ã®ã§ã€ã»ã¨ã‚“ã©ã®å ´åˆã€ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«è¼ƒã¹ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºãŒåŠæ¸›ã™ã‚‹ã€‚B+木を更新ã™ã‚‹éš›ã«ã¯å¤šãã®ãƒšãƒ¼ã‚¸ã‚’æ“作ã™ã‚‹å¿…è¦ãŒã‚ã‚‹ãŒã€QDBMã¯ãƒšãƒ¼ã‚¸ã‚’キャッシュã™ã‚‹ã“ã¨ã«ã‚ˆã£ã¦ãƒ•ã‚¡ã‚¤ãƒ«æ“作を減らã—ã¦å‡¦ç†ã‚’効率化ã™ã‚‹ã€‚ã»ã¨ã‚“ã©ã®å ´åˆã€ç–Žã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹å…¨ä½“ãŒãƒ¡ãƒ¢ãƒªä¸Šã«ã‚­ãƒ£ãƒƒã‚·ãƒ¥ã•ã‚Œã‚‹ã®ã§ã€å„レコードをå‚ç…§ã™ã‚‹ã®ã«å¿…è¦ãªãƒ•ã‚¡ã‚¤ãƒ«æ“作ã¯å¹³å‡1パス以下ã§ã‚る。

+ +

B+木データベースã¯ãƒˆãƒ©ãƒ³ã‚¶ã‚¯ã‚·ãƒ§ãƒ³æ©Ÿæ§‹ã‚’æä¾›ã™ã‚‹ã€‚トランザクションを開始ã—ã¦ã‹ã‚‰çµ‚了ã™ã‚‹ã¾ã§ã®ä¸€é€£ã®æ“作を一括ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ã‚³ãƒŸãƒƒãƒˆã—ãŸã‚Šã€ä¸€é€£ã®æ›´æ–°æ“作を破棄ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®çŠ¶æ…‹ã‚’トランザクションã®é–‹å§‹å‰ã®çŠ¶æ…‹ã«ãƒ­ãƒ¼ãƒ«ãƒãƒƒã‚¯ã—ãŸã‚Šã™ã‚‹ã“ã¨ãŒã§ãる。トランザクションã®é–“ã«ã‚¢ãƒ—リケーションã®ãƒ—ロセスãŒã‚¯ãƒ©ãƒƒã‚·ãƒ¥ã—ã¦ã‚‚データベースファイルã¯ç ´å£Šã•ã‚Œãªã„。

+ +

å¯é€†ãƒ‡ãƒ¼ã‚¿åœ§ç¸®ãƒ©ã‚¤ãƒ–ラリã§ã‚ã‚‹ZLIBã‹LZOã‹BZIP2を有効化ã—ã¦QDBMをビルドã™ã‚‹ã¨ã€B+木ã®å„ページã®å†…容ã¯åœ§ç¸®ã•ã‚Œã¦ãƒ•ã‚¡ã‚¤ãƒ«ã«æ›¸ãè¾¼ã¾ã‚Œã‚‹ã€‚åŒä¸€ãƒšãƒ¼ã‚¸å†…ã®å„レコードã¯ä¼¼ãŸã‚ˆã†ãªãƒ‘ターンをæŒã¤ãŸã‚ã€Lempel-Zivãªã©ã®ã‚¢ãƒ«ã‚´ãƒªã‚ºãƒ ã‚’é©ç”¨ã™ã‚‹ã¨é«˜ã„圧縮効率ãŒæœŸå¾…ã§ãる。テキストデータを扱ã†å ´åˆã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ã‚µã‚¤ã‚ºãŒå…ƒã®25%程度ã«ãªã‚‹ã€‚データベースã®è¦æ¨¡ãŒå¤§ããディスクI/OãŒãƒœãƒˆãƒ«ãƒãƒƒã‚¯ã¨ãªã‚‹å ´åˆã¯ã€åœ§ç¸®æ©Ÿèƒ½ã‚’有効化ã™ã‚‹ã¨å‡¦ç†é€Ÿåº¦ãŒå¤§å¹…ã«æ”¹å–„ã•ã‚Œã‚‹ã€‚

+ +

å˜ç´”ã ãŒå¤šæ§˜ãªã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ç¾¤

+ +

QDBMã®APIã¯éžå¸¸ã«å˜ç´”ã§ã‚る。ANSI Cã§å®šç¾©ã•ã‚ŒãŸ `FILE' ãƒã‚¤ãƒ³ã‚¿ã‚’用ã„ãŸé€šå¸¸ã®ãƒ•ã‚¡ã‚¤ãƒ«å…¥å‡ºåŠ›ã¨åŒã˜ã‚ˆã†ã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã«å¯¾ã™ã‚‹å…¥å‡ºåŠ›ã‚’è¡Œã†ã“ã¨ãŒã§ãる。QDBMã®åŸºæœ¬APIã§ã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å®Ÿä½“ã¯å˜ä¸€ã®ãƒ•ã‚¡ã‚¤ãƒ«ã«è¨˜éŒ²ã•ã‚Œã‚‹ã€‚æ‹¡å¼µAPIã§ã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å®Ÿä½“ã¯å˜ä¸€ã®ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã«å«ã¾ã‚Œã‚‹è¤‡æ•°ã®ãƒ•ã‚¡ã‚¤ãƒ«ã«è¨˜éŒ²ã•ã‚Œã‚‹ã€‚二ã¤ã®APIã¯äº’ã„ã«é…·ä¼¼ã—ã¦ã„ã‚‹ã®ã§ã€ã‚¢ãƒ—リケーションを一方ã‹ã‚‰ä»–æ–¹ã«ç§»æ¤ã™ã‚‹ã“ã¨ã¯ãŸã‚„ã™ã„。

+ +

NDBMãŠã‚ˆã³GDBMã«äº’æ›ã™ã‚‹APIã‚‚æä¾›ã•ã‚Œã‚‹ã€‚NDBMã‚„GDBMã®ã‚¢ãƒ—リケーションã¯å¸‚å ´ã«æ•°å¤šã存在ã™ã‚‹ãŒã€ãれらをQDBMã«ç§»æ¤ã™ã‚‹ã®ã¯ãŸã‚„ã™ã„。ã»ã¨ã‚“ã©ã®å ´åˆã€ãƒ˜ãƒƒãƒ€ãƒ•ã‚¡ã‚¤ãƒ«ã®å–ã‚Šè¾¼ã¿ï¼ˆ#include)を書ãæ›ãˆã¦ã‚³ãƒ³ãƒ‘イルã—ãªãŠã›ã°ã‚ˆã„。ãŸã ã—ã€ã‚ªãƒªã‚¸ãƒŠãƒ«ã®NDBMã‚„GDBMã§ä½œæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’QDBMã§æ‰±ã†ã“ã¨ã¯ã§ããªã„。

+ +

メモリ上ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’ç°¡å˜ã«æ‰±ã†ãŸã‚ã«ã€ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£APIãŒæä¾›ã•ã‚Œã‚‹ã€‚メモリ確ä¿é–¢æ•°ã¨ã‚½ãƒ¼ãƒˆé–¢æ•°ã¨æ‹¡å¼µå¯èƒ½ãªãƒ‡ãƒ¼ã‚¿ã¨é…列リストã¨ãƒãƒƒã‚·ãƒ¥ãƒžãƒƒãƒ—ç­‰ã®å®Ÿè£…ã§ã‚る。ãれらを用ã„ã‚‹ã¨ã€C言語ã§ã‚‚Perlã‚„Rubyç­‰ã®ã‚¹ã‚¯ãƒªãƒ—ト言語ã®ã‚ˆã†ãªæ‰‹è»½ã•ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’扱ã†ã“ã¨ãŒã§ãる。

+ +

B+木データベースã¯ä¸Šç´šAPIを介ã—ã¦åˆ©ç”¨ã™ã‚‹ã€‚上級APIã¯åŸºæœ¬APIã¨ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£APIを利用ã—ã¦å®Ÿè£…ã•ã‚Œã‚‹ã€‚上級APIも基本APIã‚„æ‹¡å¼µAPIã«é¡žä¼¼ã—ãŸæ›¸å¼ã‚’æŒã¤ã®ã§ã€ä½¿ã„方を覚ãˆã‚‹ã®ã¯å®¹æ˜“ã§ã‚る。

+ +

全文検索システムã§åˆ©ç”¨ã•ã‚Œã‚‹è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’扱ã†ãŸã‚ã«ã€è»¢ç½®APIãŒæä¾›ã•ã‚Œã‚‹ã€‚文書群ã®è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’容易ã«æ‰±ã†ã“ã¨ãŒã§ãã‚Œã°ã€ã‚¢ãƒ—リケーションã¯ãƒ†ã‚­ã‚¹ãƒˆå‡¦ç†ã‚„自然言語処ç†ã«æ³¨åŠ›ã§ãる。ã“ã®APIã¯æ–‡å­—コードや言語ã«ä¾å­˜ã—ãªã„ã®ã§ã€ãƒ¦ãƒ¼ã‚¶ã®å¤šæ§˜ãªè¦æ±‚ã«å¿œãˆã‚‹å…¨æ–‡æ¤œç´¢ã‚·ã‚¹ãƒ†ãƒ ã‚’実装ã™ã‚‹ã“ã¨ãŒå¯èƒ½ã¨ãªã‚‹ã€‚

+ +

QDBMã¯C言語ã®ä»–ã«ã‚‚ã€C++ã€Javaã€PerlãŠã‚ˆã³Rubyã®APIã‚’æä¾›ã™ã‚‹ã€‚C言語ã®APIã«ã¯ã€åŸºæœ¬APIã€æ‹¡å¼µAPIã€NDBM互æ›APIã€GDBM互æ›APIã€ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£APIã€ä¸Šç´šAPIãŠã‚ˆã³è»¢ç½®APIã®ä¸ƒç¨®é¡žãŒã‚る。å„APIã«å¯¾å¿œã—ãŸã‚³ãƒžãƒ³ãƒ‰ãƒ©ã‚¤ãƒ³ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ã‚‚用æ„ã•ã‚Œã¦ã„る。ãれらã¯ãƒ—ロトタイピングやテストやデãƒãƒƒã‚°ãªã©ã§æ´»èºã™ã‚‹ã€‚C++用APIã¯åŸºæœ¬APIã¨æ‹¡å¼µAPIã¨ä¸Šç´šAPIã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹æ“作関数群をC++ã®ã‚¯ãƒ©ã‚¹æ©Ÿæ§‹ã§ã‚«ãƒ—セル化ã—ãŸã‚‚ã®ã§ã‚る。Java用APIã¯Java Native Interfaceを用ã„ã¦åŸºæœ¬APIã¨æ‹¡å¼µAPIã¨ä¸Šç´šAPIを呼ã³å‡ºã™ã‚‚ã®ã§ã‚る。Perl用APIã¯XS言語を用ã„ã¦åŸºæœ¬APIã¨æ‹¡å¼µAPIã¨ä¸Šç´šAPIを呼ã³å‡ºã™ã‚‚ã®ã§ã‚る。Ruby用APIã¯Rubyã®ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ã¨ã—ã¦åŸºæœ¬APIã¨æ‹¡å¼µAPIã¨ä¸Šç´šAPIを呼ã³å‡ºã™ã‚‚ã®ã§ã‚る。データベースã®ç®¡ç†ã¨ãƒ•ã‚¡ã‚¤ãƒ«ã‚¢ãƒƒãƒ—ロードã¨å…¨æ–‡æ¤œç´¢ã®ãŸã‚ã®CGIスクリプトもæä¾›ã•ã‚Œã‚‹ã€‚

+ +

幅広ã„移æ¤æ€§

+ +

QDBMã¯ANSI C(C89)ã®è¨˜æ³•ã«å¾“ã„ã€ANSI Cã¾ãŸã¯POSIXã§å®šç¾©ã•ã‚ŒãŸAPIã®ã¿ã‚’用ã„ã¦å®Ÿè£…ã•ã‚Œã‚‹ã€‚ã—ãŸãŒã£ã¦ã€ã»ã¨ã‚“ã©ã®UNIXãŠã‚ˆã³ãã®äº’æ›ã‚’ã†ãŸã†OSã§å‹•ä½œã•ã›ã‚‹ã“ã¨ãŒã§ãる。C言語ã®APIã«é–¢ã—ã¦ã¯ã€å°‘ãªãã¨ã‚‚以下ã®ãƒ—ラットフォームã§å‹•ä½œç¢ºèªã•ã‚Œã¦ã„る。

+ +
    +
  • Linux (2.2, 2.4, 2.6) (IA32, IA64, AMD64, PA-RISC, Alpha, PowerPC, M68000, ARM)
  • +
  • FreeBSD (4.9, 5.0, 5.1, 5.2, 5.3) (IA32, IA64, SPARC, Alpha)
  • +
  • NetBSD (1.6) (IA32)
  • +
  • OpenBSD (3.4) (IA32)
  • +
  • SunOS (5.6, 5.7, 5.8, 5.9, 5.10) (IA32, SPARC)
  • +
  • HP-UX (11.11, 11.23) (IA64, PA-RISC)
  • +
  • AIX (5.2) (POWER)
  • +
  • Windows (2000, XP) (IA32, IA64, AMD64) (Cygwin, MinGW, Visual C++)
  • +
  • Mac OS X (10.2, 10.3, 10.4) (IA32, PowerPC)
  • +
  • Tru64 (5.1) (Alpha)
  • +
  • RISC OS (5.03) (ARM)
  • +
+ +

QDBMãŒä½œæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã¯å‡¦ç†ç³»ã®ãƒã‚¤ãƒˆã‚ªãƒ¼ãƒ€ã«ä¾å­˜ã™ã‚‹ãŒã€ãã®å¯¾ç­–ã¨ã—ã¦ã€ãƒã‚¤ãƒˆã‚ªãƒ¼ãƒ€ã«ä¾å­˜ã—ãªã„å½¢å¼ã®ãƒ‡ãƒ¼ã‚¿ã‚’ダンプã™ã‚‹ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£ãŒæä¾›ã•ã‚Œã‚‹ã€‚

+ +
+ +

インストール

+ +

準備

+ +

ソースパッケージを用ã„ã¦QDBMをインストールã™ã‚‹ã«ã¯ã€GCCã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³2.8以é™ã¨ `make' ãŒå¿…è¦ã§ã‚る。

+ +

QDBMã®é…布用アーカイブファイルを展開ã—ãŸã‚‰ã€ç”Ÿæˆã•ã‚ŒãŸãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã«å…¥ã£ã¦ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ä½œæ¥­ã‚’è¡Œã†ã€‚

+ +

普通ã®æ‰‹é †

+ +

Linuxã¨BSDã¨SunOSã§ã¯ä»¥ä¸‹ã®æ‰‹é †ã«å¾“ã†ã€‚

+ +

ビルド環境を設定ã™ã‚‹ã€‚

+ +
./configure
+
+ +

プログラムをビルドã™ã‚‹ã€‚

+ +
make
+
+ +

プログラムã®è‡ªå·±è¨ºæ–­ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚

+ +
make check
+
+ +

プログラムをインストールã™ã‚‹ã€‚作業㯠`root' ユーザã§è¡Œã†ã€‚

+ +
make install
+
+ +

GNU Libtoolを使ã†å ´åˆ

+ +

上記ã®æ–¹æ³•ã§ã†ã¾ãã„ã‹ãªã„å ´åˆã€ä»¥ä¸‹ã®æ‰‹é †ã«å¾“ã†ã€‚ã“ã®æ‰‹é †ã«ã¯ã€GNU Libtoolã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³1.5以é™ãŒå¿…è¦ã§ã‚る。

+ +

ビルド環境を設定ã™ã‚‹ã€‚

+ +
./configure
+
+ +

プログラムをビルドã™ã‚‹ã€‚

+ +
make -f LTmakefile
+
+ +

プログラムã®è‡ªå·±è¨ºæ–­ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚

+ +
make -f LTmakefile check
+
+ +

プログラムをインストールã™ã‚‹ã€‚作業㯠`root' ユーザã§è¡Œã†ã€‚

+ +
make -f LTmakefile install
+
+ +

çµæžœ

+ +

一連ã®ä½œæ¥­ãŒçµ‚ã‚‹ã¨ã€ä»¥ä¸‹ã®ãƒ•ã‚¡ã‚¤ãƒ«ãŒã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã•ã‚Œã‚‹ã€‚ãã®ä»–ã«ã‚‚ã€ãƒžãƒ‹ãƒ¥ã‚¢ãƒ«ãŒ `/usr/local/man/man1' 㨠`/usr/local/man/man3' ã«ã€ãれ以外ã®æ–‡æ›¸ãŒ `/usr/local/share/qdbm' ã«ã€`pkg-config' 用ã®è¨­å®šãƒ•ã‚¡ã‚¤ãƒ«ãŒ `/usr/local/lib/pkgconfig' ã«ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã•ã‚Œã‚‹ã€‚

+ +
/usr/local/include/depot.h
+/usr/local/include/curia.h
+/usr/local/include/relic.h
+/usr/local/include/hovel.h
+/usr/local/include/cabin.h
+/usr/local/include/villa.h
+/usr/local/include/vista.h
+/usr/local/include/odeum.h
+/usr/local/lib/libqdbm.a
+/usr/local/lib/libqdbm.so.14.13.0
+/usr/local/lib/libqdbm.so.14
+/usr/local/lib/libqdbm.so
+/usr/local/bin/dpmgr
+/usr/local/bin/dptest
+/usr/local/bin/dptsv
+/usr/local/bin/crmgr
+/usr/local/bin/crtest
+/usr/local/bin/crtsv
+/usr/local/bin/rlmgr
+/usr/local/bin/rltest
+/usr/local/bin/hvmgr
+/usr/local/bin/hvtest
+/usr/local/bin/cbtest
+/usr/local/bin/cbcodec
+/usr/local/bin/vlmgr
+/usr/local/bin/vltest
+/usr/local/bin/vltsv
+/usr/local/bin/odmgr
+/usr/local/bin/odtest
+/usr/local/bin/odidx
+/usr/local/bin/qmttest
+
+ +

`libqdbm.so' ã¨å‹•çš„ã«ãƒªãƒ³ã‚¯ã—ãŸãƒ—ログラムを実行ã™ã‚‹éš›ã«ã¯ã€ãƒ©ã‚¤ãƒ–ラリã®æ¤œç´¢ãƒ‘ス㫠`/usr/local/lib' ã‚’å«ã‚ã‚‹ã¹ãã§ã‚る。環境変数 `LD_LIBRARY_PATH' ã§ãƒ©ã‚¤ãƒ–ラリã®æ¤œç´¢ãƒ‘スを設定ã™ã‚‹ã“ã¨ãŒã§ãる。

+ +

QDBMをアンインストールã™ã‚‹ã«ã¯ã€`./configure' ã‚’ã—ãŸå¾Œã®çŠ¶æ…‹ã§ä»¥ä¸‹ã®ã‚³ãƒžãƒ³ãƒ‰ã‚’実行ã™ã‚‹ã€‚作業㯠`root' ユーザã§è¡Œã†ã€‚

+ +
make uninstall
+
+ +

QDBMã®å¤ã„ãƒãƒ¼ã‚¸ãƒ§ãƒ³ãŒã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã•ã‚Œã¦ã„ã‚‹å ´åˆã€ãれをアンインストールã—ã¦ã‹ã‚‰ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ä½œæ¥­ã‚’è¡Œã†ã¹ãã§ã‚る。

+ +

C言語以外ã®APIã¨CGIスクリプトã¯ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã§ã¯ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã•ã‚Œãªã„。C++用APIã®ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«æ–¹æ³•ã«ã¤ã„ã¦ã¯ã€ã‚µãƒ–ディレクトリ `plus' ã«ã‚ã‚‹ `xspex-ja.html' ã‚’å‚ç…§ã™ã‚‹ã“ã¨ã€‚JAVA用APIã®ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«æ–¹æ³•ã«ã¤ã„ã¦ã¯ã€ã‚µãƒ–ディレクトリ `java' ã«ã‚ã‚‹ `jspex-ja.html' ã‚’å‚ç…§ã™ã‚‹ã“ã¨ã€‚Perl用APIã®ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«æ–¹æ³•ã«ã¤ã„ã¦ã¯ã€ã‚µãƒ–ディレクトリ `perl' ã«ã‚ã‚‹ `plspex-ja.html' ã‚’å‚ç…§ã™ã‚‹ã“ã¨ã€‚Ruby用APIã®ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«æ–¹æ³•ã«ã¤ã„ã¦ã¯ã€ã‚µãƒ–ディレクトリ `ruby' ã«ã‚ã‚‹ `rbspex-ja.html' ã‚’å‚ç…§ã™ã‚‹ã“ã¨ã€‚CGIスクリプトã®ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«æ–¹æ³•ã«ã¤ã„ã¦ã¯ã€ã‚µãƒ–ディレクトリ `cgi' ã«ã‚ã‚‹ `cgispex.html' ã‚’å‚ç…§ã™ã‚‹ã“ã¨ã€‚

+ +

RPMç­‰ã®ãƒã‚¤ãƒŠãƒªãƒ‘ッケージを用ã„ã¦ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã‚’è¡Œã†å ´åˆã¯ã€ãã‚Œãžã‚Œã®ãƒ‘ッケージマãƒãƒ¼ã‚¸ãƒ£ã®ãƒžãƒ‹ãƒ¥ã‚¢ãƒ«ã‚’å‚ç…§ã™ã‚‹ã“ã¨ã€‚例ãˆã°ã€RPMを用ã„ã‚‹å ´åˆã€ä»¥ä¸‹ã®ã‚ˆã†ãªã‚³ãƒžãƒ³ãƒ‰ã‚’ `root' ユーザã§å®Ÿè¡Œã™ã‚‹ã€‚

+ +
rpm -ivh qdbm-1.x.x-x.i386.rpm
+
+ +

Windowsã®å ´åˆ

+ +

Windows(Cygwin)ã«ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã™ã‚‹å ´åˆã€ä»¥ä¸‹ã®æ‰‹é †ã«å¾“ã†ã€‚

+ +

ビルド環境を設定ã™ã‚‹ã€‚

+ +
./configure
+
+ +

プログラムをビルドã™ã‚‹ã€‚

+ +
make win
+
+ +

プログラムã®è‡ªå·±è¨ºæ–­ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚

+ +
make check-win
+
+ +

プログラムをインストールã™ã‚‹ã€‚ãªãŠã€ã‚¢ãƒ³ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã™ã‚‹å ´åˆã¯ `make uninstall-win' ã¨ã™ã‚‹ã€‚

+ +
make install-win
+
+ +

Windowsã§ã¯ã€é™çš„ライブラリ `libqdbm.a' ã«åŠ ãˆã¦ã‚¤ãƒ³ãƒãƒ¼ãƒˆãƒ©ã‚¤ãƒ–ラリ `libqdbm.dll.a' ãŒç”Ÿæˆã•ã‚Œã€å‹•çš„ライブラリ `libqdbm.so' ç­‰ã®ä»£ã‚ã‚Šã«ãƒ€ã‚¤ãƒŠãƒŸãƒƒã‚¯ãƒªãƒ³ã‚¯ãƒ©ã‚¤ãƒ–ラリ `qdbm.dll' ãŒç”Ÿæˆã•ã‚Œã‚‹ã€‚`qdbm.dll' 㯠`/usr/local/bin' ã«ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã•ã‚Œã‚‹ã€‚

+ +

Cygwin環境ã§MinGWを用ã„ã¦ãƒ“ルドã™ã‚‹ã«ã¯ã€`make win' ã®ä»£ã‚ã‚Šã« `make mingw' を用ã„る。Cygwinã®UNIXエミュレーション層を用ã„ã‚‹å ´åˆã€ç”Ÿæˆã•ã‚Œã‚‹ãƒ—ログラム㯠`cygwin1.dll' ã«ä¾å­˜ã—ãŸã‚‚ã®ã«ãªã‚‹ï¼ˆGNU GPLã®å½±éŸ¿ã‚’å—ã‘る)。MinGWã«ã‚ˆã£ã¦Win32ã®ãƒã‚¤ãƒ†ã‚£ãƒ–DLLã¨ãƒªãƒ³ã‚¯ã•ã›ã‚Œã°ã“ã®å•é¡Œã‚’回é¿ã§ãる。

+ +

Visual C++を用ã„ã¦ãƒ“ルドã™ã‚‹ã«ã¯ã€`VCmakefile' を編集ã—ã¦ãƒ˜ãƒƒãƒ€ã¨ãƒ©ã‚¤ãƒ–ラリã®æ¤œç´¢ãƒ‘スを設定ã—ãŸä¸Šã§ã€`nmake /f VCMakefile' ã¨ã™ã‚Œã°ã‚ˆã„。生æˆã•ã‚ŒãŸ `qdbm.dll' ã¨ãƒªãƒ³ã‚¯ã™ã‚‹ã‚¢ãƒ—リケーションã¯ã€ã‚³ãƒ³ãƒ‘イラ㮠`/MD' ã¾ãŸã¯ `/MDd' オプションを用ã„㦠`msvcrt.dll' ã¨ãƒªãƒ³ã‚¯ã•ã›ã‚‹å¿…è¦ãŒã‚る。詳細設定ã«é–¢ã—ã¦ã¯ `VCmakefile' ã‚’å‚ç…§ã®ã“ã¨ã€‚

+ +

Mac OS Xã®å ´åˆ

+ +

Mac OS X(Darwin)ã«ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã™ã‚‹å ´åˆã€ä»¥ä¸‹ã®æ‰‹é †ã«å¾“ã†ã€‚

+ +

ビルド環境を設定ã™ã‚‹ã€‚

+ +
./configure
+
+ +

プログラムをビルドã™ã‚‹ã€‚

+ +
make mac
+
+ +

プログラムã®è‡ªå·±è¨ºæ–­ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚

+ +
make check-mac
+
+ +

プログラムをインストールã™ã‚‹ã€‚ãªãŠã€ã‚¢ãƒ³ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã™ã‚‹å ´åˆã¯ `make uninstall-mac' ã¨ã™ã‚‹ã€‚

+ +
make install-mac
+
+ +

Mac OS Xã§ã¯ã€`libqdbm.so' ç­‰ã®ä»£ã‚ã‚Šã« `libqdbm.dylib' ç­‰ãŒç”Ÿæˆã•ã‚Œã‚‹ã€‚ライブラリã®æ¤œç´¢ãƒ‘スã®æŒ‡å®šã¯ç’°å¢ƒå¤‰æ•° `DYLD_LIBRARY_PATH' ã§è¡Œã†ã“ã¨ãŒã§ãる。

+ +

HP-UXã®å ´åˆ

+ +

HP-UXã«ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã™ã‚‹å ´åˆã€ä»¥ä¸‹ã®æ‰‹é †ã«å¾“ã†ã€‚

+ +

ビルド環境を設定ã™ã‚‹ã€‚

+ +
./configure
+
+ +

プログラムをビルドã™ã‚‹ã€‚

+ +
make hpux
+
+ +

プログラムã®è‡ªå·±è¨ºæ–­ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚

+ +
make check-hpux
+
+ +

プログラムをインストールã™ã‚‹ã€‚ãªãŠã€ã‚¢ãƒ³ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã™ã‚‹å ´åˆã¯ `make uninstall-hpux' ã¨ã™ã‚‹ã€‚

+ +
make install-hpux
+
+ +

HP-UXã§ã¯ã€`libqdbm.so' ç­‰ã®ä»£ã‚ã‚Šã« `libqdbm.sl' ãŒç”Ÿæˆã•ã‚Œã‚‹ã€‚ライブラリã®æ¤œç´¢ãƒ‘スã®æŒ‡å®šã¯ç’°å¢ƒå¤‰æ•° `SHLIB_PATH' ã§è¡Œã†ã“ã¨ãŒã§ãる。

+ +

RISC OSã®å ´åˆ

+ +

RISC OSã«ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã™ã‚‹å ´åˆã€ä»¥ä¸‹ã®æ‰‹é †ã«å¾“ã†ã€‚

+ +

プログラムをビルドã™ã‚‹ã€‚デフォルトã§ã¯ã‚³ãƒ³ãƒ‘イラ㫠`cc' を用ã„るよã†ã«ãªã£ã¦ã„ã‚‹ãŒã€`gcc' を用ã„ãŸã‘れ㰠`CC=gcc' ã¨ã„ã†å¼•æ•°ã‚’加ãˆã‚Œã°ã‚ˆã„。

+ +
make -f RISCmakefile
+
+ +

一連ã®ä½œæ¥­ãŒçµ‚ã‚‹ã¨ã€`libqdbm' ã¨ã„ã†ãƒ©ã‚¤ãƒ–ラリファイル㨠`dpmgr' ç­‰ã®ã‚³ãƒžãƒ³ãƒ‰ãŒç”Ÿæˆã•ã‚Œã‚‹ã€‚ãれらã®ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«æ–¹æ³•ã¯å®šç¾©ã•ã‚Œã¦ã„ãªã„ã®ã§ã€æ‰‹å‹•ã§ä»»æ„ã®å ´æ‰€ã«ã‚³ãƒ”ーã—ã¦ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã™ã‚‹ã“ã¨ã€‚`depot.h' ç­‰ã®ãƒ˜ãƒƒãƒ€ãƒ•ã‚¡ã‚¤ãƒ«ã‚‚åŒæ§˜ã«æ‰‹å‹•ã§ã‚¤ãƒ³ã‚¹ãƒˆãƒ¼ãƒ«ã™ã‚‹ã“ã¨ã€‚

+ +

詳細設定

+ +

`./configure' を実行ã™ã‚‹éš›ã«ä»¥ä¸‹ã®ã‚ªãƒ—ション引数を指定ã™ã‚‹ã“ã¨ã§ã€ãƒ“ルド方法ã®è©³ç´°ãªè¨­å®šã‚’è¡Œã†ã“ã¨ãŒã§ãる。

+ +
    +
  • --enable-debug : デãƒãƒƒã‚°ç”¨ã«ãƒ“ルドã™ã‚‹ã€‚デãƒãƒƒã‚°ã‚·ãƒ³ãƒœãƒ«ã‚’有効化ã—ã€æœ€é©åŒ–ã‚’è¡Œã‚ãšã€é™çš„ã«ãƒªãƒ³ã‚¯ã™ã‚‹ã€‚
  • +
  • --enable-devel : 開発用ã«ãƒ“ルドã™ã‚‹ã€‚デãƒãƒƒã‚°ã‚·ãƒ³ãƒœãƒ«ã‚’有効化ã—ã€æœ€é©åŒ–ã‚’è¡Œã„ã€å‹•çš„ã«ãƒªãƒ³ã‚¯ã™ã‚‹ã€‚
  • +
  • --enable-stable : 安定版ã®ãƒªãƒªãƒ¼ã‚¹ç”¨ã«ãƒ“ルドã™ã‚‹ã€‚ä¿å®ˆçš„ãªæœ€é©åŒ–ã‚’è¡Œã„ã€å‹•çš„ã«ãƒªãƒ³ã‚¯ã™ã‚‹ã€‚
  • +
  • --enable-pthread : POSIXスレッドを用ã„ã€ã‚°ãƒ­ãƒ¼ãƒãƒ«å¤‰æ•°ã‚’スレッド固有データã¨ã—ã¦æ‰±ã†ã€‚
  • +
  • --disable-lock : ファイルロッキングãŒå®Ÿè£…ã•ã‚Œã¦ã„ãªã„環境用ã«ãƒ“ルドã™ã‚‹ã€‚
  • +
  • --disable-mmap : メモリマッピングãŒå®Ÿè£…ã•ã‚Œã¦ã„ãªã„環境用ã«ãƒ“ルドã™ã‚‹ã€‚
  • +
  • --enable-zlib : ZLIBã«ã‚ˆã‚‹B+木ã¨è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®ãƒ¬ã‚³ãƒ¼ãƒ‰åœ§ç¸®ã‚’機能ã•ã›ã‚‹ã€‚
  • +
  • --enable-lzo : LZOã«ã‚ˆã‚‹B+木ã¨è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®ãƒ¬ã‚³ãƒ¼ãƒ‰åœ§ç¸®ã‚’機能ã•ã›ã‚‹ã€‚
  • +
  • --enable-bzip : BZIP2ã«ã‚ˆã‚‹B+木ã¨è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®ãƒ¬ã‚³ãƒ¼ãƒ‰åœ§ç¸®ã‚’機能ã•ã›ã‚‹ã€‚
  • +
  • --enable-iconv : ICONVã«ã‚ˆã‚‹æ–‡å­—コード変æ›ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£ã‚’機能ã•ã›ã‚‹ã€‚
  • +
+ +

通常ã€QDBMã¨ãã®ã‚¢ãƒ—リケーション㯠`libqdbm.*' 以外ã®éžæ¨™æº–ã®ãƒ©ã‚¤ãƒ–ラリã«ã¯ä¾å­˜ã—ãªã„ã§ãƒ“ルドã™ã‚‹ã“ã¨ãŒã§ãる。ãŸã ã—ã€POSIXスレッドを有効ã«ã—ãŸå ´åˆã¯ `libpthread.*' ã«ä¾å­˜ã—ã€ZLIBを有効ã«ã—ãŸå ´åˆã¯ `libz.*' ã«ä¾å­˜ã—ã€LZOを有効ã«ã—ãŸå ´åˆã¯ `liblzo2.*' ã«ä¾å­˜ã—ã€BZIP2を有効ã«ã—ãŸå ´åˆã¯ `libbz2.*' ã«ä¾å­˜ã—ã€ICONVを有効ã«ã—ãŸå ´åˆã¯ `libiconv.*' ã«ä¾å­˜ã™ã‚‹ã‚ˆã†ã«ãªã‚‹ã€‚

+ +

LZOã®ãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã¯GNU GPLãªã®ã§ã€`liblzo2.*' ã¨ãƒªãƒ³ã‚¯ã—ãŸã‚¢ãƒ—リケーションã¯GNU GPLã®åˆ¶ç´„ã‚’å—ã‘ã‚‹ã“ã¨ã«æ³¨æ„ã™ã‚‹ã“ã¨ã€‚

+ +
+ +

Depot: 基本API

+ +

概è¦

+ +

Depotã¯QDBMã®åŸºæœ¬APIã§ã‚る。QDBMãŒæä¾›ã™ã‚‹ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ç®¡ç†æ©Ÿèƒ½ã®ã»ã¼å…¨ã¦ãŒDepotã«ã‚ˆã£ã¦å®Ÿè£…ã•ã‚Œã‚‹ã€‚ãã®ä»–ã®APIã¯Depotã®ãƒ©ãƒƒãƒ‘ーã«ã™ãŽãªã„。ã—ãŸãŒã£ã¦ã€QDBMã®APIã®ä¸­ã§DepotãŒæœ€ã‚‚高速ã«å‹•ä½œã™ã‚‹ã€‚

+ +

Depotを使ã†ãŸã‚ã«ã¯ã€`depot.h' 㨠`stdlib.h' をインクルードã™ã¹ãã§ã‚る。通常ã€ã‚½ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®å†’頭付近ã§ä»¥ä¸‹ã®è¨˜è¿°ã‚’è¡Œã†ã€‚

+ +
+
#include <depot.h>
+
#include <stdlib.h>
+
+ +

Depotã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†éš›ã«ã¯ã€`DEPOT' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。ã“ã‚Œã¯ã€`stdio.h' ã®å„種ルーãƒãƒ³ãŒãƒ•ã‚¡ã‚¤ãƒ«å…¥å‡ºåŠ›ã« `FILE' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’用ã„ã‚‹ã®ã«ä¼¼ã¦ã„る。ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `dpopen' ã§é–‹ãã€é–¢æ•° `dpclose' ã§é–‰ã˜ã‚‹ã€‚ãƒãƒ³ãƒ‰ãƒ«ã®ãƒ¡ãƒ³ãƒã‚’直接å‚ç…§ã™ã‚‹ã“ã¨ã¯æŽ¨å¥¨ã•ã‚Œãªã„。データベースã«è‡´å‘½çš„ãªã‚¨ãƒ©ãƒ¼ãŒèµ·ããŸå ´åˆã¯ã€ä»¥å¾Œãã®ãƒãƒ³ãƒ‰ãƒ«ã«å¯¾ã™ã‚‹ `dpclose' を除ãå…¨ã¦ã®æ“作ã¯ä½•ã‚‚ã›ãšã«ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã™ã€‚ã²ã¨ã¤ã®ãƒ—ロセスã§è¤‡æ•°ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’åŒæ™‚ã«åˆ©ç”¨ã™ã‚‹ã“ã¨ã¯å¯èƒ½ã§ã‚ã‚‹ãŒã€åŒã˜ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®è¤‡æ•°ã®ãƒãƒ³ãƒ‰ãƒ«ã‚’利用ã—ã¦ã¯ãªã‚‰ãªã„。

+ +

API

+ +

外部変数 `dpversion' ã¯ãƒãƒ¼ã‚¸ãƒ§ãƒ³æƒ…å ±ã®æ–‡å­—列ã§ã‚る。

+ +
+
extern const char *dpversion;
+
ã“ã®å¤‰æ•°ã®æŒ‡ã™é ˜åŸŸã¯æ›¸ãè¾¼ã¿ç¦æ­¢ã§ã‚る。
+
+ +

外部変数 `dpecode' ã«ã¯ç›´å‰ã®ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ãŒè¨˜éŒ²ã•ã‚Œã‚‹ã€‚エラーコードã®è©³ç´°ã«ã¤ã„ã¦ã¯ `depot.h' ã‚’å‚ç…§ã™ã‚‹ã“ã¨ã€‚

+ +
+
extern int dpecode;
+
ã“ã®å¤‰æ•°ã®åˆæœŸå€¤ã¯ `DP_ENOERR' ã§ã‚る。ãã®ä»–ã®å€¤ã¨ã—ã¦ã€`DP_EFATAL'ã€`DP_EMODE'ã€`DP_EBROKEN'ã€`DP_EKEEP'ã€`DP_ENOITEM'ã€`DP_EALLOC'ã€`DP_EMAP'ã€`DP_EOPEN'ã€`DP_ECLOSE'ã€`DP_ETRUNC'ã€`DP_ESYNC'ã€`DP_ESTAT'ã€`DP_ESEEK'ã€`DP_EREAD'ã€`DP_EWRITE'ã€`DP_ELOCK'ã€`DP_EUNLINK'ã€`DP_EMKDIR'ã€`DP_ERMDIR' ãŠã‚ˆã³ `DP_EMISC' ãŒã‚る。
+
+ +

エラーコードã«å¯¾å¿œã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸æ–‡å­—列を得るã«ã¯ã€é–¢æ•° `dperrmsg' を用ã„る。

+ +
+
const char *dperrmsg(int ecode);
+
`ecode' ã¯ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ã‚¨ãƒ©ãƒ¼ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã®æ–‡å­—列ã§ã‚ã‚Šã€ãã®é ˜åŸŸã¯æ›¸ãè¾¼ã¿ç¦æ­¢ã§ã‚る。
+
+ +

データベースã®ãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `dpopen' を用ã„る。

+ +
+
DEPOT *dpopen(const char *name, int omode, int bnum);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚`omode' ã¯æŽ¥ç¶šãƒ¢ãƒ¼ãƒ‰ã‚’指定ã—ã€`DP_OREADER' ãªã‚‰ãƒªãƒ¼ãƒ€ã€`DP_OWRITER' ãªã‚‰ãƒ©ã‚¤ã‚¿ã¨ãªã‚‹ã€‚`DP_OWRITER' ã®å ´åˆã€`DP_OCREAT' ã¾ãŸã¯ `DP_OTRUNC' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãる。`DP_OCREAT' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãŒç„¡ã„å ´åˆã«æ–°è¦ä½œæˆã™ã‚‹ã“ã¨ã‚’指示ã—ã€`DP_OTRUNC' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãŒå­˜åœ¨ã—ã¦ã‚‚作り直ã™ã“ã¨ã‚’指示ã™ã‚‹ã€‚`DP_OREADER' 㨠`DP_OWRITER' ã®ä¸¡æ–¹ã§ `DP_ONOLCK' ã¾ãŸã¯ `DP_OLCKNB' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ãŒã€å‰è€…ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãƒ­ãƒƒã‚¯ã‚’ã‹ã‘ãšã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ãã“ã¨ã‚’指示ã—ã€å¾Œè€…ã¯ãƒ–ロックã›ãšã«ãƒ­ãƒƒã‚¯ã‚’ã‹ã‘ã‚‹ã“ã¨ã‚’指示ã™ã‚‹ã€‚`DP_OCREAT' 㯠`DP_OSPARSE' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ãŒã€ãã‚Œã¯ç”Ÿæˆã•ã‚Œã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’スパースã«ã™ã‚‹ã“ã¨ã‚’指示ã™ã‚‹ã€‚`bnum' ã¯ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã®ç›®å®‰ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ãŒä½¿ã‚れる。ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã™ã‚‹æ™‚ã«æ±ºã‚られã€æœ€é©åŒ–以外ã®æ‰‹æ®µã§å¤‰æ›´ã™ã‚‹ã“ã¨ã¯ã§ããªã„。ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã¯ã€æ ¼ç´ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã®åŠåˆ†ã‹ã‚‰4å€ç¨‹åº¦ã«ã™ã‚‹ã®ãŒã‚ˆã„。戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚‹ã‹ã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。ライタ(読ã¿æ›¸ã両用モード)ã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’é–‹ãéš›ã«ã¯ãã®ãƒ•ã‚¡ã‚¤ãƒ«ã«å¯¾ã—ã¦æŽ’他ロックãŒã‹ã‘られã€ãƒªãƒ¼ãƒ€ï¼ˆèª­ã¿è¾¼ã¿å°‚用モード)ã§é–‹ãéš›ã«ã¯å…±æœ‰ãƒ­ãƒƒã‚¯ãŒã‹ã‘られる。ãã®éš›ã«ã¯è©²å½“ã®ãƒ­ãƒƒã‚¯ãŒã‹ã‘られるã¾ã§åˆ¶å¾¡ãŒãƒ–ロックã™ã‚‹ã€‚`DP_ONOLCK' を使ã†å ´åˆã€ã‚¢ãƒ—リケーションãŒæŽ’他制御ã®è²¬ä»»ã‚’è² ã†ã€‚
+
+ +

データベースã¨ã®æŽ¥ç¶šã‚’é–‰ã˜ã¦ãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpclose' を用ã„る。

+ +
+
int dpclose(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。データベースã®æ›´æ–°å†…容ã¯ã€æŽ¥ç¶šã‚’é–‰ã˜ãŸæ™‚点ã§åˆã‚ã¦ãƒ•ã‚¡ã‚¤ãƒ«ã¨åŒæœŸã•ã‚Œã‚‹ã€‚ライタã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã„ãŸå ´åˆã€é©åˆ‡ã«æŽ¥ç¶šã‚’é–‰ã˜ãªã„ã¨ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãŒç ´å£Šã•ã‚Œã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã§ããªããªã‚‹ã€‚
+
+ +

レコードを追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpput' を用ã„る。

+ +
+
int dpput(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
+
`depot' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`vbuf' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`vsiz' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(vbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`dmode' ã¯ã‚­ãƒ¼ãŒæ—¢å­˜ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨é‡è¤‡ã—ãŸéš›ã®åˆ¶å¾¡ã‚’指定ã™ã‚‹ã€‚`DP_DOVER' ã¯æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’上書ãã—ã€`DP_DKEEP' ã¯æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’残ã—ã¦ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã—ã€`DP_DCAT' ã¯æŒ‡å®šã•ã‚ŒãŸå€¤ã‚’既存ã®å€¤ã®æœ«å°¾ã«åŠ ãˆã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

レコードを削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpout' を用ã„る。

+ +
+
int dpout(DEPOT *depot, const char *kbuf, int ksiz);
+
`depot' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

レコードをå–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpget' を用ã„る。

+ +
+
char *dpget(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, int *sp);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`start' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹æœ€åˆã®ãƒã‚¤ãƒˆã®ã‚ªãƒ•ã‚»ãƒƒãƒˆã‚’指定ã™ã‚‹ã€‚`max' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ç„¡åˆ¶é™ã¨ãªã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚å–り出ãã†ã¨ã—ãŸå€¤ã®ã‚µã‚¤ã‚ºãŒ `start' よりå°ã•ã‹ã£ãŸå ´åˆã«ã¯è©²å½“ã¨ã¿ãªã•ãªã„。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

レコードをå–å¾—ã—ã¦ãƒãƒƒãƒ•ã‚¡ã«æ›¸ã込むã«ã¯ã€é–¢æ•° `dpgetwb' を用ã„る。

+ +
+
int dpgetwb(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, char *vbuf);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`start' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹æœ€åˆã®ãƒã‚¤ãƒˆã®ã‚ªãƒ•ã‚»ãƒƒãƒˆã‚’指定ã™ã‚‹ã€‚`max' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚ãã‚Œã¯æ›¸ãè¾¼ã¿ç”¨ã®ãƒãƒƒãƒ•ã‚¡ã®ã‚µã‚¤ã‚ºä»¥ä¸‹ã§ã‚ã‚‹å¿…è¦ãŒã‚る。`vbuf' ã¯æŠ½å‡ºã—ãŸãƒ‡ãƒ¼ã‚¿ã‚’書ã込むãƒãƒƒãƒ•ã‚¡ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒãƒƒãƒ•ã‚¡ã«æ›¸ãè¾¼ã¾ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ã®ã‚µã‚¤ã‚ºã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ -1 ã‚’è¿”ã™ã€‚å–り出ãã†ã¨ã—ãŸå€¤ã®ã‚µã‚¤ã‚ºãŒ `start' よりå°ã•ã‹ã£ãŸå ´åˆã«ã¯è©²å½“ã¨ã¿ãªã•ãªã„。書ãè¾¼ã¿ç”¨ãƒãƒƒãƒ•ã‚¡ã®æœ«å°¾ã«çµ‚端文字ãŒè¿½åŠ ã•ã‚Œãªã„ã“ã¨ã«æ³¨æ„ã™ã¹ãã§ã‚る。
+
+ +

レコードã®å€¤ã®ã‚µã‚¤ã‚ºã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpvsiz' を用ã„る。

+ +
+
int dpvsiz(DEPOT *depot, const char *kbuf, int ksiz);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯è©²å½“レコードã®å€¤ã®ã‚µã‚¤ã‚ºã§ã‚ã‚‹ãŒã€è©²å½“ãŒãªã„å ´åˆã‚„エラーã®å ´åˆã¯ -1 ã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æœ‰ç„¡ã‚’調ã¹ã‚‹ã®ã«ã‚‚便利ã§ã‚る。`dpget' ã¨é•ã£ã¦å®Ÿãƒ‡ãƒ¼ã‚¿ã‚’読ã¿è¾¼ã¾ãªã„ã®ã§åŠ¹çŽ‡ãŒã‚ˆã„。
+
+ +

データベースã®ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‚’åˆæœŸåŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpiterinit' を用ã„る。

+ +
+
int dpiterinit(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。イテレータã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã•ã‚ŒãŸå…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å‚ç…§ã™ã‚‹ãŸã‚ã«ç”¨ã„られる。
+
+ +

データベースã®ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‹ã‚‰æ¬¡ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã‚’å–り出ã™ã«ã¯ã€é–¢æ•° `dpiternext' を用ã„る。

+ +
+
char *dpiternext(DEPOT *depot, int *sp);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ã‚­ãƒ¼ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。イテレータãŒæœ€å¾Œã¾ã§ãã¦è©²å½“ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã‚’ç¹°ã‚Šè¿”ã—ã¦å‘¼ã¶ã“ã¨ã«ã‚ˆã£ã¦å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’一度ãšã¤å‚ç…§ã™ã‚‹ã“ã¨ãŒã§ãる。ãŸã ã—ã€ç¹°ã‚Šè¿”ã—ã®é–“ã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ›´æ–°ãŒã‚ã£ãŸå ´åˆã¯ãã®é™ã‚Šã§ã¯ãªã„。ãªãŠã€å–り出ã™ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é †åºã¯åˆ¶å¾¡ã§ããšã€æ ¼ç´ã—ãŸé †ç•ªã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å–り出ã›ã‚‹ã¨ã¯é™ã‚‰ãªã„。
+
+ +

データベースã®ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã‚’設定ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpsetalign' を用ã„る。

+ +
+
int dpsetalign(DEPOT *depot, int align);
+
`depot' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`align' ã¯ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。アラインメントを設定ã—ã¦ãŠãã¨ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ä¸Šæ›¸ãã‚’é »ç¹ã«ã™ã‚‹å ´åˆã®å‡¦ç†åŠ¹çŽ‡ãŒè‰¯ããªã‚‹ã€‚アラインメントã«ã¯ã€ä¸€é€£ã®æ›´æ–°æ“作をã—ãŸå¾Œã®çŠ¶æ…‹ã§ã®æ¨™æº–çš„ãªå€¤ã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã®ãŒã‚ˆã„。アラインメントãŒæ­£æ•°ã®å ´åˆã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é ˜åŸŸã®ã‚µã‚¤ã‚ºãŒã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã®å€æ•°ã«ãªã‚‹ã‚ˆã†ã«ãƒ‘ディングãŒã¨ã‚‰ã‚Œã‚‹ã€‚アラインメントãŒè² æ•°ã®å ´åˆã€`vsiz' を値ã®ã‚µã‚¤ã‚ºã¨ã—ã¦ã€ãƒ‘ディングã®ã‚µã‚¤ã‚ºã¯ `(vsiz / pow(2, abs(align) - 1))' ã¨ã—ã¦ç®—出ã•ã‚Œã‚‹ã€‚アラインメントã®è¨­å®šã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ä¿å­˜ã•ã‚Œãªã„ã®ã§ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã度ã«æŒ‡å®šã™ã‚‹å¿…è¦ãŒã‚る。
+
+ +

データベースã®ãƒ•ãƒªãƒ¼ãƒ–ロックプールã®ã‚µã‚¤ã‚ºè¨­å®šã™ã‚‹ã«ã¯ã€é–¢æ•° `dpsetfbpsiz' を用ã„る。

+ +
+
int dpsetfbpsiz(DEPOT *depot, int size);
+
`depot' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãƒ•ãƒªãƒ¼ãƒ–ロックプールã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。フリーブロックプールã®ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã®ã‚µã‚¤ã‚ºã¯16ã§ã‚る。サイズをより大ããã™ã‚‹ã¨ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ä¸Šæ›¸ãã‚’ç¹°ã‚Šè¿”ã™éš›ã®ç©ºé–“効率ã¯ä¸ŠãŒã‚‹ãŒã€æ™‚間効率ãŒä¸‹ãŒã‚‹ã€‚
+
+ +

データベースを更新ã—ãŸå†…容をファイルã¨ãƒ‡ãƒã‚¤ã‚¹ã«åŒæœŸã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `dpsync' を用ã„る。

+ +
+
int dpsync(DEPOT *depot);
+
`depot' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‰ã˜ãªã„ã†ã¡ã«åˆ¥ãƒ—ロセスã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’利用ã•ã›ã‚‹å ´åˆã«å½¹ç«‹ã¤ã€‚
+
+ +

データベースを最é©åŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpoptimize' を用ã„る。

+ +
+
int dpoptimize(DEPOT *depot, int bnum);
+
`depot' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`bnum' ã¯æ–°ãŸãªãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰ç¾åœ¨ã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã«æœ€é©ãªå€¤ãŒæŒ‡å®šã•ã‚Œã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。レコードを削除ã—ãŸã‚Šã€ç½®æ›ãƒ¢ãƒ¼ãƒ‰ã‚„連çµãƒ¢ãƒ¼ãƒ‰ã§æ›¸ãè¾¼ã¿ã‚’ç¹°ã‚Šè¿”ã—ãŸã‚Šã™ã‚‹å ´åˆã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹å†…ã«ä¸è¦ãªé ˜åŸŸãŒè“„ç©ã™ã‚‹ãŒã€ã“ã®é–¢æ•°ã¯ãれを解消ã™ã‚‹ã®ã«å½¹ç«‹ã¤ã€‚
+
+ +

データベースã®åå‰ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dpname' を用ã„る。

+ +
+
char *dpname(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰åå‰ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

データベースファイルã®ã‚µã‚¤ã‚ºã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dpfsiz' を用ã„る。

+ +
+
int dpfsiz(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

データベースã®ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dpbnum' を用ã„る。

+ +
+
int dpbnum(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

データベースã®ãƒã‚±ãƒƒãƒˆé…列ã®åˆ©ç”¨æ¸ˆã¿ã®è¦ç´ æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dpbusenum' を用ã„る。

+ +
+
int dpbusenum(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒã‚±ãƒƒãƒˆé…列ã®åˆ©ç”¨æ¸ˆã¿ã®è¦ç´ æ•°ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒã‚±ãƒƒãƒˆé…列ã®å…¨ã¦ã®è¦ç´ ã‚’å‚ç…§ã™ã‚‹ã®ã§ã€åŠ¹çŽ‡ãŒæ‚ªã„。
+
+ +

データベースã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dprnum' を用ã„る。

+ +
+
int dprnum(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

データベースãƒãƒ³ãƒ‰ãƒ«ãŒãƒ©ã‚¤ã‚¿ã‹ã©ã†ã‹ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `dpwritable' を用ã„る。

+ +
+
int dpwritable(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ©ã‚¤ã‚¿ãªã‚‰çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

データベースã«è‡´å‘½çš„エラーãŒèµ·ããŸã‹ã©ã†ã‹ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `dpfatalerror' を用ã„る。

+ +
+
int dpfatalerror(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯è‡´å‘½çš„エラーãŒã‚ã‚Œã°çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

データベースファイルã®inode番å·ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dpinode' を用ã„る。

+ +
+
int dpinode(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®inode番å·ã§ã‚る。
+
+ +

データベースã®æœ€çµ‚更新時刻を得るã«ã¯ã€é–¢æ•° `dpmtime' を用ã„る。

+ +
+
time_t dpmtime(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æœ€çµ‚更新時刻ã§ã‚る。
+
+ +

データベースファイルã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dpfdesc' を用ã„る。

+ +
+
int dpfdesc(DEPOT *depot);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã§ã‚る。データベースã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—タを直接æ“ã‚‹ã“ã¨ã¯æŽ¨å¥¨ã•ã‚Œãªã„。
+
+ +

データベースファイルを削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpremove' を用ã„る。

+ +
+
int dpremove(const char *name);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

壊れãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’修復ã™ã‚‹ã«ã¯ã€é–¢æ•° `dprepair' を用ã„る。

+ +
+
int dprepair(const char *name);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。修復ã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å…¨ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒå…ƒæ¥ã‚‚ã—ãã¯æœŸå¾…ã•ã‚Œã‚‹çŠ¶æ…‹ã«æˆ»ã‚‹ä¿è¨¼ã¯ãªã„。
+
+ +

å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’エンディアンéžä¾å­˜ã®ãƒ‡ãƒ¼ã‚¿ã¨ã—ã¦ãƒ€ãƒ³ãƒ—ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpexportdb' を用ã„る。

+ +
+
int dpexportdb(DEPOT *depot, const char *name);
+
`depot' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`name' ã¯å‡ºåŠ›ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

エンディアンéžä¾å­˜ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’ロードã™ã‚‹ã«ã¯ã€é–¢æ•° `dpimportdb' を用ã„る。

+ +
+
int dpimportdb(DEPOT *depot, const char *name);
+
`depot' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚データベースã¯ç©ºã§ãªã‘ã‚Œã°ãªã‚‰ãªã„。`name' ã¯å…¥åŠ›ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

データベースファイルã‹ã‚‰ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’直接å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `dpsnaffle' を用ã„る。

+ +
+
char *dpsnaffle(const char *name, const char *kbuf, int ksiz, int *sp);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`start' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹æœ€åˆã®ãƒã‚¤ãƒˆã®ã‚ªãƒ•ã‚»ãƒƒãƒˆã‚’指定ã™ã‚‹ã€‚`max' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ç„¡åˆ¶é™ã¨ãªã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚å–り出ãã†ã¨ã—ãŸå€¤ã®ã‚µã‚¤ã‚ºãŒ `start' よりå°ã•ã‹ã£ãŸå ´åˆã«ã¯è©²å½“ã¨ã¿ãªã•ãªã„。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ãŒåˆ¥ã®ãƒ—ロセスã«ãƒ­ãƒƒã‚¯ã•ã‚Œã¦ã„ã¦ã‚‚利用ã§ãã‚‹ãŒã€æœ€æ–°ã®æ›´æ–°ãŒå映ã•ã‚Œã¦ã„ã‚‹ä¿è¨¼ã¯ãªã„。
+
+ +

データベースã®å†…部ã§ç”¨ã„ã‚‹ãƒãƒƒã‚·ãƒ¥é–¢æ•°ã¨ã—ã¦ã€é–¢æ•° `dpinnerhash' ãŒã‚る。

+ +
+
int dpinnerhash(const char *kbuf, int ksiz);
+
`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯ã‚­ãƒ¼ã‹ã‚‰31ビット長ã®ãƒãƒƒã‚·ãƒ¥å€¤ã‚’算出ã—ãŸå€¤ã§ã‚る。ã“ã®é–¢æ•°ã¯ã‚¢ãƒ—リケーションãŒãƒã‚±ãƒƒãƒˆé…列ã®çŠ¶æ…‹ã‚’予測ã™ã‚‹éš›ã«å½¹ç«‹ã¤ã€‚
+
+ +

データベースã®å†…部ã§ç”¨ã„ã‚‹ãƒãƒƒã‚·ãƒ¥é–¢æ•°ã¨ç‹¬ç«‹ã—ãŸãƒãƒƒã‚·ãƒ¥é–¢æ•°ã¨ã—ã¦ã€é–¢æ•° `dpouterhash' ãŒã‚る。

+ +
+
int dpouterhash(const char *kbuf, int ksiz);
+
`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯ã‚­ãƒ¼ã‹ã‚‰31ビット長ã®ãƒãƒƒã‚·ãƒ¥å€¤ã‚’算出ã—ãŸå€¤ã§ã‚る。ã“ã®é–¢æ•°ã¯ã‚¢ãƒ—リケーションãŒãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ›´ã«ä¸Šã§ãƒãƒƒã‚·ãƒ¥ã‚¢ãƒ«ã‚´ãƒªã‚ºãƒ ã‚’利用ã™ã‚‹éš›ã«å½¹ç«‹ã¤ã€‚
+
+ +

ã‚る数以上ã®è‡ªç„¶æ•°ã®ç´ æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dpprimenum' を用ã„る。

+ +
+
int dpprimenum(int num);
+
`num' ã¯é©å½“ãªè‡ªç„¶æ•°ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ã€æŒ‡å®šã—ãŸæ•°ã¨åŒã˜ã‹ã‚ˆã‚Šå¤§ããã‹ã¤ãªã‚‹ã¹ãå°ã•ã„自然数ã®ç´ æ•°ã§ã‚る。ã“ã®é–¢æ•°ã¯ã‚¢ãƒ—リケーションãŒåˆ©ç”¨ã™ã‚‹ãƒã‚±ãƒƒãƒˆé…列ã®ã‚µã‚¤ã‚ºã‚’決ã‚ã‚‹å ´åˆã«å½¹ç«‹ã¤ã€‚
+
+ +

サンプルコード

+ +

åå‰ã¨å¯¾å¿œã•ã›ã¦é›»è©±ç•ªå·ã‚’æ ¼ç´ã—ã€ãれを検索ã™ã‚‹ã‚¢ãƒ—リケーションã®ã‚µãƒ³ãƒ—ルコードを以下ã«ç¤ºã™ã€‚

+ +
#include <depot.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define NAME     "mikio"
+#define NUMBER   "000-1234-5678"
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  DEPOT *depot;
+  char *val;
+
+  /* データベースを開ã */
+  if(!(depot = dpopen(DBNAME, DP_OWRITER | DP_OCREAT, -1))){
+    fprintf(stderr, "dpopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* レコードを格ç´ã™ã‚‹ */
+  if(!dpput(depot, NAME, -1, NUMBER, -1, DP_DOVER)){
+    fprintf(stderr, "dpput: %s\n", dperrmsg(dpecode));
+  }
+
+  /* レコードをå–å¾—ã™ã‚‹ */
+  if(!(val = dpget(depot, NAME, -1, 0, -1, NULL))){
+    fprintf(stderr, "dpget: %s\n", dperrmsg(dpecode));
+  } else {
+    printf("Name: %s\n", NAME);
+    printf("Number: %s\n", val);
+    free(val);
+  }
+
+  /* データベースを閉ã˜ã‚‹ */
+  if(!dpclose(depot)){
+    fprintf(stderr, "dpclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

データベースã®å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’表示ã™ã‚‹ã‚¢ãƒ—リケーションã®ã‚µãƒ³ãƒ—ルコードを以下ã«ç¤ºã™ã€‚

+ +
#include <depot.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  DEPOT *depot;
+  char *key, *val;
+
+  /* データベースを開ã */
+  if(!(depot = dpopen(DBNAME, DP_OREADER, -1))){
+    fprintf(stderr, "dpopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* イテレータをåˆæœŸåŒ–ã™ã‚‹ */
+  if(!dpiterinit(depot)){
+    fprintf(stderr, "dpiterinit: %s\n", dperrmsg(dpecode));
+  }
+
+  /* イテレータを走査ã™ã‚‹ */
+  while((key = dpiternext(depot, NULL)) != NULL){
+    if(!(val = dpget(depot, key, -1, 0, -1, NULL))){
+      fprintf(stderr, "dpget: %s\n", dperrmsg(dpecode));
+      free(key);
+      break;
+    }
+    printf("%s: %s\n", key, val);
+    free(val);
+    free(key);
+  }
+
+  /* データベースを閉ã˜ã‚‹ */
+  if(!dpclose(depot)){
+    fprintf(stderr, "dpclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

注記

+ +

Depotを利用ã—ãŸãƒ—ログラムをビルドã™ã‚‹ã«ã¯ã€ãƒ©ã‚¤ãƒ–ラリ `libqdbm.a' ã¾ãŸã¯ `libqdbm.so' をリンク対象ã«åŠ ãˆã‚‹å¿…è¦ãŒã‚る。例ãˆã°ã€`sample.c' ã‹ã‚‰ `sample' を作るã«ã¯ã€ä»¥ä¸‹ã®ã‚ˆã†ã«ãƒ“ルドを行ã†ã€‚

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

POSIXスレッドを有効ã«ã—ã¦QDBMをビルドã—ãŸå ´åˆã€å¤–部変数 `dpecode' ã¯ã‚¹ãƒ¬ãƒƒãƒ‰å›ºæœ‰ãƒ‡ãƒ¼ã‚¿ã¸ã®å‚ç…§ã¨ã—ã¦æ‰±ã‚ã‚Œã€Depotã®å„関数ã¯ãƒªã‚¨ãƒ³ãƒˆãƒ©ãƒ³ãƒˆã«ãªã‚‹ã€‚ãã®å ´åˆã€ã‚¹ãƒ¬ãƒƒãƒ‰é–“ã§åŒæ™‚ã«åŒã˜ãƒãƒ³ãƒ‰ãƒ«ã«ã‚¢ã‚¯ã‚»ã‚¹ã—ãªã„é™ã‚Šã¯ã€å„関数ã¯ã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ã§ã‚る。ãŸã ã—ã€`errno' ã‚„ `malloc' ç­‰ãŒã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ãªå‡¦ç†ç³»ã§ã‚ã‚‹ã“ã¨ãŒå‰æã¨ãªã‚‹ã€‚

+ +
+ +

Depot用コマンド

+ +

Depotã«å¯¾å¿œã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ãƒ©ã‚¤ãƒ³ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ã¯ä»¥ä¸‹ã®ã‚‚ã®ã§ã‚る。

+ +

コマンド `dpmgr' ã¯Depotã‚„ãã®ã‚¢ãƒ—リケーションã®ãƒ‡ãƒãƒƒã‚°ã«å½¹ç«‹ã¤ãƒ„ールã§ã‚る。データベースを更新ã—ãŸã‚Šã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®çŠ¶æ…‹ã‚’調ã¹ãŸã‚Šã™ã‚‹æ©Ÿèƒ½ã‚’æŒã¤ã€‚シェルスクリプトã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚¢ãƒ—リケーションを作るã®ã«ã‚‚利用ã§ãる。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`key' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã€`val' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’指定ã™ã‚‹ã€‚

+ +
+
dpmgr create [-s] [-bnum num] name
+
データベースファイルを作æˆã™ã‚‹ã€‚
+
dpmgr put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat] [-na] name key val
+
キーã¨å€¤ã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã™ã‚‹ã€‚
+
dpmgr out [-kx|-ki] name key
+
キーã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã™ã‚‹ã€‚
+
dpmgr get [-nl] [-kx|-ki] [-start num] [-max num] [-ox] [-n] name key
+
キーã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’å–å¾—ã—ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
dpmgr list [-nl] [-k|-v] [-ox] name
+
データベース内ã®å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã¨å€¤ã‚’タブã¨æ”¹è¡Œã§åŒºåˆ‡ã£ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
dpmgr optimize [-bnum num] [-na] name
+
データベースを最é©åŒ–ã™ã‚‹ã€‚
+
dpmgr inform [-nl] name
+
データベースã®é›‘多ãªæƒ…報を出力ã™ã‚‹ã€‚
+
dpmgr remove name
+
データベースファイルを削除ã™ã‚‹ã€‚
+
dpmgr repair name
+
壊れãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’修復ã™ã‚‹ã€‚
+
dpmgr exportdb name file
+
å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’エンディアンéžä¾å­˜ã®ãƒ‡ãƒ¼ã‚¿ã¨ã—ã¦ãƒ€ãƒ³ãƒ—ã™ã‚‹ã€‚
+
dpmgr importdb [-bnum num] name file
+
エンディアンéžä¾å­˜ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’ロードã™ã‚‹ã€‚
+
dpmgr snaffle [-kx|-ki] [-ox] [-n] name key
+
ロックã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‹ã‚‰ã‚­ãƒ¼ã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’å–å¾—ã—ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
dpmgr version
+
QDBMã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³æƒ…報を標準出力ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -s : ファイルをスパースã«ã™ã‚‹ã€‚
  • +
  • -bnum num : ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã‚’ `num' ã«æŒ‡å®šã™ã‚‹ã€‚
  • +
  • -kx : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—㦠`key' を扱ã†ã€‚
  • +
  • -ki : 10進数ã«ã‚ˆã‚‹æ•°å€¤è¡¨ç¾ã¨ã—㦠`key' を扱ã†ã€‚
  • +
  • -vx : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—㦠`val' を扱ã†ã€‚
  • +
  • -vi : 10進数ã«ã‚ˆã‚‹æ•°å€¤è¡¨ç¾ã¨ã—㦠`val' を扱ã†ã€‚
  • +
  • -vf : åå‰ãŒ `val' ã®ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ‡ãƒ¼ã‚¿ã‚’値ã¨ã—ã¦èª­ã¿è¾¼ã‚€ã€‚
  • +
  • -keep : 既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã‚­ãƒ¼ãŒé‡è¤‡æ™‚ã«ä¸Šæ›¸ãã›ãšã«ã‚¨ãƒ©ãƒ¼ã«ã™ã‚‹ã€‚
  • +
  • -cat : 既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã‚­ãƒ¼ãŒé‡è¤‡æ™‚ã«å€¤ã‚’末尾ã«è¿½åŠ ã™ã‚‹ã€‚
  • +
  • -na : アラインメントを設定ã—ãªã„。
  • +
  • -nl : ファイルロックをã‹ã‘ãšã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã。
  • +
  • -start : 値ã‹ã‚‰å–り出ã™ãƒ‡ãƒ¼ã‚¿ã®é–‹å§‹ã‚ªãƒ•ã‚»ãƒƒãƒˆã‚’指定ã™ã‚‹ã€‚
  • +
  • -max : 値ã‹ã‚‰å–り出ã™ãƒ‡ãƒ¼ã‚¿ã®æœ€å¤§ã®é•·ã•ã‚’指定ã™ã‚‹ã€‚
  • +
  • -ox : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—ã¦æ¨™æº–出力を行ã†ã€‚
  • +
  • -n : 標準出力ã®æœ«å°¾ã«ä»˜åŠ ã•ã‚Œã‚‹æ”¹è¡Œæ–‡å­—ã®å‡ºåŠ›ã‚’抑制ã™ã‚‹ã€‚
  • +
  • -k : キーã®ã¿ã‚’出力ã™ã‚‹ã€‚
  • +
  • -v : 値ã®ã¿ã‚’出力ã™ã‚‹ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚環境変数 `QDBMDBGFD' ã®å€¤ã¨ã—ã¦ã€å¤‰æ•° `dpecode' ã®å¤‰æ›´å±¥æ­´ã‚’出力ã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—タを指定ã“ã¨ãŒã§ãる。

+ +

コマンド `dptest' ã¯Depotã®æ©Ÿèƒ½ãƒ†ã‚¹ãƒˆã‚„性能テストã«ç”¨ã„るツールã§ã‚る。ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã«ã‚ˆã£ã¦ç”Ÿæˆã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ `dpmgr' ã«ã‚ˆã£ã¦è§£æžã—ãŸã‚Šã€`time' コマンドã«ã‚ˆã£ã¦ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã®å®Ÿè¡Œæ™‚間を計ã£ãŸã‚Šã™ã‚‹ã¨ã‚ˆã„。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`rnum' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã€`bnum' ã¯ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã€`pnum' ã¯ã‚­ãƒ¼ã®ãƒ‘ターン数ã€`align' ã¯ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã®åŸºæœ¬ã‚µã‚¤ã‚ºã€`fbpsiz' ã¯ãƒ•ãƒªãƒ¼ãƒ–ロックプールã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚

+ +
+
dptest write [-s] name rnum bnum
+
`00000001'ã€`00000002' ã®ã‚ˆã†ã«å¤‰åŒ–ã™ã‚‹8ãƒã‚¤ãƒˆã®ã‚­ãƒ¼ã¨é©å½“ãª8ãƒã‚¤ãƒˆã®å€¤ã‚’連続ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«è¿½åŠ ã™ã‚‹ã€‚
+
dptest read [-wb] name
+
上記ã§ç”Ÿæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å…¨ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã™ã‚‹ã€‚
+
dptest rcat [-c] name rnum bnum pnum align fbpsiz
+
キーãŒã‚る程度é‡è¤‡ã™ã‚‹ã‚ˆã†ã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã®è¿½åŠ ã‚’è¡Œã„ã€é€£çµãƒ¢ãƒ¼ãƒ‰ã§å‡¦ç†ã™ã‚‹ã€‚
+
dptest combo name
+
å„種æ“作ã®çµ„ã¿åˆã‚ã›ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚
+
dptest wicked [-c] name rnum
+
å„種更新æ“作を無作為ã«é¸æŠžã—ã¦å®Ÿè¡Œã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -s : ファイルをスパースã«ã™ã‚‹ã€‚
  • +
  • -wb : 関数 `dpget' ã®ä»£ã‚ã‚Šã«é–¢æ•° `dpgetwb' を用ã„る。
  • +
  • -c : Cabinã®ãƒžãƒƒãƒ—を使ã£ã¦æ¯”較テストを行ã†ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚環境変数 `QDBMDBGFD' ã®å€¤ã¨ã—ã¦ã€å¤‰æ•° `dpecode' ã®å¤‰æ›´å±¥æ­´ã‚’出力ã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—タを指定ã“ã¨ãŒã§ãる。

+ +

コマンド `dptsv' ã¯ã‚¿ãƒ–区切りã§ã‚­ãƒ¼ã¨å€¤ã‚’表ç¾ã—ãŸè¡Œã‹ã‚‰ãªã‚‹TSVファイルã¨Depotã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’相互変æ›ã™ã‚‹ã€‚ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã€QDBMã®ä»–ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã‚„ä»–ã®DBMã¨ã®é–“ã§ãƒ‡ãƒ¼ã‚¿ã®äº¤æ›ã‚’è¡Œã†éš›ã«å½¹ç«‹ã¤ã€‚ã¾ãŸã€ãƒã‚¤ãƒˆã‚ªãƒ¼ãƒ€ã®é•ã†ã‚·ã‚¹ãƒ†ãƒ ã®é–“ã§ãƒ‡ãƒ¼ã‚¿ã‚’交æ›ã™ã‚‹éš›ã«ã‚‚役立ã¤ã€‚以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åを指定ã™ã‚‹ã€‚`export' サブコマンドã§ã¯TSVã®ãƒ‡ãƒ¼ã‚¿ã¯æ¨™æº–入力ã‹ã‚‰èª­ã¿è¾¼ã‚€ã€‚キーãŒé‡è¤‡ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã¯å¾Œè€…を優先ã™ã‚‹ã€‚`-bnum' オプションã®å¼•æ•° `num' ã¯ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`import' サブコマンドã§ã¯TSVã®ãƒ‡ãƒ¼ã‚¿ãŒæ¨™æº–出力ã«æ›¸ã出ã•ã‚Œã‚‹ã€‚

+ +
+
dptsv import [-bnum num] [-bin] name
+
TSVファイルを読ã¿è¾¼ã‚“ã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã™ã‚‹ã€‚
+
dptsv export [-bin] name
+
データベースã®å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’TSVファイルã¨ã—ã¦å‡ºåŠ›ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -bnum num : ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã‚’ `num' ã«æŒ‡å®šã™ã‚‹ã€‚
  • +
  • -bin : Base64å½¢å¼ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’扱ã†ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +

Depotã®ã‚³ãƒžãƒ³ãƒ‰ç¾¤ã‚’駆使ã™ã‚‹ã¨ã€ç°¡å˜ãªãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚·ã‚¹ãƒ†ãƒ ãŒæ§‹ç¯‰ã§ãる。例ãˆã° `/etc/password' をユーザåã§æ¤œç´¢ã™ã‚‹ãŸã‚ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã™ã‚‹ã«ã¯ã€ä»¥ä¸‹ã®ã‚ˆã†ã«ã™ã‚‹ã€‚

+ +
cat /etc/passwd | tr ':' '\t' | dptsv import casket
+
+ +

ãã—ã¦ã€`mikio' ã¨ã„ã†ãƒ¦ãƒ¼ã‚¶ã®æƒ…報をå–り出ã™ã«ã¯ã€ä»¥ä¸‹ã®ã‚ˆã†ã«ã™ã‚‹ã€‚

+ +
dpmgr get casket mikio
+
+ +

ã“れらã®ã‚³ãƒžãƒ³ãƒ‰ã¨åŒç­‰ã®æ©Ÿèƒ½ã‚’Depotã®APIを用ã„ã¦å®Ÿè£…ã™ã‚‹ã“ã¨ã‚‚容易ã§ã‚る。

+ +
+ +

Curia: æ‹¡å¼µAPI

+ +

概è¦

+ +

Curiaã¯QDBMã®æ‹¡å¼µAPIã§ã‚ã‚Šã€è¤‡æ•°ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ディレクトリã§ä¸€æ‹¬ã—ã¦æ‰±ã†æ©Ÿèƒ½ã‚’æä¾›ã™ã‚‹ã€‚データベースを複数ã®ãƒ•ã‚¡ã‚¤ãƒ«ã«åˆ†å‰²ã™ã‚‹ã“ã¨ã§ã€ãƒ•ã‚¡ã‚¤ãƒ«ã‚·ã‚¹ãƒ†ãƒ ã«ã‚ˆã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ã‚µã‚¤ã‚ºã®åˆ¶é™ã‚’回é¿ã™ã‚‹ã“ã¨ãŒã§ãる。複数ã®ãƒ‡ãƒã‚¤ã‚¹ã«ãƒ•ã‚¡ã‚¤ãƒ«ã‚’分散ã•ã›ã‚Œã°ã€ã‚¹ã‚±ãƒ¼ãƒ©ãƒ“リティをå‘上ã•ã›ã‚‹ã“ã¨ãŒã§ãる。

+ +

Depotã§ã¯ãƒ•ã‚¡ã‚¤ãƒ«åを指定ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’構築ã™ã‚‹ãŒã€Curiaã§ã¯ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªåを指定ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’構築ã™ã‚‹ã€‚指定ã—ãŸãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®ç›´ä¸‹ã«ã¯ã€`depot' ã¨ã„ã†åå‰ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ãŒç”Ÿæˆã•ã‚Œã‚‹ã€‚ã“ã‚Œã¯ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®å±žæ€§ã‚’ä¿æŒã™ã‚‹ã‚‚ã®ã§ã‚ã‚Šã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å®Ÿãƒ‡ãƒ¼ã‚¿ã¯æ ¼ç´ã•ã‚Œãªã„。ãã‚Œã¨ã¯åˆ¥ã«ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’分割ã—ãŸå€‹æ•°ã ã‘ã€4æ¡ã®10進数値ã®åå‰ã‚’æŒã¤ã‚µãƒ–ディレクトリãŒç”Ÿæˆã•ã‚Œã€å„々ã®ã‚µãƒ–ディレクトリã®ä¸­ã«ã¯ `depot' ã¨ã„ã†åå‰ã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ãŒç”Ÿæˆã•ã‚Œã‚‹ã€‚レコードã®å®Ÿãƒ‡ãƒ¼ã‚¿ã¯ãれらã«æ ¼ç´ã•ã‚Œã‚‹ã€‚例ãˆã°ã€`casket' ã¨ã„ã†åå‰ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã—ã€åˆ†å‰²æ•°ã‚’3ã«ã™ã‚‹å ´åˆã€`casket/depot'ã€`casket/0001/depot'ã€`casket/0002/depot'ã€`casket/0003/depot' ãŒç”Ÿæˆã•ã‚Œã‚‹ã€‚データベースを作æˆã™ã‚‹éš›ã«ã™ã§ã«ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªãŒå­˜åœ¨ã—ã¦ã„ã¦ã‚‚エラーã¨ã¯ãªã‚‰ãªã„。ã—ãŸãŒã£ã¦ã€äºˆã‚サブディレクトリを生æˆã—ã¦ãŠã„ã¦ã€å„々ã«ç•°ãªã‚‹ãƒ‡ãƒã‚¤ã‚¹ã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚·ã‚¹ãƒ†ãƒ ã‚’マウントã—ã¦ãŠã‘ã°ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’複数ã®ãƒ‡ãƒã‚¤ã‚¹ã«åˆ†æ•£ã•ã›ã‚‹ã“ã¨ãŒã§ãる。

+ +

Curiaã«ã¯ãƒ©ãƒ¼ã‚¸ã‚ªãƒ–ジェクトを扱ã†æ©Ÿèƒ½ãŒã‚る。通常ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ãƒ‡ãƒ¼ã‚¿ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã«æ ¼ç´ã•ã‚Œã‚‹ãŒã€ãƒ©ãƒ¼ã‚¸ã‚ªãƒ–ジェクトã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ãƒ‡ãƒ¼ã‚¿ã¯å€‹åˆ¥ã®ãƒ•ã‚¡ã‚¤ãƒ«ã«æ ¼ç´ã•ã‚Œã‚‹ã€‚ラージオブジェクトã®ãƒ•ã‚¡ã‚¤ãƒ«ã¯ãƒãƒƒã‚·ãƒ¥å€¤ã‚’å…ƒã«ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã«åˆ†ã‘ã¦æ ¼ç´ã•ã‚Œã‚‹ã®ã§ã€é€šå¸¸ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ã¯åŠ£ã‚‹ãŒã€ãã‚Œãªã‚Šã®é€Ÿåº¦ã§å‚ç…§ã§ãる。サイズãŒå¤§ããå‚照頻度ãŒä½Žã„データã¯ã€ãƒ©ãƒ¼ã‚¸ã‚ªãƒ–ジェクトã¨ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‹ã‚‰åˆ†é›¢ã™ã¹ãã§ã‚る。ãã†ã™ã‚Œã°ã€é€šå¸¸ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«å¯¾ã™ã‚‹å‡¦ç†é€Ÿåº¦ãŒå‘上ã™ã‚‹ã€‚ラージオブジェクトã®ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªéšŽå±¤ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ãŒæ ¼ç´ã•ã‚Œã‚‹ã‚µãƒ–ディレクトリã®ä¸­ã® `lob' ã¨ã„ã†åå‰ã®ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®ä¸­ã«ä½œã‚‰ã‚Œã‚‹ã€‚通常ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¨ãƒ©ãƒ¼ã‚¸ã‚ªãƒ–ジェクトã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¯ã‚­ãƒ¼ç©ºé–“ãŒç•°ãªã‚Šã€äº’ã„ã«å¹²æ¸‰ã™ã‚‹ã“ã¨ã¯ãªã„。

+ +

Curiaを使ã†ãŸã‚ã«ã¯ã€`depot.h' 㨠`curia.h' 㨠`stdlib.h' をインクルードã™ã¹ãã§ã‚る。通常ã€ã‚½ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®å†’頭付近ã§ä»¥ä¸‹ã®è¨˜è¿°ã‚’è¡Œã†ã€‚

+ +
+
#include <depot.h>
+
#include <curia.h>
+
#include <stdlib.h>
+
+ +

Curiaã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†éš›ã«ã¯ã€`CURIA' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。ã“ã‚Œã¯ã€`stdio.h' ã®å„種ルーãƒãƒ³ãŒãƒ•ã‚¡ã‚¤ãƒ«å…¥å‡ºåŠ›ã« `FILE' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’用ã„ã‚‹ã®ã«ä¼¼ã¦ã„る。ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `cropen' ã§é–‹ãã€é–¢æ•° `crclose' ã§é–‰ã˜ã‚‹ã€‚ãƒãƒ³ãƒ‰ãƒ«ã®ãƒ¡ãƒ³ãƒã‚’直接å‚ç…§ã™ã‚‹ã“ã¨ã¯æŽ¨å¥¨ã•ã‚Œãªã„。データベースã«è‡´å‘½çš„ãªã‚¨ãƒ©ãƒ¼ãŒèµ·ããŸå ´åˆã¯ã€ä»¥å¾Œãã®ãƒãƒ³ãƒ‰ãƒ«ã«å¯¾ã™ã‚‹ `crclose' を除ãå…¨ã¦ã®æ“作ã¯ä½•ã‚‚ã›ãšã«ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã™ã€‚ã²ã¨ã¤ã®ãƒ—ロセスã§è¤‡æ•°ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’åŒæ™‚ã«åˆ©ç”¨ã™ã‚‹ã“ã¨ã¯å¯èƒ½ã§ã‚ã‚‹ãŒã€åŒã˜ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®è¤‡æ•°ã®ãƒãƒ³ãƒ‰ãƒ«ã‚’利用ã—ã¦ã¯ãªã‚‰ãªã„。

+ +

Curiaã§ã‚‚Depotã¨åŒã˜ã外部変数 `dpecode' ã«ç›´å‰ã®ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ãŒè¨˜éŒ²ã•ã‚Œã‚‹ã€‚エラーコードã«å¯¾å¿œã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸æ–‡å­—列を得るã«ã¯ã€é–¢æ•° `dperrmsg' を用ã„る。

+ +

API

+ +

データベースã®ãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `cropen' を用ã„る。

+ +
+
CURIA *cropen(const char *name, int omode, int bnum, int dnum);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®åå‰ã‚’指定ã™ã‚‹ã€‚`omode' ã¯æŽ¥ç¶šãƒ¢ãƒ¼ãƒ‰ã‚’指定ã—ã€`CR_OREADER' ãªã‚‰ãƒªãƒ¼ãƒ€ã€`CR_OWRITER' ãªã‚‰ãƒ©ã‚¤ã‚¿ã¨ãªã‚‹ã€‚`CR_OWRITER' ã®å ´åˆã€`CR_OCREAT' ã¾ãŸã¯ `CR_OTRUNC' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãる。`CR_OCREAT' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãŒç„¡ã„å ´åˆã«æ–°è¦ä½œæˆã™ã‚‹ã“ã¨ã‚’指示ã—ã€`CR_OTRUNC' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãŒå­˜åœ¨ã—ã¦ã‚‚作り直ã™ã“ã¨ã‚’指示ã™ã‚‹ã€‚`CR_OREADER' 㨠`CR_OWRITER' ã®ä¸¡æ–¹ã§ `CR_ONOLCK' ã¾ãŸã¯ `CR_OLCKNB' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ãŒã€å‰è€…ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãƒ­ãƒƒã‚¯ã‚’ã‹ã‘ãšã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ãã“ã¨ã‚’指示ã—ã€å¾Œè€…ã¯ãƒ–ロックã›ãšã«ãƒ­ãƒƒã‚¯ã‚’ã‹ã‘ã‚‹ã“ã¨ã‚’指示ã™ã‚‹ã€‚`CR_OCREAT' 㯠`CR_OSPARSE' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ãŒã€ãã‚Œã¯ç”Ÿæˆã•ã‚Œã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’スパースã«ã™ã‚‹ã“ã¨ã‚’指示ã™ã‚‹ã€‚`bnum' ã¯ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã®ç›®å®‰ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ãŒä½¿ã‚れる。ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã™ã‚‹æ™‚ã«æ±ºã‚られã€æœ€é©åŒ–以外ã®æ‰‹æ®µã§å¤‰æ›´ã™ã‚‹ã“ã¨ã¯ã§ããªã„。ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã¯ã€æ ¼ç´ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã®åŠåˆ†ã‹ã‚‰4å€ç¨‹åº¦ã«ã™ã‚‹ã®ãŒã‚ˆã„。`dnum' ã¯è¦ç´ ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ•°ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ãŒä½¿ã‚れる。データベースファイルã®åˆ†å‰²æ•°ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã™ã‚‹æ™‚ã«æŒ‡å®šã—ãŸã‚‚ã®ã‹ã‚‰å¤‰æ›´ã™ã‚‹ã“ã¨ã¯ã§ããªã„。データベースファイルã®åˆ†å‰²æ•°ã®æœ€å¤§å€¤ã¯ 512 個ã§ã‚る。戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚‹ã‹ã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。ライタ(読ã¿æ›¸ã両用モード)ã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’é–‹ãéš›ã«ã¯ãã®ãƒ•ã‚¡ã‚¤ãƒ«ã«å¯¾ã—ã¦æŽ’他ロックãŒã‹ã‘られã€ãƒªãƒ¼ãƒ€ï¼ˆèª­ã¿è¾¼ã¿å°‚用モード)ã§é–‹ãéš›ã«ã¯å…±æœ‰ãƒ­ãƒƒã‚¯ãŒã‹ã‘られる。ãã®éš›ã«ã¯è©²å½“ã®ãƒ­ãƒƒã‚¯ãŒã‹ã‘られるã¾ã§åˆ¶å¾¡ãŒãƒ–ロックã™ã‚‹ã€‚`CR_ONOLCK' を使ã†å ´åˆã€ã‚¢ãƒ—リケーションãŒæŽ’他制御ã®è²¬ä»»ã‚’è² ã†ã€‚
+
+ +

データベースã¨ã®æŽ¥ç¶šã‚’é–‰ã˜ã¦ãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `crclose' を用ã„る。

+ +
+
int crclose(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。データベースã®æ›´æ–°å†…容ã¯ã€æŽ¥ç¶šã‚’é–‰ã˜ãŸæ™‚点ã§åˆã‚ã¦ãƒ•ã‚¡ã‚¤ãƒ«ã¨åŒæœŸã•ã‚Œã‚‹ã€‚ライタã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã„ãŸå ´åˆã€é©åˆ‡ã«æŽ¥ç¶šã‚’é–‰ã˜ãªã„ã¨ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãŒç ´å£Šã•ã‚Œã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã§ããªããªã‚‹ã€‚
+
+ +

レコードを追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `crput' を用ã„る。

+ +
+
int crput(CURIA *curia, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
+
`curia' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`vbuf' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`vsiz' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(vbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`dmode' ã¯ã‚­ãƒ¼ãŒæ—¢å­˜ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨é‡è¤‡ã—ãŸéš›ã®åˆ¶å¾¡ã‚’指定ã™ã‚‹ã€‚`CR_DOVER' ã¯æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’上書ãã—ã€`CR_DKEEP' ã¯æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’残ã—ã¦ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã—ã€`DP_DCAT' ã¯æŒ‡å®šã•ã‚ŒãŸå€¤ã‚’既存ã®å€¤ã®æœ«å°¾ã«åŠ ãˆã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

レコードを削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `crout' を用ã„る。

+ +
+
int crout(CURIA *curia, const char *kbuf, int ksiz);
+
`curia' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

レコードをå–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `crget' を用ã„る。

+ +
+
char *crget(CURIA *curia, const char *kbuf, int ksiz, int start, int max, int *sp);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`start' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹æœ€åˆã®ãƒã‚¤ãƒˆã®ã‚ªãƒ•ã‚»ãƒƒãƒˆã‚’指定ã™ã‚‹ã€‚`max' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ç„¡åˆ¶é™ã¨ãªã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚å–り出ãã†ã¨ã—ãŸå€¤ã®ã‚µã‚¤ã‚ºãŒ `start' よりå°ã•ã‹ã£ãŸå ´åˆã«ã¯è©²å½“ã¨ã¿ãªã•ãªã„。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

レコードをå–å¾—ã—ã¦ãƒãƒƒãƒ•ã‚¡ã«æ›¸ã込むã«ã¯ã€é–¢æ•° `crgetwb' を用ã„る。

+ +
+
int crgetwb(CURIA *curia, const char *kbuf, int ksiz, int start, int max, char *vbuf);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`start' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹æœ€åˆã®ãƒã‚¤ãƒˆã®ã‚ªãƒ•ã‚»ãƒƒãƒˆã‚’指定ã™ã‚‹ã€‚`max' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚ãã‚Œã¯æ›¸ãè¾¼ã¿ç”¨ã®ãƒãƒƒãƒ•ã‚¡ã®ã‚µã‚¤ã‚ºä»¥ä¸‹ã§ã‚ã‚‹å¿…è¦ãŒã‚る。`vbuf' ã¯æŠ½å‡ºã—ãŸãƒ‡ãƒ¼ã‚¿ã‚’書ã込むãƒãƒƒãƒ•ã‚¡ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒãƒƒãƒ•ã‚¡ã«æ›¸ãè¾¼ã¾ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ã®ã‚µã‚¤ã‚ºã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ -1 ã‚’è¿”ã™ã€‚å–り出ãã†ã¨ã—ãŸå€¤ã®ã‚µã‚¤ã‚ºãŒ `start' よりå°ã•ã‹ã£ãŸå ´åˆã«ã¯è©²å½“ã¨ã¿ãªã•ãªã„。書ãè¾¼ã¿ç”¨ãƒãƒƒãƒ•ã‚¡ã®æœ«å°¾ã«çµ‚端文字ãŒè¿½åŠ ã•ã‚Œãªã„ã“ã¨ã«æ³¨æ„ã™ã¹ãã§ã‚る。
+
+ +

レコードã®å€¤ã®ã‚µã‚¤ã‚ºã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `crvsiz' を用ã„る。

+ +
+
int crvsiz(CURIA *curia, const char *kbuf, int ksiz);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯è©²å½“レコードã®å€¤ã®ã‚µã‚¤ã‚ºã§ã‚ã‚‹ãŒã€è©²å½“ãŒãªã„å ´åˆã‚„エラーã®å ´åˆã¯ -1 ã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æœ‰ç„¡ã‚’調ã¹ã‚‹ã®ã«ã‚‚便利ã§ã‚る。`crget' ã¨é•ã£ã¦å®Ÿãƒ‡ãƒ¼ã‚¿ã‚’読ã¿è¾¼ã¾ãªã„ã®ã§åŠ¹çŽ‡ãŒã‚ˆã„。
+
+ +

データベースã®ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‚’åˆæœŸåŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `criterinit' を用ã„る。

+ +
+
int criterinit(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。イテレータã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã•ã‚ŒãŸå…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å‚ç…§ã™ã‚‹ãŸã‚ã«ç”¨ã„られる。
+
+ +

データベースã®ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‹ã‚‰æ¬¡ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã‚’å–り出ã™ã«ã¯ã€é–¢æ•° `criternext' を用ã„る。

+ +
+
char *criternext(CURIA *curia, int *sp);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ã‚­ãƒ¼ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。イテレータãŒæœ€å¾Œã¾ã§ãã¦è©²å½“ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã‚’ç¹°ã‚Šè¿”ã—ã¦å‘¼ã¶ã“ã¨ã«ã‚ˆã£ã¦å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’一度ãšã¤å‚ç…§ã™ã‚‹ã“ã¨ãŒã§ãる。ãŸã ã—ã€ç¹°ã‚Šè¿”ã—ã®é–“ã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ›´æ–°ãŒã‚ã£ãŸå ´åˆã¯ãã®é™ã‚Šã§ã¯ãªã„。ãªãŠã€å–り出ã™ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é †åºã¯åˆ¶å¾¡ã§ããšã€æ ¼ç´ã—ãŸé †ç•ªã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å–り出ã›ã‚‹ã¨ã¯é™ã‚‰ãªã„。
+
+ +

データベースã®ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã‚’設定ã™ã‚‹ã«ã¯ã€é–¢æ•° `crsetalign' を用ã„る。

+ +
+
int crsetalign(CURIA *curia, int align);
+
`curia' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`align' ã¯ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。アラインメントを設定ã—ã¦ãŠãã¨ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ä¸Šæ›¸ãã‚’é »ç¹ã«ã™ã‚‹å ´åˆã®å‡¦ç†åŠ¹çŽ‡ãŒè‰¯ããªã‚‹ã€‚アラインメントã«ã¯ã€ä¸€é€£ã®æ›´æ–°æ“作をã—ãŸå¾Œã®çŠ¶æ…‹ã§ã®æ¨™æº–çš„ãªå€¤ã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã®ãŒã‚ˆã„。アラインメントãŒæ­£æ•°ã®å ´åˆã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é ˜åŸŸã®ã‚µã‚¤ã‚ºãŒã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã®å€æ•°ã«ãªã‚‹ã‚ˆã†ã«ãƒ‘ディングãŒã¨ã‚‰ã‚Œã‚‹ã€‚アラインメントãŒè² æ•°ã®å ´åˆã€`vsiz' を値ã®ã‚µã‚¤ã‚ºã¨ã—ã¦ã€ãƒ‘ディングã®ã‚µã‚¤ã‚ºã¯ `(vsiz / pow(2, abs(align) - 1))' ã¨ã—ã¦ç®—出ã•ã‚Œã‚‹ã€‚アラインメントã®è¨­å®šã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ä¿å­˜ã•ã‚Œãªã„ã®ã§ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã度ã«æŒ‡å®šã™ã‚‹å¿…è¦ãŒã‚る。
+
+ +

データベースã®ãƒ•ãƒªãƒ¼ãƒ–ロックプールã®ã‚µã‚¤ã‚ºè¨­å®šã™ã‚‹ã«ã¯ã€é–¢æ•° `crsetfbpsiz' を用ã„る。

+ +
+
int crsetfbpsiz(CURIA *curia, int size);
+
`curia' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãƒ•ãƒªãƒ¼ãƒ–ロックプールã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。フリーブロックプールã®ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã®ã‚µã‚¤ã‚ºã¯16ã§ã‚る。サイズをより大ããã™ã‚‹ã¨ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ä¸Šæ›¸ãã‚’ç¹°ã‚Šè¿”ã™éš›ã®ç©ºé–“効率ã¯ä¸ŠãŒã‚‹ãŒã€æ™‚間効率ãŒä¸‹ãŒã‚‹ã€‚
+
+ +

データベースを更新ã—ãŸå†…容をファイルã¨ãƒ‡ãƒã‚¤ã‚¹ã«åŒæœŸã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `crsync' を用ã„る。

+ +
+
int crsync(CURIA *curia);
+
`curia' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‰ã˜ãªã„ã†ã¡ã«åˆ¥ãƒ—ロセスã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’利用ã•ã›ã‚‹å ´åˆã«å½¹ç«‹ã¤ã€‚
+
+ +

データベースを最é©åŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `croptimize' を用ã„る。

+ +
+
int croptimize(CURIA *curia, int bnum);
+
`curia' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`bnum' ã¯æ–°ãŸãªãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰ç¾åœ¨ã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã«æœ€é©ãªå€¤ãŒæŒ‡å®šã•ã‚Œã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。レコードを削除ã—ãŸã‚Šã€ç½®æ›ãƒ¢ãƒ¼ãƒ‰ã‚„連çµãƒ¢ãƒ¼ãƒ‰ã§æ›¸ãè¾¼ã¿ã‚’ç¹°ã‚Šè¿”ã—ãŸã‚Šã™ã‚‹å ´åˆã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹å†…ã«ä¸è¦ãªé ˜åŸŸãŒè“„ç©ã™ã‚‹ãŒã€ã“ã®é–¢æ•°ã¯ãれを解消ã™ã‚‹ã®ã«å½¹ç«‹ã¤ã€‚
+
+ +

データベースã®åå‰ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `crname' を用ã„る。

+ +
+
char *crname(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰åå‰ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

データベースファイルã®ã‚µã‚¤ã‚ºã®åˆè¨ˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `crfsiz' を用ã„る。

+ +
+
int crfsiz(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºã®åˆè¨ˆã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。戻り値ãŒ2GBを越ãˆãŸå ´åˆã¯æ¡æº¢ã‚ŒãŒèµ·ã“る。
+
+ +

データベースファイルã®ã‚µã‚¤ã‚ºã®åˆè¨ˆã‚’å€ç²¾åº¦æµ®å‹•å°æ•°ã¨ã—ã¦å¾—ã‚‹ã«ã¯ã€é–¢æ•° `crfsizd' を用ã„る。

+ +
+
double crfsizd(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºã®åˆè¨ˆã®å€ç²¾åº¦å€¤ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

データベースã®ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã®åˆè¨ˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `crbnum' を用ã„る。

+ +
+
int crbnum(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã®åˆè¨ˆã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

データベースã®ãƒã‚±ãƒƒãƒˆé…列ã®åˆ©ç”¨æ¸ˆã¿ã®è¦ç´ æ•°ã®åˆè¨ˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `crbusenum' を用ã„る。

+ +
+
int crbusenum(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒã‚±ãƒƒãƒˆé…列ã®åˆ©ç”¨æ¸ˆã¿ã®è¦ç´ æ•°ã®åˆè¨ˆã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒã‚±ãƒƒãƒˆé…列ã®å…¨ã¦ã®è¦ç´ ã‚’å‚ç…§ã™ã‚‹ã®ã§ã€åŠ¹çŽ‡ãŒæ‚ªã„。
+
+ +

データベースã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `crrnum' を用ã„る。

+ +
+
int crrnum(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

データベースãƒãƒ³ãƒ‰ãƒ«ãŒãƒ©ã‚¤ã‚¿ã‹ã©ã†ã‹ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `crwritable' を用ã„る。

+ +
+
int crwritable(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ©ã‚¤ã‚¿ãªã‚‰çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

データベースã«è‡´å‘½çš„エラーãŒèµ·ããŸã‹ã©ã†ã‹ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `crfatalerror' を用ã„る。

+ +
+
int crfatalerror(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯è‡´å‘½çš„エラーãŒã‚ã‚Œã°çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

データベースディレクトリã®inode番å·ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `crinode' を用ã„る。

+ +
+
int crinode(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®inode番å·ã§ã‚る。
+
+ +

データベースã®æœ€çµ‚更新時刻を得るã«ã¯ã€é–¢æ•° `crmtime' を用ã„る。

+ +
+
time_t crmtime(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æœ€çµ‚更新時刻ã§ã‚る。
+
+ +

データベースディレクトリを削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `crremove' を用ã„る。

+ +
+
int crremove(const char *name);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

壊れãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’修復ã™ã‚‹ã«ã¯ã€é–¢æ•° `crrepair' を用ã„る。

+ +
+
int crrepair(const char *name);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。修復ã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å…¨ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒå…ƒæ¥ã‚‚ã—ãã¯æœŸå¾…ã•ã‚Œã‚‹çŠ¶æ…‹ã«æˆ»ã‚‹ä¿è¨¼ã¯ãªã„。
+
+ +

å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’エンディアンéžä¾å­˜ã®ãƒ‡ãƒ¼ã‚¿ã¨ã—ã¦ãƒ€ãƒ³ãƒ—ã™ã‚‹ã«ã¯ã€é–¢æ•° `crexportdb' を用ã„る。

+ +
+
int crexportdb(CURIA *curia, const char *name);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`name' ã¯å‡ºåŠ›ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

エンディアンéžä¾å­˜ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’ロードã™ã‚‹ã«ã¯ã€é–¢æ•° `crimportdb' を用ã„る。

+ +
+
int crimportdb(CURIA *curia, const char *name);
+
`curia' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚データベースã¯ç©ºã§ãªã‘ã‚Œã°ãªã‚‰ãªã„。`name' ã¯å…¥åŠ›ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

データベースディレクトリã‹ã‚‰ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’直接å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `crsnaffle' を用ã„る。

+ +
+
char *crsnaffle(const char *name, const char *kbuf, int ksiz, int *sp);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®åå‰ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`start' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹æœ€åˆã®ãƒã‚¤ãƒˆã®ã‚ªãƒ•ã‚»ãƒƒãƒˆã‚’指定ã™ã‚‹ã€‚`max' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ç„¡åˆ¶é™ã¨ãªã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚å–り出ãã†ã¨ã—ãŸå€¤ã®ã‚µã‚¤ã‚ºãŒ `start' よりå°ã•ã‹ã£ãŸå ´åˆã«ã¯è©²å½“ã¨ã¿ãªã•ãªã„。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªãŒåˆ¥ã®ãƒ—ロセスã«ãƒ­ãƒƒã‚¯ã•ã‚Œã¦ã„ã¦ã‚‚利用ã§ãã‚‹ãŒã€æœ€æ–°ã®æ›´æ–°ãŒå映ã•ã‚Œã¦ã„ã‚‹ä¿è¨¼ã¯ãªã„。
+
+ +

ラージオブジェクト用データベースã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `crputlob' を用ã„る。

+ +
+
int crputlob(CURIA *curia, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
+
`curia' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`vbuf' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`vsiz' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(vbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`dmode' ã¯ã‚­ãƒ¼ãŒæ—¢å­˜ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨é‡è¤‡ã—ãŸéš›ã®åˆ¶å¾¡ã‚’指定ã™ã‚‹ã€‚`CR_DOVER' ã¯æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’上書ãã—ã€`CR_DKEEP' ã¯æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’残ã—ã¦ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã—ã€`DP_DCAT' ã¯æŒ‡å®šã•ã‚ŒãŸå€¤ã‚’既存ã®å€¤ã®æœ«å°¾ã«åŠ ãˆã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

ラージオブジェクト用データベースã‹ã‚‰ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `croutlob' を用ã„る。

+ +
+
int croutlob(CURIA *curia, const char *kbuf, int ksiz);
+
`curia' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

ラージオブジェクト用データベースã‹ã‚‰ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `crgetlob' を用ã„る。

+ +
+
char *crgetlob(CURIA *curia, const char *kbuf, int ksiz, int start, int max, int *sp);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`start' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹æœ€åˆã®ãƒã‚¤ãƒˆã®ã‚ªãƒ•ã‚»ãƒƒãƒˆã‚’指定ã™ã‚‹ã€‚`max' ã¯å€¤ã®é ˜åŸŸã‹ã‚‰æŠ½å‡ºã™ã‚‹ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ç„¡åˆ¶é™ã¨ãªã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚å–り出ãã†ã¨ã—ãŸå€¤ã®ã‚µã‚¤ã‚ºãŒ `start' よりå°ã•ã‹ã£ãŸå ´åˆã«ã¯è©²å½“ã¨ã¿ãªã•ãªã„。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

ラージオブジェクト用データベースã«ã‚るレコードã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `crgetlobfd' を用ã„る。

+ +
+
int crgetlobfd(CURIA *curia, const char *kbuf, int ksiz);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰è©²å½“ã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ -1 ã‚’è¿”ã™ã€‚戻り値ã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—タ㯠`open' コールã§é–‹ã‹ã‚Œã‚‹ã€‚データベースãŒãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã•ã‚ŒãŸå ´åˆã¯ãã®ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã¯æ›¸ãè¾¼ã¿å¯èƒ½ï¼ˆO_RDWR)ã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°æ›¸ãè¾¼ã¿ä¸å¯èƒ½ï¼ˆO_RDONLY)ã§ã‚る。ディスクリプタãŒä¸è¦ã«ãªã£ãŸã‚‰ `close' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

ラージオブジェクト用データベースã«ã‚るレコードã®å€¤ã®ã‚µã‚¤ã‚ºã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `crvsizlob' を用ã„る。

+ +
+
int crvsizlob(CURIA *curia, const char *kbuf, int ksiz);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯è©²å½“レコードã®å€¤ã®ã‚µã‚¤ã‚ºã§ã‚ã‚Šã€è©²å½“ãŒãªã„å ´åˆã‚„エラーã®å ´åˆã¯ -1 ã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æœ‰ç„¡ã‚’調ã¹ã‚‹ã®ã«ã‚‚便利ã§ã‚る。`crgetlob' ã¨é•ã£ã¦å®Ÿãƒ‡ãƒ¼ã‚¿ã‚’読ã¿è¾¼ã¾ãªã„ã®ã§åŠ¹çŽ‡ãŒã‚ˆã„。
+
+ +

ラージオブジェクト用データベースã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã®åˆè¨ˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `crrnumlob' を用ã„る。

+ +
+
int crrnumlob(CURIA *curia);
+
`curia' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã®åˆè¨ˆã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

サンプルコード

+ +

åå‰ã¨å¯¾å¿œã•ã›ã¦é›»è©±ç•ªå·ã‚’æ ¼ç´ã—ã€ãれを検索ã™ã‚‹ã‚¢ãƒ—リケーションã®ã‚µãƒ³ãƒ—ルコードを以下ã«ç¤ºã™ã€‚

+ +
#include <depot.h>
+#include <curia.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define NAME     "mikio"
+#define NUMBER   "000-1234-5678"
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  CURIA *curia;
+  char *val;
+
+  /* データベースを開ã */
+  if(!(curia = cropen(DBNAME, CR_OWRITER | CR_OCREAT, -1, -1))){
+    fprintf(stderr, "cropen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* レコードを格ç´ã™ã‚‹ */
+  if(!crput(curia, NAME, -1, NUMBER, -1, CR_DOVER)){
+    fprintf(stderr, "crput: %s\n", dperrmsg(dpecode));
+  }
+
+  /* レコードをå–å¾—ã™ã‚‹ */
+  if(!(val = crget(curia, NAME, -1, 0, -1, NULL))){
+    fprintf(stderr, "crget: %s\n", dperrmsg(dpecode));
+  } else {
+    printf("Name: %s\n", NAME);
+    printf("Number: %s\n", val);
+    free(val);
+  }
+
+  /* データベースを閉ã˜ã‚‹ */
+  if(!crclose(curia)){
+    fprintf(stderr, "crclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

データベースã®å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’表示ã™ã‚‹ã‚¢ãƒ—リケーションã®ã‚µãƒ³ãƒ—ルコードを以下ã«ç¤ºã™ã€‚

+ +
#include <depot.h>
+#include <curia.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  CURIA *curia;
+  char *key, *val;
+
+  /* データベースを開ã */
+  if(!(curia = cropen(DBNAME, CR_OREADER, -1, -1))){
+    fprintf(stderr, "cropen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* イテレータをåˆæœŸåŒ–ã™ã‚‹ */
+  if(!criterinit(curia)){
+    fprintf(stderr, "criterinit: %s\n", dperrmsg(dpecode));
+  }
+
+  /* イテレータを走査ã™ã‚‹ */
+  while((key = criternext(curia, NULL)) != NULL){
+    if(!(val = crget(curia, key, -1, 0, -1, NULL))){
+      fprintf(stderr, "crget: %s\n", dperrmsg(dpecode));
+      free(key);
+      break;
+    }
+    printf("%s: %s\n", key, val);
+    free(val);
+    free(key);
+  }
+
+  /* データベースを閉ã˜ã‚‹ */
+  if(!crclose(curia)){
+    fprintf(stderr, "crclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

注記

+ +

Curiaを利用ã—ãŸãƒ—ログラムをビルドã™ã‚‹æ–¹æ³•ã¯ã€Depotã®å ´åˆã¨å…¨ãåŒã˜ã§ã‚る。

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

POSIXスレッドを有効ã«ã—ã¦QDBMをビルドã—ãŸå ´åˆã€å¤–部変数 `dpecode' ã¯ã‚¹ãƒ¬ãƒƒãƒ‰å›ºæœ‰ãƒ‡ãƒ¼ã‚¿ã¸ã®å‚ç…§ã¨ã—ã¦æ‰±ã‚ã‚Œã€Curiaã®å„関数ã¯ãƒªã‚¨ãƒ³ãƒˆãƒ©ãƒ³ãƒˆã«ãªã‚‹ã€‚ãã®å ´åˆã€ã‚¹ãƒ¬ãƒƒãƒ‰é–“ã§åŒæ™‚ã«åŒã˜ãƒãƒ³ãƒ‰ãƒ«ã«ã‚¢ã‚¯ã‚»ã‚¹ã—ãªã„é™ã‚Šã¯ã€å„関数ã¯ã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ã§ã‚る。ãŸã ã—ã€`errno' ã‚„ `malloc' ç­‰ãŒã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ãªå‡¦ç†ç³»ã§ã‚ã‚‹ã“ã¨ãŒå‰æã¨ãªã‚‹ã€‚

+ +
+ +

Curia用コマンド

+ +

Curiaã«å¯¾å¿œã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ãƒ©ã‚¤ãƒ³ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ã¯ä»¥ä¸‹ã®ã‚‚ã®ã§ã‚る。

+ +

コマンド `crmgr' ã¯Curiaã‚„ãã®ã‚¢ãƒ—リケーションã®ãƒ‡ãƒãƒƒã‚°ã«å½¹ç«‹ã¤ãƒ„ールã§ã‚る。データベースを更新ã—ãŸã‚Šã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®çŠ¶æ…‹ã‚’調ã¹ãŸã‚Šã™ã‚‹æ©Ÿèƒ½ã‚’æŒã¤ã€‚シェルスクリプトã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚¢ãƒ—リケーションを作るã®ã«ã‚‚利用ã§ãる。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`key' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã€`val' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’指定ã™ã‚‹ã€‚

+ +
+
crmgr create [-s] [-bnum num] [-dnum num] name
+
データベースディレクトリを作æˆã™ã‚‹ã€‚
+
crmgr put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat] [-lob] [-na] name key val
+
キーã¨å€¤ã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã™ã‚‹ã€‚
+
crmgr out [-kx|-ki] [-lob] name key
+
キーã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã™ã‚‹ã€‚
+
crmgr get [-nl] [-kx|-ki] [-start num] [-max num] [-ox] [-lob] [-n] name key
+
キーã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’å–å¾—ã—ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
crmgr list [-nl] [-k|-v] [-ox] name
+
データベース内ã®å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã¨å€¤ã‚’タブã¨æ”¹è¡Œã§åŒºåˆ‡ã£ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
crmgr optimize [-bnum num] [-na] name
+
データベースを最é©åŒ–ã™ã‚‹ã€‚
+
crmgr inform [-nl] name
+
データベースã®é›‘多ãªæƒ…報を出力ã™ã‚‹ã€‚
+
crmgr remove name
+
データベースディレクトリを削除ã™ã‚‹ã€‚
+
crmgr repair name
+
壊れãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’修復ã™ã‚‹ã€‚
+
crmgr exportdb name dir
+
å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’エンディアンéžä¾å­˜ã®ãƒ‡ãƒ¼ã‚¿ã¨ã—ã¦ãƒ€ãƒ³ãƒ—ã™ã‚‹ã€‚
+
crmgr importdb [-bnum num] [-dnum num] name dir
+
エンディアンéžä¾å­˜ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’ロードã™ã‚‹ã€‚
+
crmgr snaffle [-kx|-ki] [-ox] [-n] name key
+
ロックã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‹ã‚‰ã‚­ãƒ¼ã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’å–å¾—ã—ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
crmgr version
+
QDBMã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³æƒ…報を標準出力ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -s : ファイルをスパースã«ã™ã‚‹ã€‚
  • +
  • -bnum num : ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã‚’ `num' ã«æŒ‡å®šã™ã‚‹ã€‚
  • +
  • -dnum num : データベースファイルã®åˆ†å‰²æ•°ã‚’ `num' ã«æŒ‡å®šã™ã‚‹ã€‚
  • +
  • -kx : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—㦠`key' を扱ã†ã€‚
  • +
  • -ki : 10進数ã«ã‚ˆã‚‹æ•°å€¤è¡¨ç¾ã¨ã—㦠`key' を扱ã†ã€‚
  • +
  • -vx : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—㦠`val' を扱ã†ã€‚
  • +
  • -vi : 10進数ã«ã‚ˆã‚‹æ•°å€¤è¡¨ç¾ã¨ã—㦠`val' を扱ã†ã€‚
  • +
  • -vf : åå‰ãŒ `val' ã®ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ‡ãƒ¼ã‚¿ã‚’値ã¨ã—ã¦èª­ã¿è¾¼ã‚€ã€‚
  • +
  • -keep : 既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã‚­ãƒ¼ãŒé‡è¤‡æ™‚ã«ä¸Šæ›¸ãã›ãšã«ã‚¨ãƒ©ãƒ¼ã«ã™ã‚‹ã€‚
  • +
  • -cat : 既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã‚­ãƒ¼ãŒé‡è¤‡æ™‚ã«å€¤ã‚’末尾ã«è¿½åŠ ã™ã‚‹ã€‚
  • +
  • -na : アラインメントを設定ã—ãªã„。
  • +
  • -nl : ファイルロックをã‹ã‘ãšã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã。
  • +
  • -start : 値ã‹ã‚‰å–り出ã™ãƒ‡ãƒ¼ã‚¿ã®é–‹å§‹ã‚ªãƒ•ã‚»ãƒƒãƒˆã‚’指定ã™ã‚‹ã€‚
  • +
  • -max : 値ã‹ã‚‰å–り出ã™ãƒ‡ãƒ¼ã‚¿ã®æœ€å¤§ã®é•·ã•ã‚’指定ã™ã‚‹ã€‚
  • +
  • -ox : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—ã¦æ¨™æº–出力を行ã†ã€‚
  • +
  • -lob : ラージオブジェクトを扱ã†ã€‚
  • +
  • -n : 標準出力ã®æœ«å°¾ã«ä»˜åŠ ã•ã‚Œã‚‹æ”¹è¡Œæ–‡å­—ã®å‡ºåŠ›ã‚’抑制ã™ã‚‹ã€‚
  • +
  • -k : キーã®ã¿ã‚’出力ã™ã‚‹ã€‚
  • +
  • -v : 値ã®ã¿ã‚’出力ã™ã‚‹ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚環境変数 `QDBMDBGFD' ã®å€¤ã¨ã—ã¦ã€å¤‰æ•° `dpecode' ã®å¤‰æ›´å±¥æ­´ã‚’出力ã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—タを指定ã“ã¨ãŒã§ãる。

+ +

コマンド `crtest' ã¯Curiaã®æ©Ÿèƒ½ãƒ†ã‚¹ãƒˆã‚„性能テストã«ç”¨ã„るツールã§ã‚る。`crtest' ã«ã‚ˆã£ã¦ç”Ÿæˆã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’ `crmgr' ã«ã‚ˆã£ã¦è§£æžã—ãŸã‚Šã€`time' コマンドã«ã‚ˆã£ã¦ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã®å®Ÿè¡Œæ™‚間を計ã£ãŸã‚Šã™ã‚‹ã¨ã‚ˆã„。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`rnum' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã€`bnum' ã¯ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã€`dnum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®åˆ†å‰²æ•°ã€`pnum' ã¯ã‚­ãƒ¼ã®ãƒ‘ターン数ã€`align' ã¯ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã®åŸºæœ¬ã‚µã‚¤ã‚ºã€`fbpsiz' ã¯ãƒ•ãƒªãƒ¼ãƒ–ロックプールã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚

+ +
+
crtest write [-s] [-lob] name rnum bnum dnum
+
`00000001'ã€`00000002' ã®ã‚ˆã†ã«å¤‰åŒ–ã™ã‚‹8ãƒã‚¤ãƒˆã®ã‚­ãƒ¼ã¨é©å½“ãª8ãƒã‚¤ãƒˆã®å€¤ã‚’連続ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«è¿½åŠ ã™ã‚‹ã€‚
+
crtest read [-wb] [-lob] name
+
上記ã§ç”Ÿæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å…¨ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã™ã‚‹ã€‚
+
crtest rcat [-c] name rnum bnum dnum pnum align fbpsiz
+
キーãŒã‚る程度é‡è¤‡ã™ã‚‹ã‚ˆã†ã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã®è¿½åŠ ã‚’è¡Œã„ã€é€£çµãƒ¢ãƒ¼ãƒ‰ã§å‡¦ç†ã™ã‚‹ã€‚
+
crtest combo name
+
å„種æ“作ã®çµ„ã¿åˆã‚ã›ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚
+
crtest wicked [-c] name rnum
+
å„種更新æ“作を無作為ã«é¸æŠžã—ã¦å®Ÿè¡Œã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -s : ファイルをスパースã«ã™ã‚‹ã€‚
  • +
  • -lob : ラージオブジェクトを扱ã†ã€‚
  • +
  • -wb : 関数 `crget' ã®ä»£ã‚ã‚Šã«é–¢æ•° `crgetwb' を用ã„る。
  • +
  • -c : Cabinã®ãƒžãƒƒãƒ—を使ã£ã¦æ¯”較テストを行ã†ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚環境変数 `QDBMDBGFD' ã®å€¤ã¨ã—ã¦ã€å¤‰æ•° `dpecode' ã®å¤‰æ›´å±¥æ­´ã‚’出力ã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—タを指定ã“ã¨ãŒã§ãる。

+ +

コマンド `crtsv' ã¯ã‚¿ãƒ–区切りã§ã‚­ãƒ¼ã¨å€¤ã‚’表ç¾ã—ãŸè¡Œã‹ã‚‰ãªã‚‹TSVファイルã¨Curiaã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’相互変æ›ã™ã‚‹ã€‚ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã€QDBMã®ä»–ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã‚„ä»–ã®DBMã¨ã®é–“ã§ãƒ‡ãƒ¼ã‚¿ã®äº¤æ›ã‚’è¡Œã†éš›ã«å½¹ç«‹ã¤ã€‚ã¾ãŸã€ãƒã‚¤ãƒˆã‚ªãƒ¼ãƒ€ã®é•ã†ã‚·ã‚¹ãƒ†ãƒ ã®é–“ã§ãƒ‡ãƒ¼ã‚¿ã‚’交æ›ã™ã‚‹éš›ã«ã‚‚役立ã¤ã€‚以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åを指定ã™ã‚‹ã€‚`export' サブコマンドã§ã¯TSVã®ãƒ‡ãƒ¼ã‚¿ã¯æ¨™æº–入力ã‹ã‚‰èª­ã¿è¾¼ã‚€ã€‚キーãŒé‡è¤‡ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã¯å¾Œè€…を優先ã™ã‚‹ã€‚`-bnum' オプションã®å¼•æ•° `num' ã¯ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`-dnum' オプションã®å¼•æ•° `num' ã¯è¦ç´ ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ•°ã‚’指定ã™ã‚‹ã€‚`import' サブコマンドã§ã¯TSVã®ãƒ‡ãƒ¼ã‚¿ãŒæ¨™æº–出力ã«æ›¸ã出ã•ã‚Œã‚‹ã€‚

+ +
+
crtsv import [-bnum num] [-dnum num] [-bin] name
+
TSVファイルを読ã¿è¾¼ã‚“ã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã™ã‚‹ã€‚
+
crtsv export [-bin] name
+
データベースã®å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’TSVファイルã¨ã—ã¦å‡ºåŠ›ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -bnum num : ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã‚’ `num' ã«æŒ‡å®šã™ã‚‹ã€‚
  • +
  • -dnum num : データベースファイルã®åˆ†å‰²æ•°ã‚’ `num' ã«æŒ‡å®šã™ã‚‹ã€‚
  • +
  • -bin : Base64å½¢å¼ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’扱ã†ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +

Curiaã®ã‚³ãƒžãƒ³ãƒ‰ç¾¤ã‚’駆使ã™ã‚‹ã¨ã€ç°¡å˜ãªãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚·ã‚¹ãƒ†ãƒ ãŒæ§‹ç¯‰ã§ãる。例ãˆã° `/etc/password' をユーザåã§æ¤œç´¢ã™ã‚‹ãŸã‚ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã™ã‚‹ã«ã¯ã€ä»¥ä¸‹ã®ã‚ˆã†ã«ã™ã‚‹ã€‚

+ +
cat /etc/passwd | tr ':' '\t' | crtsv import casket
+
+ +

ãã—ã¦ã€`mikio' ã¨ã„ã†ãƒ¦ãƒ¼ã‚¶ã®æƒ…報をå–り出ã™ã«ã¯ã€ä»¥ä¸‹ã®ã‚ˆã†ã«ã™ã‚‹ã€‚

+ +
crmgr get casket mikio
+
+ +

ã“れらã®ã‚³ãƒžãƒ³ãƒ‰ã¨åŒç­‰ã®æ©Ÿèƒ½ã‚’Curiaã®APIを用ã„ã¦å®Ÿè£…ã™ã‚‹ã“ã¨ã‚‚容易ã§ã‚る。

+ +
+ +

Relic: NDBM互æ›API

+ +

概è¦

+ +

Relicã¯ã€NDBMã¨äº’æ›ã™ã‚‹APIã§ã‚る。ã™ãªã‚ã¡ã€Depotã®é–¢æ•°ç¾¤ã‚’NDBMã®APIã§åŒ…ã‚“ã ã‚‚ã®ã§ã‚る。Relicを使ã£ã¦NDBMã®ã‚¢ãƒ—リケーションをQDBMã«ç§»æ¤ã™ã‚‹ã®ã¯ãŸã‚„ã™ã„。ã»ã¨ã‚“ã©ã®å ´åˆã€ã‚¤ãƒ³ã‚¯ãƒ«ãƒ¼ãƒ‰ã™ã‚‹ãƒ˜ãƒƒãƒ€ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ `ndbm.h' ã‹ã‚‰ `relic.h' ã«æ›ãˆã€ãƒ“ルドã®éš›ã®ãƒªãƒ³ã‚«ã‚ªãƒ—ションを `-lndbm' ã‹ã‚‰ `-lqdbm' ã«æ›ãˆã‚‹ã ã‘ã§ã‚ˆã„。

+ +

オリジナルã®NDBMã§ã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¯äºŒã¤ã®ãƒ•ã‚¡ã‚¤ãƒ«ã®å¯¾ã‹ã‚‰ãªã‚‹ã€‚ã²ã¨ã¤ã¯æŽ¥å°¾è¾žã« `.dir' ãŒã¤ãåå‰ã§ã€ã‚­ãƒ¼ã®ãƒ“ットマップを格ç´ã™ã‚‹ã€Œãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªãƒ•ã‚¡ã‚¤ãƒ«ã€ã§ã‚る。もã†ã²ã¨ã¤ã¯æŽ¥å°¾è¾žã« `.pag' ãŒã¤ãåå‰ã§ã€ãƒ‡ãƒ¼ã‚¿ã®å®Ÿä½“ã‚’æ ¼ç´ã™ã‚‹ã€Œãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ã€ã§ã‚る。Relicã§ã¯ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªãƒ•ã‚¡ã‚¤ãƒ«ã¯å˜ãªã‚‹ãƒ€ãƒŸãƒ¼ã¨ã—ã¦ä½œæˆã—ã€ãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ã‚’データベースã¨ã™ã‚‹ã€‚Relicã§ã¯ã‚ªãƒªã‚¸ãƒŠãƒ«ã®NDBMã¨é•ã„ã€æ ¼ç´ã™ã‚‹ãƒ‡ãƒ¼ã‚¿ã®ã‚µã‚¤ã‚ºã«åˆ¶é™ã¯ãªã„。ãªãŠã€ã‚ªãƒªã‚¸ãƒŠãƒ«ã®NDBMã§ç”Ÿæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’Relicã§æ‰±ã†ã“ã¨ã¯ã§ããªã„。

+ +

Relicを使ã†ãŸã‚ã«ã¯ã€`relic.h' 㨠`stdlib.h' 㨠`sys/types.h' 㨠`sys/stat.h' 㨠`fcntl.h' をインクルードã™ã¹ãã§ã‚る。通常ã€ã‚½ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®å†’頭付近ã§ä»¥ä¸‹ã®è¨˜è¿°ã‚’è¡Œã†ã€‚

+ +
+
#include <relic.h>
+
#include <stdlib.h>
+
#include <sys/types.h>
+
#include <sys/stat.h>
+
#include <fcntl.h>
+
+ +

Relicã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†éš›ã«ã¯ã€`DBM' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `dbm_open' ã§é–‹ãã€é–¢æ•° `dbm_close' ã§é–‰ã˜ã‚‹ã€‚ãƒãƒ³ãƒ‰ãƒ«ã®ãƒ¡ãƒ³ãƒã‚’直接å‚ç…§ã™ã‚‹ã“ã¨ã¯æŽ¨å¥¨ã•ã‚Œãªã„。

+ +

API

+ +

データã®æ ¼ç´ã€å‰Šé™¤ã€æ¤œç´¢ã«ç”¨ã„る関数ã¨ã®ãƒ‡ãƒ¼ã‚¿ã®æŽˆå—ã«ã¯ã€ã‚­ãƒ¼ã¨å€¤ã‚’表ç¾ã™ã‚‹ã®ã« `datum' åž‹ã®æ§‹é€ ä½“を用ã„る。

+ +
+
typedef struct { void *dptr; size_t dsize; } datum;
+
`dptr' ã¯ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。`dsize' ã¯ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã§ã‚る。
+
+ +

データベースã®ãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `dbm_open' を用ã„る。

+ +
+
DBM *dbm_open(char *name, int flags, int mode);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®åå‰ã‚’指定ã™ã‚‹ãŒã€ãƒ•ã‚¡ã‚¤ãƒ«åã¯ãã‚Œã«æŽ¥å°¾è¾žã‚’ã¤ã‘ãŸã‚‚ã®ã«ãªã‚‹ã€‚`flags' 㯠`open' コールã«æ¸¡ã™ã‚‚ã®ã¨åŒã˜ã ãŒã€`O_WRONLY' 㯠`O_RDWR' ã¨åŒã˜ã«ãªã‚Šã€è¿½åŠ ãƒ•ãƒ©ã‚°ã§ã¯ `O_CREAT' 㨠`O_TRUNC' ã®ã¿ãŒæœ‰åŠ¹ã§ã‚る。`mode' 㯠`open' コールã«æ¸¡ã™ã‚‚ã®ã¨åŒã˜ã§ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ¢ãƒ¼ãƒ‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。
+
+ +

データベースã¨ã®æŽ¥ç¶šã‚’é–‰ã˜ã¦ãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `dbm_close' を用ã„る。

+ +
+
void dbm_close(DBM *db);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ããªããªã‚‹ã€‚
+
+ +

レコードを追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `dbm_store' を用ã„る。

+ +
+
int dbm_store(DBM *db, datum key, datum content, int flags);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`key' ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“を指定ã™ã‚‹ã€‚`content' ã¯å€¤ã®æ§‹é€ ä½“を指定ã™ã‚‹ã€‚`frags' ㌠`DBM_INSERT' ãªã‚‰ã‚­ãƒ¼ã®é‡è¤‡æ™‚ã«æ›¸ãè¾¼ã¿ã‚’断念ã—ã€`DBM_REPLACE' ãªã‚‰ä¸Šæ›¸ãã‚’è¡Œã†ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ 0 ã§ã‚ã‚Šã€é‡è¤‡ã§ã®æ–­å¿µãªã‚‰ 1 ã§ã‚ã‚Šã€ãã®ä»–ã®ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

レコードを削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `dbm_delete' を用ã„る。

+ +
+
int dbm_delete(DBM *db, datum key);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`key' ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“を指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ 0 ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

レコードをå–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `dbm_fetch' を用ã„る。

+ +
+
datum dbm_fetch(DBM *db, datum key);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`key' ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“を指定ã™ã‚‹ã€‚戻り値ã¯å€¤ã®æ§‹é€ ä½“ã§ã‚る。該当ãŒã‚ã‚Œã°ãƒ¡ãƒ³ãƒ `dptr' ãŒãã®é ˜åŸŸã‚’指ã—ã€ãƒ¡ãƒ³ãƒ `dsize' ãŒãã®ã‚µã‚¤ã‚ºã‚’示ã™ã€‚該当ãŒãªã‘れ㰠`dptr' ã®å€¤ã¯ `NULL' ã¨ãªã‚‹ã€‚`dptr' ã®æŒ‡ã™é ˜åŸŸã¯ãƒãƒ³ãƒ‰ãƒ«ã«é–¢é€£ã¥ã‘られã¦ç¢ºä¿ã•ã‚Œã€åŒã˜ãƒãƒ³ãƒ‰ãƒ«ã«å¯¾ã—ã¦æ¬¡ã«ã“ã®é–¢æ•°ã‚’呼ã³å‡ºã™ã‹ã€ãƒãƒ³ãƒ‰ãƒ«ã‚’é–‰ã˜ã‚‹ã¾ã§ã€æœ‰åŠ¹ãªãƒ‡ãƒ¼ã‚¿ã‚’ä¿æŒã™ã‚‹ã€‚
+
+ +

最åˆã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dbm_firstkey' を用ã„る。

+ +
+
datum dbm_firstkey(DBM *db);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“ã§ã‚る。該当ãŒã‚ã‚Œã°ãƒ¡ãƒ³ãƒ `dptr' ãŒãã®é ˜åŸŸã‚’指ã—ã€`dsize' ãŒãã®ã‚µã‚¤ã‚ºã‚’示ã™ã€‚該当ãŒãªã‘れ㰠`dptr' ã®å€¤ã¯ `NULL' ã¨ãªã‚‹ã€‚`dptr' ã®æŒ‡ã™é ˜åŸŸã¯ãƒãƒ³ãƒ‰ãƒ«ã«é–¢é€£ã¥ã‘られã¦ç¢ºä¿ã•ã‚Œã€åŒã˜ãƒãƒ³ãƒ‰ãƒ«ã«å¯¾ã—ã¦æ¬¡ã«ã“ã®é–¢æ•°ã‚‚ã—ãã¯é–¢æ•° `dbm_nextkey' を呼ã³å‡ºã™ã‹ã€ãƒãƒ³ãƒ‰ãƒ«ã‚’é–‰ã˜ã‚‹ã¾ã§ã€æœ‰åŠ¹ãªãƒ‡ãƒ¼ã‚¿ã‚’ä¿æŒã™ã‚‹ã€‚
+
+ +

次レコードã®ã‚­ãƒ¼ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dbm_nextkey' を用ã„る。

+ +
+
datum dbm_nextkey(DBM *db);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“ã§ã‚る。該当ãŒã‚ã‚Œã°ãƒ¡ãƒ³ãƒ `dptr' ãŒãã®é ˜åŸŸã‚’指ã—ã€`dsize' ãŒãã®ã‚µã‚¤ã‚ºã‚’示ã™ã€‚該当ãŒãªã‘れ㰠`dptr' ã®å€¤ã¯ `NULL' ã¨ãªã‚‹ã€‚`dptr' ã®æŒ‡ã™é ˜åŸŸã¯ãƒãƒ³ãƒ‰ãƒ«ã«é–¢é€£ã¥ã‘られã¦ç¢ºä¿ã•ã‚Œã€åŒã˜ãƒãƒ³ãƒ‰ãƒ«ã«å¯¾ã—ã¦æ¬¡ã«ã“ã®é–¢æ•°ã‚‚ã—ãã¯é–¢æ•° `dbm_firstkey' を呼ã³å‡ºã™ã‹ã€ãƒãƒ³ãƒ‰ãƒ«ã‚’é–‰ã˜ã‚‹ã¾ã§ã€æœ‰åŠ¹ãªãƒ‡ãƒ¼ã‚¿ã‚’ä¿æŒã™ã‚‹ã€‚
+
+ +

データベースã«è‡´å‘½çš„エラーãŒèµ·ããŸã‹ã©ã†ã‹ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `dbm_error' を用ã„る。

+ +
+
int dbm_error(DBM *db);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯è‡´å‘½çš„エラーãŒã‚ã‚Œã°çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

関数 `dbm_clearerr' ã¯ä½•ã‚‚ã—ãªã„。

+ +
+
int dbm_clearerr(DBM *db);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値㯠0 ã§ã‚る。ã“ã®é–¢æ•°ã¯äº’æ›æ€§ã®ãŸã‚ã«ã®ã¿å­˜åœ¨ã™ã‚‹ã€‚
+
+ +

データベースãŒèª­ã¿è¾¼ã¿å°‚用ã‹ã©ã†ã‹ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `dbm_rdonly' を用ã„る。

+ +
+
int dbm_rdonly(DBM *db);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯èª­ã¿è¾¼ã¿å°‚用ãªã‚‰çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

ディレクトリファイルã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dbm_dirfno' を用ã„る。

+ +
+
int dbm_dirfno(DBM *db);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã§ã‚る。
+
+ +

データファイルã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `dbm_pagfno' を用ã„る。

+ +
+
int dbm_pagfno(DBM *db);
+
`db' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã§ã‚る。
+
+ +

サンプルコード

+ +

åå‰ã¨å¯¾å¿œã•ã›ã¦é›»è©±ç•ªå·ã‚’æ ¼ç´ã—ã€ãれを検索ã™ã‚‹ã‚¢ãƒ—リケーションã®ã‚µãƒ³ãƒ—ルコードを以下ã«ç¤ºã™ã€‚

+ +
#include <relic.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <string.h>
+
+#define NAME     "mikio"
+#define NUMBER   "000-1234-5678"
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  DBM *db;
+  datum key, val;
+  int i;
+
+  /* データベースを開ã */
+  if(!(db = dbm_open(DBNAME, O_RDWR | O_CREAT, 00644))){
+    perror("dbm_open");
+    return 1;
+  }
+
+  /* レコードを準備ã™ã‚‹ */
+  key.dptr = NAME;
+  key.dsize = strlen(NAME);
+  val.dptr = NUMBER;
+  val.dsize = strlen(NUMBER);
+
+  /* レコードを格ç´ã™ã‚‹ */
+  if(dbm_store(db, key, val, DBM_REPLACE) != 0){
+    perror("dbm_store");
+  }
+
+  /* レコードを検索ã™ã‚‹ */
+  val = dbm_fetch(db, key);
+  if(val.dptr){
+    printf("Name: %s\n", NAME);
+    printf("Number: ");
+    for(i = 0; i < val.dsize; i++){
+      putchar(((char *)val.dptr)[i]);
+    }
+    putchar('\n');
+  } else {
+    perror("dbm_fetch");
+  }
+
+  /* データベースを閉ã˜ã‚‹ */
+  dbm_close(db);
+
+  return 0;
+}
+
+ +

注記

+ +

Relicを利用ã—ãŸãƒ—ログラムをビルドã™ã‚‹æ–¹æ³•ã¯ã€Depotã®å ´åˆã¨å…¨ãåŒã˜ã§ã‚る。リンカã«æ¸¡ã™ã‚ªãƒ—ション㯠`-lndbm' ã§ã¯ãªã `-lqdbm' ã§ã‚る。

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

スレッド間ã§åŒæ™‚ã«åŒã˜ãƒãƒ³ãƒ‰ãƒ«ã«ã‚¢ã‚¯ã‚»ã‚¹ã—ãªã„é™ã‚Šã¯ã€Relicã®å„関数ã¯ã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ã§ã‚る。ãŸã ã—ã€`errno' ã‚„ `malloc' ç­‰ãŒã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ãªå‡¦ç†ç³»ã§ã‚ã‚‹ã“ã¨ãŒå‰æã¨ãªã‚‹ã€‚

+ +
+ +

Relic用コマンド

+ +

Relicã«å¯¾å¿œã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ãƒ©ã‚¤ãƒ³ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ã¯ä»¥ä¸‹ã®ã‚‚ã®ã§ã‚る。

+ +

コマンド `rlmgr' ã¯Relicã‚„ãã®ã‚¢ãƒ—リケーションã®ãƒ‡ãƒãƒƒã‚°ã«å½¹ç«‹ã¤ãƒ„ールã§ã‚る。データベースを更新ã—ãŸã‚Šã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®çŠ¶æ…‹ã‚’調ã¹ãŸã‚Šã™ã‚‹æ©Ÿèƒ½ã‚’æŒã¤ã€‚シェルスクリプトã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚¢ãƒ—リケーションを作るã®ã«ã‚‚利用ã§ãる。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`key' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã€`val' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’指定ã™ã‚‹ã€‚

+ +
+
rlmgr create name
+
データベースファイルを作æˆã™ã‚‹ã€‚
+
rlmgr store [-kx] [-vx|-vf] [-insert] name key val
+
キーã¨å€¤ã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã™ã‚‹ã€‚
+
rlmgr delete [-kx] name key
+
キーã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã™ã‚‹ã€‚
+
rlmgr fetch [-kx] [-ox] [-n] name key
+
キーã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’å–å¾—ã—ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
rlmgr list [-ox] name
+
データベース内ã®å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã¨å€¤ã‚’タブã¨æ”¹è¡Œã§åŒºåˆ‡ã£ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -kx : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—㦠`key' を扱ã†ã€‚
  • +
  • -vx : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—㦠`val' を扱ã†ã€‚
  • +
  • -vf : åå‰ãŒ `val' ã®ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ‡ãƒ¼ã‚¿ã‚’値ã¨ã—ã¦èª­ã¿è¾¼ã‚€ã€‚
  • +
  • -insert : 既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã‚­ãƒ¼ãŒé‡è¤‡æ™‚ã«ä¸Šæ›¸ãã›ãšã«ã‚¨ãƒ©ãƒ¼ã«ã™ã‚‹ã€‚
  • +
  • -ox : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—ã¦æ¨™æº–出力を行ã†ã€‚
  • +
  • -n : 標準出力ã®æœ«å°¾ã«ä»˜åŠ ã•ã‚Œã‚‹æ”¹è¡Œæ–‡å­—ã®å‡ºåŠ›ã‚’抑制ã™ã‚‹ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +

コマンド `rltest' ã¯Relicã®æ©Ÿèƒ½ãƒ†ã‚¹ãƒˆã‚„性能テストã«ç”¨ã„るツールã§ã‚る。ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã«ã‚ˆã£ã¦ç”Ÿæˆã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ `rlmgr' ã«ã‚ˆã£ã¦è§£æžã—ãŸã‚Šã€`time' コマンドã«ã‚ˆã£ã¦ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã®å®Ÿè¡Œæ™‚間を計ã£ãŸã‚Šã™ã‚‹ã¨ã‚ˆã„。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`rnum' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã‚’指定ã™ã‚‹ã€‚

+ +
+
rltest write name rnum
+
`00000001'ã€`00000002' ã®ã‚ˆã†ã«å¤‰åŒ–ã™ã‚‹8ãƒã‚¤ãƒˆã®ã‚­ãƒ¼ã¨é©å½“ãª8ãƒã‚¤ãƒˆã®å€¤ã‚’連続ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«è¿½åŠ ã™ã‚‹ã€‚
+
rltest read name rnum
+
上記ã§ç”Ÿæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’検索ã™ã‚‹ã€‚
+
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +
+ +

Hovel: GDBM互æ›API

+ +

概è¦

+ +

Hovelã¯ã€GDBMã¨äº’æ›ã™ã‚‹APIã§ã‚る。ã™ãªã‚ã¡ã€DepotãŠã‚ˆã³Curiaã®é–¢æ•°ç¾¤ã‚’GDBMã®APIã§åŒ…ã‚“ã ã‚‚ã®ã§ã‚る。Hovelを使ã£ã¦GDBMã®ã‚¢ãƒ—リケーションをQDBMã«ç§»æ¤ã™ã‚‹ã®ã¯ãŸã‚„ã™ã„。ã»ã¨ã‚“ã©ã®å ´åˆã€ã‚¤ãƒ³ã‚¯ãƒ«ãƒ¼ãƒ‰ã™ã‚‹ãƒ˜ãƒƒãƒ€ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ `gdbm.h' ã‹ã‚‰ `hovel.h' ã«æ›ãˆã€ãƒ“ルドã®éš›ã®ãƒªãƒ³ã‚«ã‚ªãƒ—ションを `-lgdbm' ã‹ã‚‰ `-lqdbm' ã«æ›ãˆã‚‹ã ã‘ã§ã‚ˆã„。ãªãŠã€ã‚ªãƒªã‚¸ãƒŠãƒ«ã®GDBMã§ç”Ÿæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’Hovelã§æ‰±ã†ã“ã¨ã¯ã§ããªã„。

+ +

Hovelを使ã†ãŸã‚ã«ã¯ã€`hovel.h' 㨠`stdlib.h' 㨠`sys/types.h' 㨠`sys/stat.h' をインクルードã™ã¹ãã§ã‚る。通常ã€ã‚½ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®å†’頭付近ã§ä»¥ä¸‹ã®è¨˜è¿°ã‚’è¡Œã†ã€‚

+ +
+
#include <hovel.h>
+
#include <stdlib.h>
+
#include <sys/types.h>
+
#include <sys/stat.h>
+
+ +

Hovelã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†éš›ã«ã¯ã€`GDBM_FILE' åž‹ã®ã‚ªãƒ–ジェクト(ãれ自体ãŒãƒã‚¤ãƒ³ã‚¿åž‹ï¼‰ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `gdbm_open' ã§é–‹ãã€é–¢æ•° `gdbm_close' ã§é–‰ã˜ã‚‹ã€‚ãƒãƒ³ãƒ‰ãƒ«ã®ãƒ¡ãƒ³ãƒã‚’直接å‚ç…§ã™ã‚‹ã“ã¨ã¯æŽ¨å¥¨ã•ã‚Œãªã„。Hovelã¯é€šå¸¸ã¯Depotã®ãƒ©ãƒƒãƒ‘ーã¨ã—ã¦å‹•ä½œã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’扱ã†ãŒã€ãƒãƒ³ãƒ‰ãƒ«ã‚’é–‹ãéš›ã«é–¢æ•° `gdbm_open2' を用ã„ã‚‹ã“ã¨ã«ã‚ˆã£ã¦Curiaã®ãƒ©ãƒƒãƒ‘ーã¨ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’扱ã†ã‚ˆã†ã«ã™ã‚‹ã“ã¨ãŒã§ãる。

+ +

API

+ +

データã®æ ¼ç´ã€å‰Šé™¤ã€æ¤œç´¢ã«ç”¨ã„る関数ã¨ã®ãƒ‡ãƒ¼ã‚¿ã®æŽˆå—ã«ã¯ã€ã‚­ãƒ¼ã¨å€¤ã‚’表ç¾ã™ã‚‹ã®ã« `datum' åž‹ã®æ§‹é€ ä½“を用ã„る。

+ +
+
typedef struct { char *dptr; size_t dsize; } datum;
+
`dptr' ã¯ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。`dsize' ã¯ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã§ã‚る。
+
+ +

外部変数 `gdbm_version' ã¯ãƒãƒ¼ã‚¸ãƒ§ãƒ³æƒ…å ±ã®æ–‡å­—列ã§ã‚る。

+ +
+
extern char *gdbm_version;
+
ã“ã®å¤‰æ•°ã®æŒ‡ã™é ˜åŸŸã¯æ›¸ãè¾¼ã¿ç¦æ­¢ã§ã‚る。
+
+ +

外部変数 `gdbm_errno' ã«ã¯ç›´å‰ã®ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ãŒè¨˜éŒ²ã•ã‚Œã‚‹ã€‚エラーコードã®è©³ç´°ã«ã¤ã„ã¦ã¯ `hovel.h' ã‚’å‚ç…§ã™ã‚‹ã“ã¨ã€‚

+ +
+
extern gdbm_error gdbm_errno;
+
ã“ã®å¤‰æ•°ã®åˆæœŸå€¤ã¯ `GDBM_NO_ERROR' ã§ã‚る。ãã®ä»–ã®å€¤ã¨ã—ã¦ã€`GDBM_MALLOC_ERROR'ã€`GDBM_BLOCK_SIZE_ERROR'ã€`GDBM_FILE_OPEN_ERROR'ã€`GDBM_FILE_WRITE_ERROR'ã€`GDBM_FILE_SEEK_ERROR'ã€`GDBM_FILE_READ_ERROR'ã€`GDBM_BAD_MAGIC_NUMBER'ã€`GDBM_EMPTY_DATABASE'ã€`GDBM_CANT_BE_READER'ã€`GDBM_CANT_BE_WRITER'ã€`GDBM_READER_CANT_DELETE'ã€`GDBM_READER_CANT_STORE'ã€`GDBM_READER_CANT_REORGANIZE'ã€`GDBM_UNKNOWN_UPDATE'ã€`GDBM_ITEM_NOT_FOUND'ã€`GDBM_REORGANIZE_FAILED'ã€`GDBM_CANNOT_REPLACE'ã€`GDBM_ILLEGAL_DATA'ã€`GDBM_OPT_ALREADY_SET' ãŠã‚ˆã³ `GDBM_OPT_ILLEGAL' ãŒã‚る。
+
+ +

エラーコードã«å¯¾å¿œã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸æ–‡å­—列を得るã«ã¯ã€é–¢æ•° `gdbm_strerror' を用ã„る。

+ +
+
char *gdbm_strerror(gdbm_error gdbmerrno);
+
`gdbmerrno' ã¯ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ã‚¨ãƒ©ãƒ¼ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã®æ–‡å­—列ã§ã‚ã‚Šã€ãã®é ˜åŸŸã¯æ›¸ãè¾¼ã¿ç¦æ­¢é ˜åŸŸã§ã‚る。
+
+ +

GDBMæµã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_open' を用ã„る。

+ +
+
GDBM_FILE gdbm_open(char *name, int block_size, int read_write, int mode, void (*fatal_func)(void));
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®åå‰ã‚’指定ã™ã‚‹ã€‚`block_size' ã¯ç„¡è¦–ã•ã‚Œã‚‹ã€‚`read_write' ã¯æŽ¥ç¶šãƒ¢ãƒ¼ãƒ‰ã‚’指定ã—ã€`GDBM_READER' ãªã‚‰ãƒªãƒ¼ãƒ€ã€`GDBM_WRITER' 㨠`GDBM_WRCREAT' 㨠`GDBM_NEWDB' ãªã‚‰ãƒ©ã‚¤ã‚¿ã¨ãªã‚‹ã€‚`GDBM_WRCREAT' ã®å ´åˆã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãŒå­˜åœ¨ã—ãªã‘ã‚Œã°ä½œæˆã—ã€`GDBM_NEWDB' ã®å ´åˆã¯æ—¢ã«å­˜åœ¨ã—ã¦ã„ã¦ã‚‚æ–°ã—ã„データベースを作æˆã™ã‚‹ã€‚ライタã«å¯¾ã—ã¦ã¯ã€`GDBM_SYNC' ã‹ `GDBM_NOLOCK' ã‹ `GDBM_LOCKNB' ã‹ `GDBM_FAST' ã‹ `GDBM_SPARSE' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãる。`GDBM_SYNC' ã¯å…¨ã¦ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹æ“作をディスクã¨åŒæœŸã•ã›ã€`GDBM_NOLOCK' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãƒ­ãƒƒã‚¯ã‚’ä¼´ã‚ãšã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ãã€`GDBM_LOCKNB' ã¯ãƒ–ロックãªã—ã®ãƒ­ãƒƒã‚¯ã‚’è¡Œã„ã€`GDBM_FAST' ã¯ç„¡è¦–ã•ã‚Œã‚‹ã€‚`GDBM_SPARSE' ã¯QDBM独自ã®ã‚‚ã®ã§ã‚ã‚Šã€ä½œæˆã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’スパースã«ã™ã‚‹ã€‚`mode' 㯠`open' コールã«æ¸¡ã™ã‚‚ã®ã¨åŒã˜ã§ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ¢ãƒ¼ãƒ‰ã‚’指定ã™ã‚‹ã€‚`fatal_func' ã¯ç„¡è¦–ã•ã‚Œã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。
+
+ +

QDBMæµã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_open2' を用ã„る。

+ +
+
GDBM_FILE gdbm_open2(char *name, int read_write, int mode, int bnum, int dnum, int align);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®åå‰ã‚’指定ã™ã‚‹ã€‚`read_write' ã¯æŽ¥ç¶šãƒ¢ãƒ¼ãƒ‰ã‚’指定ã—ã€`GDBM_READER' ãªã‚‰ãƒªãƒ¼ãƒ€ã€`GDBM_WRITER' 㨠`GDBM_WRCREAT' 㨠`GDBM_NEWDB' ãªã‚‰ãƒ©ã‚¤ã‚¿ã¨ãªã‚‹ã€‚`GDBM_WRCREAT' ã®å ´åˆã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãŒå­˜åœ¨ã—ãªã‘ã‚Œã°ä½œæˆã—ã€`GDBM_NEWDB' ã®å ´åˆã¯æ—¢ã«å­˜åœ¨ã—ã¦ã„ã¦ã‚‚æ–°ã—ã„データベースを作æˆã™ã‚‹ã€‚ライタã«å¯¾ã—ã¦ã¯ã€`GDBM_SYNC' ã‹ `GDBM_NOLOCK' ã‹ `GDBM_LOCKNB' ã‹ `GDBM_FAST' ã‹ `GDBM_SPARSE' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãる。`GDBM_SYNC' ã¯å…¨ã¦ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹æ“作をディスクã¨åŒæœŸã•ã›ã€`GDBM_NOLOCK' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãƒ­ãƒƒã‚¯ã‚’ä¼´ã‚ãšã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ãã€`GDBM_LOCKNB' ã¯ãƒ–ロックãªã—ã®ãƒ­ãƒƒã‚¯ã‚’è¡Œã„ã€`GDBM_FAST' ã¯ç„¡è¦–ã•ã‚Œã‚‹ã€‚`GDBM_SPARSE' ã¯QDBM独自ã®ã‚‚ã®ã§ã‚ã‚Šã€ä½œæˆã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’スパースã«ã™ã‚‹ã€‚`mode' 㯠`open' コールもã—ã㯠`mkdir' コールã«æ¸¡ã™ã‚‚ã®ã¨åŒã˜ã§ãƒ•ã‚¡ã‚¤ãƒ«ã‚„ディレクトリã®ãƒ¢ãƒ¼ãƒ‰ã‚’指定ã™ã‚‹ã€‚`bnum' ã¯ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã®ç›®å®‰ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ãŒä½¿ã‚れる。`dnum' ã¯è¦ç´ ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ•°ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰è¿”ã•ã‚Œã‚‹ãƒãƒ³ãƒ‰ãƒ«ã¯Depotã®ãƒ©ãƒƒãƒ‘ーã¨ã—ã¦ç”Ÿæˆã•ã‚Œã€ãã†ã§ãªã‘ã‚Œã°Curiaã®ãƒ©ãƒƒãƒ‘ーã«ãªã‚‹ã€‚`align' ã¯ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã®åŸºæœ¬ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。既ã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãŒå­˜åœ¨ã™ã‚‹å ´åˆã€ãã‚ŒãŒDepotã®ã‚‚ã®ã‹Curiaã®ã‚‚ã®ã‹ãŒè‡ªå‹•çš„ã«åˆ¤æ–­ã•ã‚Œã‚‹ã€‚
+
+ +

データベースã¨ã®æŽ¥ç¶šã‚’é–‰ã˜ã¦ãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_close' を用ã„る。

+ +
+
void gdbm_close(GDBM_FILE dbf);
+
`dbf' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ããªããªã‚‹ã€‚
+
+ +

レコードを追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_store' を用ã„る。

+ +
+
int gdbm_store(GDBM_FILE dbf, datum key, datum content, int flag);
+
`dbf' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`key' ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“を指定ã™ã‚‹ã€‚`content' ã¯å€¤ã®æ§‹é€ ä½“を指定ã™ã‚‹ã€‚`frags' ㌠`GDBM_INSERT' ãªã‚‰ã‚­ãƒ¼ã®é‡è¤‡æ™‚ã«æ›¸ãè¾¼ã¿ã‚’断念ã—ã€`GDBM_REPLACE' ãªã‚‰ä¸Šæ›¸ãã‚’è¡Œã†ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ 0 ã€é‡è¤‡ã§ã®æ–­å¿µãªã‚‰ 1 ã€ãã®ä»–ã®ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

レコードを削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_delete' を用ã„る。

+ +
+
int gdbm_delete(GDBM_FILE dbf, datum key);
+
`dbf' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`key' ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“を指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ 0 ã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

レコードをå–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_fetch' を用ã„る。

+ +
+
datum gdbm_fetch(GDBM_FILE dbf, datum key);
+
`dbf' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`key' ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“を指定ã™ã‚‹ã€‚戻り値ã¯å€¤ã®æ§‹é€ ä½“ã§ã‚る。該当ãŒã‚ã‚Œã°ãƒ¡ãƒ³ãƒ `dptr' ãŒãã®é ˜åŸŸã‚’指ã—ã€`dsize' ãŒãã®ã‚µã‚¤ã‚ºã‚’示ã™ã€‚該当ãŒãªã‘れ㰠`dptr' ã®å€¤ã¯ `NULL' ã¨ãªã‚‹ã€‚戻り値ã®ãƒ¡ãƒ³ãƒ `dptr' ã®æŒ‡ã™é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

レコードãŒå­˜åœ¨ã™ã‚‹ã‹èª¿ã¹ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_exists' を用ã„る。

+ +
+
int gdbm_exists(GDBM_FILE dbf, datum key);
+
`dbf' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`key' ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“を指定ã™ã‚‹ã€‚戻り値ã¯è©²å½“ãŒã‚ã‚Œã°çœŸã§ã‚ã‚Šã€è©²å½“ãŒãªã„å ´åˆã‚„エラーã®å ´åˆã¯å½ã§ã‚る。
+
+ +

最åˆã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_firstkey' を用ã„る。

+ +
+
datum gdbm_firstkey(GDBM_FILE dbf);
+
`dbf' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“ã§ã‚る。該当ãŒã‚ã‚Œã°ãƒ¡ãƒ³ãƒ `dptr' ãŒãã®é ˜åŸŸã‚’指ã—ã€`dsize' ãŒãã®ã‚µã‚¤ã‚ºã‚’示ã™ã€‚該当ãŒãªã‘れ㰠`dptr' ã®å€¤ã¯ `NULL' ã¨ãªã‚‹ã€‚戻り値ã®ãƒ¡ãƒ³ãƒ `dptr' ã®æŒ‡ã™é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

次ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° gdbm_nextkey を用ã„る。

+ +
+
datum gdbm_nextkey(GDBM_FILE dbf, datum key);
+
`dbf' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`key' ã¯ç„¡è¦–ã•ã‚Œã‚‹ã€‚戻り値ã¯ã‚­ãƒ¼ã®æ§‹é€ ä½“ã§ã‚る。該当ãŒã‚ã‚Œã°ãƒ¡ãƒ³ãƒ `dptr' ãŒãã®é ˜åŸŸã‚’指ã—ã€`dsize' ãŒãã®ã‚µã‚¤ã‚ºã‚’示ã™ã€‚該当ãŒãªã‘れ㰠`dptr' ã®å€¤ã¯ `NULL' ã¨ãªã‚‹ã€‚戻り値ã®ãƒ¡ãƒ³ãƒ `dptr' ã®æŒ‡ã™é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

データベースを更新ã—ãŸå†…容をファイルã¨ãƒ‡ãƒã‚¤ã‚¹ã«åŒæœŸã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_sync' を用ã„る。

+ +
+
void gdbm_sync(GDBM_FILE dbf);
+
`dbf' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚
+
+ +

データベースを最é©åŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_reorganize' を用ã„る。

+ +
+
int gdbm_reorganize(GDBM_FILE dbf);
+
`dbf' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ 0 ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

データベースファイルã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `gdbm_fdesc' を用ã„る。

+ +
+
int gdbm_fdesc(GDBM_FILE dbf);
+
`dbf' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—ã‚¿ã§ã‚る。データベースãŒãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªãªã‚‰ã€æˆ»ã‚Šå€¤ã¯ -1 ã§ã‚る。
+
+ +

関数 `gdbm_setopt' ã¯ä½•ã‚‚ã—ãªã„。

+ +
+
int gdbm_setopt(GDBM_FILE dbf, int option, int *value, int size);
+
`dbf' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`option' ã¯ç„¡è¦–ã•ã‚Œã‚‹ã€‚`value' ã¯ç„¡è¦–ã•ã‚Œã‚‹ã€‚`size' ã¯ç„¡è¦–ã•ã‚Œã‚‹ã€‚戻り値㯠0 ã§ã‚る。ã“ã®é–¢æ•°ã¯äº’æ›æ€§ã®ãŸã‚ã«ã®ã¿å­˜åœ¨ã™ã‚‹ã€‚
+
+ +

サンプルコード

+ +

åå‰ã¨å¯¾å¿œã•ã›ã¦é›»è©±ç•ªå·ã‚’æ ¼ç´ã—ã€ãれを検索ã™ã‚‹ã‚¢ãƒ—リケーションã®ã‚µãƒ³ãƒ—ルコードを以下ã«ç¤ºã™ã€‚

+ +
#include <hovel.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <string.h>
+
+#define NAME     "mikio"
+#define NUMBER   "000-1234-5678"
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  GDBM_FILE dbf;
+  datum key, val;
+  int i;
+
+  /* データベースを開ã */
+  if(!(dbf = gdbm_open(DBNAME, 0, GDBM_WRCREAT, 00644, NULL))){
+    fprintf(stderr, "gdbm_open: %s\n", gdbm_strerror(gdbm_errno));
+    return 1;
+  }
+
+  /* レコードを準備ã™ã‚‹ */
+  key.dptr = NAME;
+  key.dsize = strlen(NAME);
+  val.dptr = NUMBER;
+  val.dsize = strlen(NUMBER);
+
+  /* レコードを格ç´ã™ã‚‹ */
+  if(gdbm_store(dbf, key, val, GDBM_REPLACE) != 0){
+    fprintf(stderr, "gdbm_store: %s\n", gdbm_strerror(gdbm_errno));
+  }
+
+  /* レコードを検索ã™ã‚‹ */
+  val = gdbm_fetch(dbf, key);
+  if(val.dptr){
+    printf("Name: %s\n", NAME);
+    printf("Number: ");
+    for(i = 0; i < val.dsize; i++){
+      putchar(val.dptr[i]);
+    }
+    putchar('\n');
+    free(val.dptr);
+  } else {
+    fprintf(stderr, "gdbm_fetch: %s\n", gdbm_strerror(gdbm_errno));
+  }
+
+  /* データベースを閉ã˜ã‚‹ */
+  gdbm_close(dbf);
+
+  return 0;
+}
+
+ +

注記

+ +

Hovelを利用ã—ãŸãƒ—ログラムをビルドã™ã‚‹æ–¹æ³•ã¯ã€Depotã®å ´åˆã¨å…¨ãåŒã˜ã§ã‚る。リンカã«æ¸¡ã™ã‚ªãƒ—ション㯠`-lgdbm' ã§ã¯ãªã `-lqdbm' ã§ã‚る。

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

POSIXスレッドを有効ã«ã—ã¦QDBMをビルドã—ãŸå ´åˆã€å¤–部変数 `gdbm_errno' ã¯ã‚¹ãƒ¬ãƒƒãƒ‰å›ºæœ‰ãƒ‡ãƒ¼ã‚¿ã¸ã®å‚ç…§ã¨ã—ã¦æ‰±ã‚ã‚Œã€Hovelã®å„関数ã¯ãƒªã‚¨ãƒ³ãƒˆãƒ©ãƒ³ãƒˆã«ãªã‚‹ã€‚ãã®å ´åˆã€ã‚¹ãƒ¬ãƒƒãƒ‰é–“ã§åŒæ™‚ã«åŒã˜ãƒãƒ³ãƒ‰ãƒ«ã«ã‚¢ã‚¯ã‚»ã‚¹ã—ãªã„é™ã‚Šã¯ã€å„関数ã¯ã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ã§ã‚る。ãŸã ã—ã€`errno' ã‚„ `malloc' ç­‰ãŒã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ãªå‡¦ç†ç³»ã§ã‚ã‚‹ã“ã¨ãŒå‰æã¨ãªã‚‹ã€‚

+ +
+ +

Hovel用コマンド

+ +

Hovelã«å¯¾å¿œã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ãƒ©ã‚¤ãƒ³ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ã¯ä»¥ä¸‹ã®ã‚‚ã®ã§ã‚る。

+ +

コマンド `hvmgr' ã¯Hovelã‚„ãã®ã‚¢ãƒ—リケーションã®ãƒ‡ãƒãƒƒã‚°ã«å½¹ç«‹ã¤ãƒ„ールã§ã‚る。データベースを更新ã—ãŸã‚Šã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®çŠ¶æ…‹ã‚’調ã¹ãŸã‚Šã™æ©Ÿèƒ½ã‚’æŒã¤ã€‚シェルスクリプトã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚¢ãƒ—リケーションを作るã®ã«ã‚‚利用ã§ãる。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`key' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã€`val' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’指定ã™ã‚‹ã€‚

+ +
+
hvmgr [-qdbm bnum dnum] [-s] create name
+
データベースファイルを作æˆã™ã‚‹ã€‚
+
hvmgr store [-qdbm] [-kx] [-vx|-vf] [-insert] name key val
+
キーã¨å€¤ã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã™ã‚‹ã€‚
+
hvmgr delete [-qdbm] [-kx] name key
+
キーã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã™ã‚‹ã€‚
+
hvmgr fetch [-qdbm] [-kx] [-ox] [-n] name key
+
キーã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’å–å¾—ã—ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
hvmgr list [-qdbm] [-ox] name
+
データベース内ã®å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã¨å€¤ã‚’タブã¨æ”¹è¡Œã§åŒºåˆ‡ã£ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
hvmgr optimize [-qdbm] name
+
データベースを最é©åŒ–ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -qdbm [bnum dnum] : `gdbm_open2' ã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã。`bnum' 㨠`dnum' ã¯ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã¨ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®åˆ†å‰²æ•°ã‚’指定ã™ã‚‹ã€‚
  • +
  • -s : ファイルをスパースã«ã™ã‚‹ã€‚
  • +
  • -kx : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—㦠`key' を扱ã†ã€‚
  • +
  • -vx : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—㦠`val' を扱ã†ã€‚
  • +
  • -vf : åå‰ãŒ `val' ã®ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ‡ãƒ¼ã‚¿ã‚’値ã¨ã—ã¦èª­ã¿è¾¼ã‚€ã€‚
  • +
  • -insert : 既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã‚­ãƒ¼ãŒé‡è¤‡æ™‚ã«ä¸Šæ›¸ãã›ãšã«ã‚¨ãƒ©ãƒ¼ã«ã™ã‚‹ã€‚
  • +
  • -ox : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—ã¦æ¨™æº–出力を行ã†ã€‚
  • +
  • -n : 標準出力ã®æœ«å°¾ã«ä»˜åŠ ã•ã‚Œã‚‹æ”¹è¡Œæ–‡å­—ã®å‡ºåŠ›ã‚’抑制ã™ã‚‹ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +

コマンド `hvtest' ã¯Hovelã®æ©Ÿèƒ½ãƒ†ã‚¹ãƒˆã‚„性能テストã«ç”¨ã„るツールã§ã‚る。ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã«ã‚ˆã£ã¦ç”Ÿæˆã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ `hvmgr' ã«ã‚ˆã£ã¦è§£æžã—ãŸã‚Šã€`time' コマンドã«ã‚ˆã£ã¦ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã®å®Ÿè¡Œæ™‚間を計ã£ãŸã‚Šã™ã‚‹ã¨ã‚ˆã„。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`rnum' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã‚’指定ã™ã‚‹ã€‚

+ +
+
hvtest write [-qdbm] [-s] name rnum
+
`00000001'ã€`00000002' ã®ã‚ˆã†ã«å¤‰åŒ–ã™ã‚‹8ãƒã‚¤ãƒˆã®ã‚­ãƒ¼ã¨é©å½“ãª8ãƒã‚¤ãƒˆã®å€¤ã‚’連続ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«è¿½åŠ ã™ã‚‹ã€‚
+
hvtest read [-qdbm] name rnum
+
上記ã§ç”Ÿæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’検索ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -qdbm : `gdbm_open2' を用ã„ã¦Curiaã®ãƒãƒ³ãƒ‰ãƒ«ã‚’é–‹ã。
  • +
  • -s : ファイルをスパースã«ã™ã‚‹ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +
+ +

Cabin: ユーティリティAPI

+ +

概è¦

+ +

Cabinã¯ãƒ¡ãƒ¢ãƒªä¸Šã§ç°¡å˜ã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’扱ã†ãŸã‚ã®ãƒ¡ãƒ¢ãƒªç¢ºä¿é–¢æ•°ã‚„整列関数や拡張å¯èƒ½ãªãƒ‡ãƒ¼ã‚¿ã‚„é…列リストやãƒãƒƒã‚·ãƒ¥ãƒžãƒƒãƒ—やヒープé…列ãªã©æä¾›ã™ã‚‹ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£ã®APIã§ã‚る。MIMEã‚„CSVã‚„XMLを解æžã™ã‚‹æ©Ÿèƒ½ã‚„ã€å„種ã®ç¬¦å·åŒ–ã¨å¾©å·ã‚’è¡Œã†æ©Ÿèƒ½ã‚‚å‚™ãˆã‚‹ã€‚

+ +

Cabinを使ã†ãŸã‚ã«ã¯ã€`cabin.h' 㨠`stdlib.h' をインクルードã™ã¹ãã§ã‚る。通常ã€ã‚½ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®å†’頭付近ã§ä»¥ä¸‹ã®è¨˜è¿°ã‚’è¡Œã†ã€‚

+ +
+
#include <cabin.h>
+
#include <stdlib.h>
+
+ +

æ‹¡å¼µå¯èƒ½ãªãƒ‡ãƒ¼ã‚¿ã‚’扱ã†éš›ã«ã¯ã€`CBDATUM' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。データãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `cbdatumopen' ã§é–‹ãã€é–¢æ•° `cbdatumclose' ã§é–‰ã˜ã‚‹ã€‚リストを扱ã†éš›ã«ã¯ã€`CBLIST' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。リストãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `cblistopen' ã§é–‹ãã€é–¢æ•° `cblistclose' ã§é–‰ã˜ã‚‹ã€‚マップを扱ã†éš›ã«ã¯ã€`CBMAP' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。マップãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `cbmapopen' ã§é–‹ãã€é–¢æ•° `cbmapclose' ã§é–‰ã˜ã‚‹ã€‚ヒープé…列を扱ã†éš›ã«ã¯ `CBHEAP' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。ヒープãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cbheapopen' ã§é–‹ãã€é–¢æ•° `cbheapclose' ã§é–‰ã˜ã‚‹ã€‚å„ãƒãƒ³ãƒ‰ãƒ«ã®ãƒ¡ãƒ³ãƒã‚’直接å‚ç…§ã™ã‚‹ã“ã¨ã¯æŽ¨å¥¨ã•ã‚Œãªã„。 + +

+ +

API

+ +

外部変数 `cbfatalfunc' ã¯è‡´å‘½çš„エラーをãƒãƒ³ãƒ‰ãƒªãƒ³ã‚°ã™ã‚‹ã‚³ãƒ¼ãƒ«ãƒãƒƒã‚¯é–¢æ•°ã§ã‚る。

+ +
+
extern void (*cbfatalfunc)(const char *message);
+
引数ã¯ã‚¨ãƒ©ãƒ¼ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’指定ã™ã‚‹ã€‚ã“ã®å¤‰æ•°ã®åˆæœŸå€¤ã¯ `NULL' ã§ã‚ã‚Šã€`NULL' ãªã‚‰ã°è‡´å‘½çš„エラーã®ç™ºç”Ÿæ™‚ã«ã¯ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã®é–¢æ•°ãŒå‘¼ã°ã‚Œã‚‹ã€‚致命的エラーã¯ãƒ¡ãƒ¢ãƒªã®å‰²ã‚Šå½“ã¦ã«å¤±æ•—ã—ãŸéš›ã«èµ·ã“る。
+
+ +

メモリ上ã«é ˜åŸŸã‚’確ä¿ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmalloc' を用ã„る。

+ +
+
void *cbmalloc(size_t size);
+
`size' ã¯é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯ç¢ºä¿ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

メモリ上ã®é ˜åŸŸã‚’å†ç¢ºä¿ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbrealloc' を用ã„る。

+ +
+
void *cbrealloc(void *ptr, size_t size);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯å†ç¢ºä¿ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `remalloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

メモリ上ã®é ˜åŸŸã‚’複製ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmemdup' を用ã„る。

+ +
+
char *cbmemdup(const char *ptr, int size);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯å†ç¢ºä¿ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã¯è¤‡è£½ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

メモリ上ã®é–‹æ”¾ã‚’解放ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbfree' を用ã„る。

+ +
+
void cbfree(void *ptr);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ãŒã€`NULL' ã®å ´åˆã¯ä½•ã‚‚ã—ãªã„。ã“ã®é–¢æ•°ã¯ `free' ã®ãƒ©ãƒƒãƒ‘ーã«éŽãŽãªã„ãŒã€`malloc' シリーズã®åˆ¥ã®ãƒ‘ッケージを使ã†ã‚¢ãƒ—リケーションã«ãŠã„ã¦QDBMãŒç¢ºä¿ã—ãŸé ˜åŸŸã‚’解放ã™ã‚‹ã®ã«ä¾¿åˆ©ã§ã‚る。
+
+ +

オブジェクトã®ãƒã‚¤ãƒ³ã‚¿ã‹ãƒãƒ³ãƒ‰ãƒ«ã‚’グローãƒãƒ«ã‚¬ãƒ™ãƒ¼ã‚¸ã‚³ãƒ¬ã‚¯ã‚¿ã«ç™»éŒ²ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbglobalgc' を用ã„る。

+ +
+
void cbglobalgc(void *ptr, void (*func)(void *));
+
`ptr' ã¯ã‚ªãƒ–ジェクトã®ãƒã‚¤ãƒ³ã‚¿ã‹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`func' ã¯ã‚ªãƒ–ジェクトã®ãƒªã‚½ãƒ¼ã‚¹ã‚’解放ã™ã‚‹é–¢æ•°ã‚’指定ã™ã‚‹ã€‚ãã®å¼•æ•°ã¯è§£æ”¾ã™ã‚‹ã‚ªãƒ–ジェクトã®ãƒã‚¤ãƒ³ã‚¿ã‹ãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。ã“ã®é–¢æ•°ã¯ã€`main' 関数ãŒãƒªã‚¿ãƒ¼ãƒ³ã™ã‚‹ã‹ `exit' 関数ãŒå‘¼ã°ã‚Œã¦ãƒ—ロセスãŒæ­£å¸¸çµ‚了ã™ã‚‹éš›ã«ã€ã‚ªãƒ–ジェクトã®ãƒªã‚½ãƒ¼ã‚¹ãŒè§£æ”¾ã•ã‚Œã‚‹ã“ã¨ã‚’ä¿è¨¼ã™ã‚‹ã€‚
+
+ +

グローãƒãƒ«ã‚¬ãƒ™ãƒ¼ã‚¸ã‚³ãƒ¬ã‚¯ã‚¿ã‚’明示的ã«ç™ºå‹•ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `cbggcsweep' を用ã„る。

+ +
+
void cbggcsweep(void);
+
ã“ã®é–¢æ•°ã‚’呼んã å¾Œã¯ã‚°ãƒ­ãƒ¼ãƒãƒ«ã‚¬ãƒ™ãƒ¼ã‚¸ã‚³ãƒ¬ã‚¯ã‚¿ã«ç™»éŒ²ã—ã¦ã‚ã£ãŸã‚ªãƒ–ジェクトã¯åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ããªããªã‚‹ã“ã¨ã«æ³¨æ„ã™ã‚‹ã“ã¨ã€‚グローãƒãƒ«ã‚¬ãƒ™ãƒ¼ã‚¸ã‚³ãƒ¬ã‚¯ã‚¿ã¯åˆæœŸåŒ–ã•ã‚Œã‚‹ã®ã§ã€æ–°ã—ã„オブジェクトを入れるã“ã¨ãŒã§ãるよã†ã«ãªã‚‹ã€‚
+
+ +

仮想メモリã®å‰²ã‚Šå½“ã¦å¯èƒ½æ€§ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `cbvmemavail' を用ã„る。

+ +
+
int cbvmemavail(size_t size);
+
`size' ã¯æ–°ãŸã«å‰²ã‚Šå½“ã¦å¯èƒ½ã§ã‚ã‚‹ã¹ã領域ã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯å‰²ã‚Šå½“ã¦ãŒå¯èƒ½ã§ã‚ã‚Œã°çœŸã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

é…列ã®å„è¦ç´ ã‚’挿入ソートã§æ•´åˆ—ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `cbisort' を用ã„る。

+ +
+
void cbisort(void *base, int nmemb, int size, int(*compar)(const void *, const void *));
+
`base' ã¯é…列ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`nmemb' ã¯é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`size' ã¯å„è¦ç´ ã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚`compar' ã¯æ¯”較関数を指定ã™ã‚‹ã€‚二ã¤ã®å¼•æ•°ã¯è¦ç´ ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。比較関数ã¯å‰è€…ãŒå¤§ãã‘ã‚Œã°æ­£æ•°ã‚’ã€å¾Œè€…ãŒå¤§ãã‘ã‚Œã°è² æ•°ã‚’ã€ä¸¡è€…ãŒç­‰ã—ã‘れ㰠0 ã‚’è¿”ã™ã¹ãã§ã‚る。挿入ソートã¯ã€ã»ã¨ã‚“ã©ã®è¦ç´ ãŒæ—¢ã«æ•´åˆ—済ã¿ã®å ´åˆã«ã®ã¿æœ‰ç”¨ã§ã‚る。
+
+ +

é…列ã®å„è¦ç´ ã‚’シェルソートã§æ•´åˆ—ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `cbssort' を用ã„る。

+ +
+
void cbssort(void *base, int nmemb, int size, int(*compar)(const void *, const void *));
+
`base' ã¯é…列ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`nmemb' ã¯é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`size' ã¯å„è¦ç´ ã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚`compar' ã¯æ¯”較関数を指定ã™ã‚‹ã€‚二ã¤ã®å¼•æ•°ã¯è¦ç´ ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。比較関数ã¯å‰è€…ãŒå¤§ãã‘ã‚Œã°æ­£æ•°ã‚’ã€å¾Œè€…ãŒå¤§ãã‘ã‚Œã°è² æ•°ã‚’ã€ä¸¡è€…ãŒç­‰ã—ã‘れ㰠0 ã‚’è¿”ã™ã¹ãã§ã‚る。ã»ã¨ã‚“ã©ã®è¦ç´ ãŒæ•´åˆ—済ã¿ã®å ´åˆã€ã‚·ã‚§ãƒ«ã‚½ãƒ¼ãƒˆã®æ–¹ãŒãƒ’ープソートやクイックソートより速ã„ã‹ã‚‚ã—ã‚Œãªã„。
+
+ +

é…列ã®å„è¦ç´ ã‚’ヒープソートã§æ•´åˆ—ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `cbhsort' を用ã„る。

+ +
+
void cbhsort(void *base, int nmemb, int size, int(*compar)(const void *, const void *));
+
`base' ã¯é…列ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`nmemb' ã¯é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`size' ã¯å„è¦ç´ ã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚`compar' ã¯æ¯”較関数を指定ã™ã‚‹ã€‚二ã¤ã®å¼•æ•°ã¯è¦ç´ ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。比較関数ã¯å‰è€…ãŒå¤§ãã‘ã‚Œã°æ­£æ•°ã‚’ã€å¾Œè€…ãŒå¤§ãã‘ã‚Œã°è² æ•°ã‚’ã€ä¸¡è€…ãŒç­‰ã—ã‘れ㰠0 ã‚’è¿”ã™ã¹ãã§ã‚る。ヒープソートã¯å…¥åŠ›ã®åã‚Šã«å¯¾ã—ã¦é ‘丈ã§ã‚ã‚‹ãŒã€ã»ã¨ã‚“ã©ã®å ´åˆã§ã‚¯ã‚¤ãƒƒã‚¯ã‚½ãƒ¼ãƒˆã®æ–¹ãŒé€Ÿã„。
+
+ +

é…列ã®å„è¦ç´ ã‚’クイックソートã§æ•´åˆ—ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `cbqsort' を用ã„る。

+ +
+
void cbqsort(void *base, int nmemb, int size, int(*compar)(const void *, const void *));
+
`base' ã¯é…列ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`nmemb' ã¯é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`size' ã¯å„è¦ç´ ã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚`compar' ã¯æ¯”較関数を指定ã™ã‚‹ã€‚二ã¤ã®å¼•æ•°ã¯è¦ç´ ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。比較関数ã¯å‰è€…ãŒå¤§ãã‘ã‚Œã°æ­£æ•°ã‚’ã€å¾Œè€…ãŒå¤§ãã‘ã‚Œã°è² æ•°ã‚’ã€ä¸¡è€…ãŒç­‰ã—ã‘れ㰠0 ã‚’è¿”ã™ã¹ãã§ã‚る。入力ã®åã‚Šã«æ•æ„Ÿã§ã¯ã‚ã‚‹ãŒã€ã‚¯ã‚¤ãƒƒã‚¯ã‚½ãƒ¼ãƒˆã¯æœ€é€Ÿã®æ•´åˆ—アルゴリズムã§ã‚る。
+
+ +

大文字ã¨å°æ–‡å­—ã®é•ã„を無視ã—ã¦äºŒã¤ã®æ–‡å­—列を比較ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbstricmp' を用ã„る。

+ +
+
int cbstricmp(const char *astr, const char *bstr);
+
`astr' ã¯ä¸€æ–¹ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`bstr' ã¯ä»–æ–¹ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯å‰è€…ãŒå¤§ãã‘ã‚Œã°æ­£ã€å¾Œè€…ãŒå¤§ãã‘ã‚Œã°è² ã€ä¸¡è€…ãŒç­‰ä¾¡ãªã‚‰ 0 ã§ã‚る。ASCIIコード中ã®ã‚¢ãƒ«ãƒ•ã‚¡ãƒ™ãƒƒãƒˆã®å¤§æ–‡å­—ã¨å°æ–‡å­—ã¯åŒºåˆ¥ã•ã‚Œãªã„。
+
+ +

文字列ãŒã‚るキーã§å§‹ã¾ã£ã¦ã„ã‚‹ã‹èª¿ã¹ã‚‹ã«ã¯ã€é–¢æ•° `cbstrfwmatch' を用ã„る。

+ +
+
int cbstrfwmatch(const char *str, const char *key);
+
`str' ã¯å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`key' ã¯å‰æ–¹ä¸€è‡´ã®ã‚­ãƒ¼ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯å¯¾è±¡ã®æ–‡å­—列ãŒã‚­ãƒ¼ã§å§‹ã¾ã£ã¦ã„ã‚Œã°çœŸã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

大文字ã¨å°æ–‡å­—ã®é•ã„を無視ã—ã¤ã¤ã€æ–‡å­—列ãŒã‚るキーã§å§‹ã¾ã£ã¦ã„ã‚‹ã‹èª¿ã¹ã‚‹ã«ã¯ã€é–¢æ•° `cbstrfwimatch' を用ã„る。

+ +
+
int cbstrfwimatch(const char *str, const char *key);
+
`str' ã¯å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`key' ã¯å‰æ–¹ä¸€è‡´ã®ã‚­ãƒ¼ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯å¯¾è±¡ã®æ–‡å­—列ãŒã‚­ãƒ¼ã§å§‹ã¾ã£ã¦ã„ã‚Œã°çœŸã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。ASCIIコード中ã®ã‚¢ãƒ«ãƒ•ã‚¡ãƒ™ãƒƒãƒˆã®å¤§æ–‡å­—ã¨å°æ–‡å­—ã¯åŒºåˆ¥ã•ã‚Œãªã„。
+
+ +

文字列ãŒã‚るキーã§çµ‚ã£ã¦ã„ã‚‹ã‹èª¿ã¹ã‚‹ã«ã¯ã€é–¢æ•° `cbstrbwmatch' を用ã„る。

+ +
+
int cbstrbwmatch(const char *str, const char *key);
+
`str' ã¯å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`key' ã¯å¾Œæ–¹ä¸€è‡´ã®ã‚­ãƒ¼ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯å¯¾è±¡ã®æ–‡å­—列ãŒã‚­ãƒ¼ã§çµ‚ã£ã¦ã„ã‚Œã°çœŸã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

大文字ã¨å°æ–‡å­—ã®é•ã„を無視ã—ã¤ã¤ã€æ–‡å­—列ãŒã‚るキーã§çµ‚ã£ã¦ã„ã‚‹ã‹èª¿ã¹ã‚‹ã«ã¯ã€é–¢æ•° `cbstrbwimatch' を用ã„る。

+ +
+
int cbstrbwimatch(const char *str, const char *key);
+
`str' ã¯å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`key' ã¯å¾Œæ–¹ä¸€è‡´ã®ã‚­ãƒ¼ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯å¯¾è±¡ã®æ–‡å­—列ãŒã‚­ãƒ¼ã§çµ‚ã£ã¦ã„ã‚Œã°çœŸã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。ASCIIコード中ã®ã‚¢ãƒ«ãƒ•ã‚¡ãƒ™ãƒƒãƒˆã®å¤§æ–‡å­—ã¨å°æ–‡å­—ã¯åŒºåˆ¥ã•ã‚Œãªã„。
+
+ +

KMP法を用ã„ã¦æ–‡å­—列ã®éƒ¨åˆ†æ–‡å­—列ã®ä½ç½®ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbstrstrkmp' を用ã„る。

+ +
+
char *cbstrstrkmp(const char *haystack, const char *needle);
+
`haystack' ã¯æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`needle' ã¯æŽ¢ã™ã¹ã部分文字列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯éƒ¨åˆ†æ–‡å­—列ã®é–‹å§‹ã‚’指ã™ãƒã‚¤ãƒ³ã‚¿ã‹ã€è¦‹ã¤ã‹ã‚‰ãªã‘れ㰠`NULL' ã§ã‚る。大抵ã®å ´åˆã€ã“ã®é–¢æ•°ã‚ˆã‚Šã‚³ãƒ³ãƒ‘イラã®ãƒ“ルドインã§ã‚ã‚‹ `strstr' ã®æ–¹ãŒé«˜é€Ÿã§ã‚る。
+
+ +

BM法を用ã„ã¦æ–‡å­—列ã®éƒ¨åˆ†æ–‡å­—列ã®ä½ç½®ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbstrstrbm' を用ã„る。

+ +
+
char *cbstrstrbm(const char *haystack, const char *needle);
+
`haystack' ã¯æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`needle' ã¯æŽ¢ã™ã¹ã部分文字列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯éƒ¨åˆ†æ–‡å­—列ã®é–‹å§‹ã‚’指ã™ãƒã‚¤ãƒ³ã‚¿ã‹ã€è¦‹ã¤ã‹ã‚‰ãªã‘れ㰠`NULL' ã§ã‚る。大抵ã®å ´åˆã€ã“ã®é–¢æ•°ã‚ˆã‚Šã‚³ãƒ³ãƒ‘イラã®ãƒ“ルドインã§ã‚ã‚‹ `strstr' ã®æ–¹ãŒé«˜é€Ÿã§ã‚る。
+
+ +

文字列ã®å…¨ã¦ã®æ–‡å­—を大文字ã«å¤‰æ›ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbstrtoupper' を用ã„る。

+ +
+
char *cbstrtoupper(char *str);
+
`str' ã¯å¤‰æ›å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。
+
+ +

文字列ã®å…¨ã¦ã®æ–‡å­—ã‚’å°æ–‡å­—ã«å¤‰æ›ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbstrtolower' を用ã„る。

+ +
+
char *cbstrtolower(char *str);
+
`str' ã¯å¤‰æ›å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。
+
+ +

文字列ã®å…ˆé ­ã¨æœ«å°¾ã«ã‚る空白文字を削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbstrtrim' を用ã„る。

+ +
+
char *cbstrtrim(char *str);
+
`str' ã¯å¤‰æ›å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。
+
+ +

文字列内ã®é€£ç¶šã™ã‚‹ç©ºç™½ã‚’絞ã£ã¦æ•´å½¢ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbstrsqzcpc' を用ã„る。

+ +
+
char *cbstrsqzspc(char *str);
+
`str' ã¯å¤‰æ›å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。
+
+ +

UTF-8ã®æ–‡å­—列ã«å«ã¾ã‚Œã‚‹æ–‡å­—æ•°ã‚’æ•°ãˆã‚‹ã«ã¯ã€é–¢æ•° `cbstrcountutf' を用ã„る。

+ +
+
int cbstrcountutf(const char *str);
+
`str' ã¯UTF-8ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãã®æ–‡å­—列ã«å«ã¾ã‚Œã‚‹æ–‡å­—æ•°ã§ã‚る。
+
+ +

UTF-8ã®æ–‡å­—列を指定ã—ãŸæ–‡å­—æ•°ã§åˆ‡ã‚‹ã«ã¯ã€é–¢æ•° `cbstrcututf' を用ã„る。

+ +
+
char *cbstrcututf(char *str, int num);
+
`str' ã¯UTF-8ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`num' ã¯ä¿æŒã™ã‚‹æ–‡å­—数を指定ã™ã‚‹ã€‚戻り値ã¯ãã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。
+
+ +

データãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `cbdatumopen' を用ã„る。

+ +
+
CBDATUM *cbdatumopen(const char *ptr, int size);
+
`ptr' ã¯åˆæœŸå†…容ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã‹ã€`NULL' ãªã‚‰ç©ºã®ãƒ‡ãƒ¼ã‚¿ã‚’作æˆã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。
+
+ +

データを複製ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbdatumdup' を用ã„る。

+ +
+
CBDATUM *cbdatumdup(const CBDATUM *datum);
+
`datum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ–°ã—ã„データãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。
+
+ +

データãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbdatumclose' を用ã„る。

+ +
+
void cbdatumclose(CBDATUM *datum);
+
`datum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ããªããªã‚‹ã€‚
+
+ +

データã«åˆ¥ã®é ˜åŸŸã‚’連çµã™ã‚‹ã«ã¯ã€é–¢æ•° `cbdatumcat' を用ã„る。

+ +
+
void cbdatumcat(CBDATUM *datum, const char *ptr, int size);
+
`datum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`ptr' ã¯é€£çµã™ã‚‹é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚
+
+ +

データã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbdatumptr' を用ã„る。

+ +
+
const char *cbdatumptr(const CBDATUM *datum);
+
`datum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。
+
+ +

データã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbdatumsize' を用ã„る。

+ +
+
int cbdatumsize(const CBDATUM *datum);
+
`datum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã§ã‚る。
+
+ +

データã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’変更ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbdatumsetsize' を用ã„る。

+ +
+
void cbdatumsetsize(CBDATUM *datum, int size);
+
`datum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`size' ã¯é ˜åŸŸã®æ–°ã—ã„サイズを指定ã™ã‚‹ã€‚æ–°ã—ã„サイズãŒæ—¢å­˜ã®ã‚µã‚¤ã‚ºã‚ˆã‚Šå¤§ãã„å ´åˆã€ä½™ã£ãŸé ˜åŸŸã¯çµ‚端文字ã§åŸ‹ã‚られる。
+
+ +

データã«æ›¸å¼å‡ºåŠ›ã‚’è¡Œãªã†ã«ã¯ã€é–¢æ•° `cbdatumprintf' を用ã„る。

+ +
+
void cbdatumprintf(CBDATUM *datum, const char *format, ...);
+
`format' ã¯printf風ã®æ›¸å¼æ–‡å­—列を指定ã™ã‚‹ã€‚変æ›æ–‡å­— `%' ã‚’ `s'ã€`d'ã€`o'ã€`u'ã€`x'ã€`X'ã€`c'ã€`e'ã€`E'ã€`f'ã€`g'ã€`G'ã€`@'ã€`?'ã€`:'ã€`%' ã¨ä½µã›ã¦åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ãる。`@' 㯠`s' ã¨åŒæ§˜ã«æ©Ÿèƒ½ã™ã‚‹ãŒã€XMLã®ãƒ¡ã‚¿æ–‡å­—をエスケープã™ã‚‹ã€‚`?' 㯠`s' ã¨åŒæ§˜ã«æ©Ÿèƒ½ã™ã‚‹ãŒã€URLã®ãƒ¡ã‚¿æ–‡å­—をエスケープã™ã‚‹ã€‚`:' 㯠`s' ã¨åŒæ§˜ã«æ©Ÿèƒ½ã™ã‚‹ãŒã€UTF-8ã¨ã—ã¦ã®MIMEエンコーディングを施ã™ã€‚ãれ以外ã®å¤‰æ›æ–‡å­—ã¯å…ƒæ¥ã®ã‚‚ã®ã¨åŒæ§˜ã«æ©Ÿèƒ½ã™ã‚‹ã€‚
+
+ +

データを確ä¿ã•ã‚ŒãŸé ˜åŸŸã«å¤‰æ›ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbdatumtomalloc' を用ã„る。

+ +
+
char *cbdatumtomalloc(CBDATUM *datum, int *sp);
+
`datum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。元ã®ãƒ‡ãƒ¼ã‚¿ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ãれをå†ã³è§£æ”¾ã—ã¦ã¯ãªã‚‰ãªã„。
+
+ +

リストãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistopen' を用ã„る。

+ +
+
CBLIST *cblistopen(void);
+
戻り値ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。
+
+ +

リストを複製ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistdup' を用ã„る。

+ +
+
CBLIST *cblistdup(const CBLIST *list);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ–°ã—ã„リストãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。
+
+ +

リストãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistclose' を用ã„る。

+ +
+
void cblistclose(CBLIST *list);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ããªããªã‚‹ã€‚
+
+ +

リストã«æ ¼ç´ã•ã‚ŒãŸè¦ç´ æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cblistnum' を用ã„る。

+ +
+
int cblistnum(const CBLIST *list);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒªã‚¹ãƒˆã«æ ¼ç´ã•ã‚ŒãŸè¦ç´ æ•°ã§ã‚る。
+
+ +

リスト内ã®ã‚ã‚‹è¦ç´ ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cblistval' を用ã„る。

+ +
+
const char *cblistval(const CBLIST *list, int index, int *sp);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`index' ã¯å–り出ã™è¦ç´ ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯è©²å½“è¦ç´ ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。`index' ãŒè¦ç´ æ•°ä»¥ä¸Šãªã‚‰ã°ã€æˆ»ã‚Šå€¤ã¯ `NULL' ã§ã‚る。
+
+ +

è¦ç´ ã‚’リストã®æœ«å°¾ã«åŠ ãˆã‚‹ã«ã¯ã€é–¢æ•° `cblistpush' を用ã„る。

+ +
+
void cblistpush(CBLIST *list, const char *ptr, int size);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`ptr' ã¯è¿½åŠ ã™ã‚‹è¦ç´ ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ãŒã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚
+
+ +

リストã®æœ«å°¾ã®è¦ç´ ã‚’削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistpop' を用ã„る。

+ +
+
char *cblistpop(CBLIST *list, int *sp);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯è©²å½“è¦ç´ ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。リストãŒç©ºãªã‚‰ã°ã€æˆ»ã‚Šå€¤ã¯ `NULL' ã§ã‚る。
+
+ +

è¦ç´ ã‚’リストã®å…ˆé ­ã«åŠ ãˆã‚‹ã«ã¯ã€é–¢æ•° `cblistunshift' を用ã„る。

+ +
+
void cblistunshift(CBLIST *list, const char *ptr, int size);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`ptr' ã¯è¿½åŠ ã™ã‚‹è¦ç´ ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ãŒã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚
+
+ +

リストã®å…ˆé ­ã®è¦ç´ ã‚’削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistshift' を用ã„る。

+ +
+
char *cblistshift(CBLIST *list, int *sp);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯è©²å½“è¦ç´ ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。リストãŒç©ºãªã‚‰ã°ã€æˆ»ã‚Šå€¤ã¯ `NULL' ã§ã‚る。
+
+ +

リスト内ã®æŒ‡å®šã—ãŸä½ç½®ã«è¦ç´ ã‚’加ãˆã‚‹ã«ã¯ã€é–¢æ•° `cblistinsert' を用ã„る。

+ +
+
void cblistinsert(CBLIST *list, int index, const char *ptr, int size);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`index' ã¯è¿½åŠ ã™ã‚‹è¦ç´ ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’指定ã™ã‚‹ã€‚`ptr' ã¯è¿½åŠ ã™ã‚‹è¦ç´ ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ãŒã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚
+
+ +

リスト内ã®æŒ‡å®šã—ãŸä½ç½®ã®è¦ç´ ã‚’削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistremove' を用ã„る。

+ +
+
char *cblistremove(CBLIST *list, int index, int *sp);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`index' ã¯å‰Šé™¤ã™ã‚‹è¦ç´ ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯è©²å½“è¦ç´ ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。`index' ãŒè¦ç´ æ•°ä»¥ä¸Šãªã‚‰ã°ã€è¦ç´ ã¯å‰Šé™¤ã•ã‚Œãšã€æˆ»ã‚Šå€¤ã¯ `NULL' ã§ã‚る。
+
+ +

リスト内ã®æŒ‡å®šã—ãŸä½ç½®ã®è¦ç´ ã‚’上書ãã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistover' を用ã„る。

+ +
+
void cblistover(CBLIST *list, int index, const char *ptr, int size);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`index' ã¯å‰Šé™¤ã™ã‚‹è¦ç´ ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’指定ã™ã‚‹ã€‚`ptr' ã¯æ–°ã—ã„内容ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ãŒã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚`index' ãŒè¦ç´ æ•°ä»¥ä¸Šãªã‚‰ã°ã€ã“ã®é–¢æ•°ã¯ä½•ã‚‚ã—ãªã„。
+
+ +

リストã®è¦ç´ ã‚’辞書順ã§æ•´åˆ—ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `cblistsort' を用ã„る。

+ +
+
void cblistsort(CBLIST *list);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚整列ã«ã¯ã‚¯ã‚¤ãƒƒã‚¯ã‚½ãƒ¼ãƒˆãŒç”¨ã„られる。
+
+ +

リストã®è¦ç´ ã‚’線形探索を使ã£ã¦æ¤œç´¢ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistlsearch' を用ã„る。

+ +
+
int cblistlsearch(const CBLIST *list, const char *ptr, int size);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`ptr' ã¯æ¤œç´¢ã‚­ãƒ¼ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ãŒã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯è©²å½“ã®è¦ç´ ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã§ã‚ã‚‹ãŒã€è©²å½“ãŒãªã‘れ㰠-1 ã§ã‚る。複数ã®è¦ç´ ãŒè©²å½“ã—ãŸå ´åˆã€å‰è€…ãŒè¿”ã•ã‚Œã‚‹ã€‚
+
+ +

リストã®è¦ç´ ã‚’二分探索を使ã£ã¦æ¤œç´¢ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistbsearch' を用ã„る。

+ +
+
int cblistbsearch(const CBLIST *list, const char *ptr, int size);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚リストã¯è¾žæ›¸é †ã«ã‚½ãƒ¼ãƒˆã•ã‚Œã¦ã„ã‚‹å¿…è¦ãŒã‚る。`ptr' ã¯æ¤œç´¢ã‚­ãƒ¼ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ãŒã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯è©²å½“ã®è¦ç´ ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã§ã‚ã‚‹ãŒã€è©²å½“ãŒãªã‘れ㰠-1 ã§ã‚る。複数ã®è¦ç´ ãŒè©²å½“ã—ãŸå ´åˆã«ã©ã¡ã‚‰ãŒè¿”ã‚‹ã‹ã¯æœªå®šç¾©ã§ã‚る。
+
+ +

リストを直列化ã—ã¦ãƒã‚¤ãƒˆé…列ã«ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistdump' を用ã„る。

+ +
+
char *cblistdump(const CBLIST *list, int *sp);
+
`list' ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`sp' ã¯æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ç›´åˆ—化ã•ã‚ŒãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

直列化ã•ã‚ŒãŸãƒªã‚¹ãƒˆã‚’復元ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblistload' を用ã„る。

+ +
+
CBLIST *cblistload(const char *ptr, int size);
+
`ptr' ã¯ãƒã‚¤ãƒˆé…列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ–°ã—ã„リストãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。
+
+ +

マップãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmapopen' を用ã„る。

+ +
+
CBMAP *cbmapopen(void);
+
戻り値ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。
+
+ +

マップを複製ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmapdup' を用ã„る。

+ +
+
CBMAP *cbmapdup(CBMAP *map);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ–°ã—ã„マップãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。コピー元ã®ãƒžãƒƒãƒ—ã®ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã¯åˆæœŸåŒ–ã•ã‚Œã‚‹ã€‚
+
+ +

マップãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmapclose' を用ã„る。

+ +
+
void cbmapclose(CBMAP *map);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã§ããªããªã‚‹ã€‚
+
+ +

マップã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmapput' を用ã„る。

+ +
+
int cbmapput(CBMAP *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int over);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`vbuf' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`vsiz' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(vbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`over' ã¯é‡è¤‡ã—ãŸãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’上書ãã™ã‚‹ã‹å¦ã‹ã‚’指定ã™ã‚‹ã€‚`over' ãŒå½ã§ã‚­ãƒ¼ãŒé‡è¤‡ã—ãŸå ´åˆã¯æˆ»ã‚Šå€¤ã¯å½ã§ã‚ã‚‹ãŒã€ãã†ã§ãªã„å ´åˆã¯çœŸã§ã‚る。
+
+ +

既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã®æœ«å°¾ã«å€¤ã‚’連çµã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmapputcat' を用ã„る。

+ +
+
void cbmapputcat(CBMAP *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`vbuf' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`vsiz' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(vbuf)' ã®å€¤ã¨ãªã‚‹ã€‚該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒå­˜åœ¨ã—ãªã„å ´åˆã¯æ–°ã—ã„レコードãŒä½œã‚‰ã‚Œã‚‹ã€‚
+
+ +

マップã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmapout' を用ã„る。

+ +
+
int cbmapout(CBMAP *map, const char *kbuf, int ksiz);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€è©²å½“ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã¯å½ã§ã‚る。
+
+ +

マップã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmapget' を用ã„る。

+ +
+
const char *cbmapget(const CBMAP *map, const char *kbuf, int ksiz, int *sp);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€è©²å½“ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã¯ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。
+
+ +

レコードをマップã®ç«¯ã«ç§»å‹•ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `cbmapmove' を用ã„る。

+ +
+
int cbmapmove(CBMAP *map, const char *kbuf, int ksiz, int head);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`head' ã¯ç§»å‹•å…ˆã‚’指定ã—ã€çœŸãªã‚‰å…ˆé ­ã€å½ãªã‚‰æœ«å°¾ã¨ãªã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€è©²å½“ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã¯å½ã§ã‚る。
+
+ +

マップã®ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‚’åˆæœŸåŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmapiterinit' を用ã„る。

+ +
+
void cbmapiterinit(CBMAP *map);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚イテレータã¯ã€ãƒžãƒƒãƒ—ã«æ ¼ç´ã•ã‚ŒãŸå…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å‚ç…§ã™ã‚‹ãŸã‚ã«ç”¨ã„られる。
+
+ +

マップã®ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‹ã‚‰æ¬¡ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã‚’å–り出ã™ã«ã¯ã€é–¢æ•° `cbmapiternext' を用ã„る。

+ +
+
const char *cbmapiternext(CBMAP *map, int *sp);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ã‚­ãƒ¼ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。イテレータãŒæœ€å¾Œã¾ã§ãã¦è©²å½“ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。å–り出ã™é †ç•ªã¯æ ¼ç´ã—ãŸéš›ã®é †ç•ªã«ä¸€è‡´ã™ã‚‹ã“ã¨ãŒä¿è¨¼ã•ã‚Œã¦ã„る。
+
+ +

マップã®ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‹ã‚‰å–り出ã—ãŸã‚­ãƒ¼ã«å¯¾å¿œã™ã‚‹å€¤ã‚’å–り出ã™ã«ã¯ã€é–¢æ•°ã€€`cbmapiterval' を用ã„る。

+ +
+
const char *cbmapiterval(const char *kbuf, int *sp);
+
`kbuf' ã¯ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‹ã‚‰å–り出ã—ãŸã‚­ãƒ¼ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。
+
+ +

マップã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbmaprnum' を用ã„る。

+ +
+
int cbmaprnum(const CBMAP *map);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã§ã‚る。
+
+ +

マップã«å«ã¾ã‚Œã‚‹å…¨ã¦ã®ã‚­ãƒ¼ã‚’å«ã‚€ãƒªã‚¹ãƒˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbmapkeys' を用ã„る。

+ +
+
CBLIST *cbmapkeys(CBMAP *map);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒžãƒƒãƒ—ã«å«ã¾ã‚Œã‚‹å…¨ã¦ã®ã‚­ãƒ¼ã‚’å«ã‚€ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

マップã«å«ã¾ã‚Œã‚‹å…¨ã¦ã®å€¤ã‚’å«ã‚€ãƒªã‚¹ãƒˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbmapvals' を用ã„る。

+ +
+
CBLIST *cbmapvals(CBMAP *map);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒžãƒƒãƒ—ã«å«ã¾ã‚Œã‚‹å…¨ã¦ã®å€¤ã‚’å«ã‚€ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

マップを直列化ã—ã¦ãƒã‚¤ãƒˆé…列ã«ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmapdump' を用ã„る。

+ +
+
char *cbmapdump(const CBMAP *map, int *sp);
+
`map' ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`sp' ã¯æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ç›´åˆ—化ã•ã‚ŒãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

直列化ã•ã‚ŒãŸãƒžãƒƒãƒ—を復元ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmapload' を用ã„る。

+ +
+
CBMAP *cbmapload(const char *ptr, int size);
+
`ptr' ã¯ãƒã‚¤ãƒˆé…列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ–°ã—ã„マップãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。
+
+ +

直列化ã—ãŸãƒžãƒƒãƒ—ã‹ã‚‰ã²ã¨ã¤ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’抽出ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmaploadone' を用ã„る。

+ +
+
char *cbmaploadone(const char *ptr, int size, const char *kbuf, int ksiz, int *sp);
+
`ptr' ã¯ãƒã‚¤ãƒˆé…列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€è©²å½“ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã¯ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。
+
+ +

ヒープãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `cbheapopen' を用ã„る。

+ +
+
CBHEAP *cbheapopen(int size, int max, int(*compar)(const void *, const void *));
+
`size' ã¯å„レコードã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚`max' ã¯ãƒ’ープã«æ ¼ç´ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ã€‚`compar' ã¯æ¯”較関数を指定ã™ã‚‹ã€‚二ã¤ã®å¼•æ•°ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。比較関数ã¯å‰è€…ãŒå¤§ãã‘ã‚Œã°æ­£æ•°ã‚’ã€å¾Œè€…ãŒå¤§ãã‘ã‚Œã°è² æ•°ã‚’ã€ä¸¡è€…ãŒç­‰ã—ã‘れ㰠0 ã‚’è¿”ã™ã¹ãã§ã‚る。戻り値ã¯ãƒ’ープãƒãƒ³ãƒ‰ãƒ«ã€‚
+
+ +

ヒープãƒãƒ³ãƒ‰ãƒ«ã‚’複製ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbheapdup' を用ã„る。

+ +
+
CBHEAP *cbheapdup(CBHEAP *heap);
+
`heap' ã¯ãƒ’ープãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ–°ã—ã„ヒープãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。
+
+ +

ヒープãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbheapclose' を用ã„る。

+ +
+
void cbheapclose(CBHEAP *heap);
+
`heap' ã¯ãƒ’ープãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ããªããªã‚‹ã€‚
+
+ +

ヒープã«æ ¼ç´ã•ã‚ŒãŸãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbheapnum' を用ã„る。

+ +
+
int cbheapnum(CBHEAP *heap);
+
`heap' ã¯ãƒ’ープãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒªã‚¹ãƒˆã«æ ¼ç´ã•ã‚ŒãŸãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã§ã‚る。
+
+ +

ヒープã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’挿入ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbheapinsert' を用ã„る。

+ +
+
int cbheapinsert(CBHEAP *heap, const void *ptr);
+
`heap' ã¯ãƒ’ープãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`ptr' ã¯è¿½åŠ ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒè¿½åŠ ã•ã‚Œã‚Œã°çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。新ã—ã„レコードã®å€¤ãŒæ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æœ€å¤§å€¤ã‚ˆã‚Šå¤§ãã‘ã‚Œã°ã€æ–°ã—ã„レコードã¯è¿½åŠ ã•ã‚Œãªã„。新ã—ã„レコードãŒè¿½åŠ ã•ã‚Œã¦ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ãŒæœ€å¤§æ•°ã‚’越ãˆãŸå ´åˆã€æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æœ€å¤§å€¤ã®ã‚‚ã®ãŒå‰Šé™¤ã•ã‚Œã‚‹ã€‚
+
+ +

ヒープ内ã®ã‚るレコードã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbheapget' を用ã„る。

+ +
+
void *cbheapval(CBHEAP *heap, int index);
+
`heap' ã¯ãƒ’ープãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`index' ã¯å–り出ã™ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’指定ã™ã‚‹ã€‚戻り値ã¯è©²å½“レコードã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。`index' ãŒè¦ç´ æ•°ä»¥ä¸Šãªã‚‰ã°ã€æˆ»ã‚Šå€¤ã¯ `NULL' ã§ã‚る。レコードã¯å†…部的ã«ã¯æ¯”較関数ã®è² å€¤ã«åŸºã¥ã„ã¦çµ„織化ã•ã‚Œã¦ã„ã‚‹ã“ã¨ã«æ³¨æ„ã™ã¹ãã§ã‚る。
+
+ +

ヒープを確ä¿ã•ã‚ŒãŸé ˜åŸŸã«å¤‰æ›ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbheaptomalloc' を用ã„る。

+ +
+
void *cbheaptomalloc(CBHEAP *heap, int *np);
+
`heap' ã¯ãƒ’ープãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`np' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯ãƒ’ープã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。レコードã¯ã‚½ãƒ¼ãƒˆæ¸ˆã¿ã«ãªã‚‹ã€‚戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。元ã®ãƒ‡ãƒ¼ã‚¿ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ãれをå†ã³è§£æ”¾ã—ã¦ã¯ãªã‚‰ãªã„。
+
+ +

書å¼ã«åŸºã¥ã„ãŸæ–‡å­—列をメモリ上ã§ç¢ºä¿ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbsprintf' を用ã„る。

+ +
+
char *cbsprintf(const char *format, ...);
+
`format' ã¯printf風ã®æ›¸å¼æ–‡å­—列を指定ã™ã‚‹ã€‚変æ›æ–‡å­— `%' をフラグ文字 `d'ã€`o'ã€`u'ã€`x'ã€`X'ã€`e'ã€`E'ã€`f'ã€`g'ã€`G'ã€`c'ã€`s' ãŠã‚ˆã³ `%' ã‚’ä¼´ã‚ã›ã¦ä½¿ç”¨ã™ã‚‹ã“ã¨ãŒã§ãる。フィールドã®å¹…ã¨ç²¾åº¦ã®æŒ‡ç¤ºå­ã‚’変æ›æ–‡å­—ã¨ãƒ•ãƒ©ã‚°æ–‡å­—ã®é–“ã«ç½®ãã“ã¨ãŒã§ãる。ãã®æŒ‡ç¤ºå­ã¯10進数字ã€`.'ã€`+'ã€`-' ãŠã‚ˆã³ã‚¹ãƒšãƒ¼ã‚¹æ–‡å­—ã‹ã‚‰ãªã‚‹ã€‚ãã®ä»–ã®å¼•æ•°ã¯æ›¸å¼æ–‡å­—列ã«ã‚ˆã£ã¦åˆ©ç”¨ã•ã‚Œã‚‹ã€‚戻り値ã¯çµæžœã®æ–‡å­—列ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

文字列中ã®ãƒ‘ターンを置æ›ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbreplace' を用ã„る。

+ +
+
char *cbreplace(const char *str, CBMAP *pairs);
+
`str' ã¯ç½®æ›å‰ã®æ–‡å­—列を指定ã™ã‚‹ã€‚`pairs' ã¯ç½®æ›ã®ãƒšã‚¢ã‹ã‚‰ãªã‚‹ãƒžãƒƒãƒ—ã®ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚å„ペアã®ã‚­ãƒ¼ã¯ç½®æ›å‰ã®ãƒ‘ターンを指定ã—ã€å€¤ã¯ç½®æ›å¾Œã®ãƒ‘ターンを指定ã™ã‚‹ã€‚戻り値ã¯çµæžœã®æ–‡å­—列ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

一連ã®ãƒ‡ãƒ¼ã‚¿ã‚’分割ã—ã¦ãƒªã‚¹ãƒˆã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `cbsplit' を用ã„る。

+ +
+
CBLIST *cbsplit(const char *ptr, int size, const char *delim);
+
`ptr' ã¯å†…容ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚`delim' ã¯åŒºåˆ‡ã‚Šæ–‡å­—ã‚’å«ã‚€æ–‡å­—列を指定ã™ã‚‹ã‹ã€`NULL' ãªã‚‰çµ‚端文字を区切り文字ã¨ã™ã‚‹ã€‚戻り値ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。区切り文字ãŒé€£ç¶šã—ã¦ã„ã‚‹å ´åˆã§ã‚‚ã€ãã®é–“ã«ç©ºã®è¦ç´ ãŒã‚ã‚‹ã¨ã¿ãªã™ã€‚戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

ファイルã®å…¨ãƒ‡ãƒ¼ã‚¿ã‚’読ã¿è¾¼ã‚€ã«ã¯ã€é–¢æ•° `cbreadfile' を用ã„る。

+ +
+
char *cbreadfile(const char *name, int *sp);
+
`name' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ãŒã€`NULL' ãªã‚‰æ¨™æº–入力を読ã¿è¾¼ã‚€ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰èª­ã¿è¾¼ã‚“ã ãƒ‡ãƒ¼ã‚¿ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

一連ã®ãƒ‡ãƒ¼ã‚¿ã‚’ファイルã«æ›¸ã込むã«ã¯ã€é–¢æ•° `cbwritefile' を用ã„る。

+ +
+
int cbwritefile(const char *name, const char *ptr, int size);
+
`name' ã¯ãƒ•ã‚¡ã‚¤ãƒ«åを指定ã™ã‚‹ãŒã€`NULL' ãªã‚‰æ¨™æº–出力ã«æ›¸ã出ã•ã‚Œã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€è©²å½“ã®ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。ファイルãŒå­˜åœ¨ã™ã‚‹å ´åˆã«ã¯ä¸Šæ›¸ãã•ã‚Œã€ãã†ã§ãªã„å ´åˆã¯æ–°ã—ã„ファイルãŒç”Ÿæˆã•ã‚Œã‚‹ã€‚
+
+ +

ファイルã®å„行を読ã¿è¾¼ã‚€ã«ã¯ã€é–¢æ•° `cbreadlines' を用ã„る。

+ +
+
CBLIST *cbreadlines(const char *name);
+
`name' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ãŒã€`NULL' ãªã‚‰æ¨™æº–入力を読ã¿è¾¼ã‚€ã€‚æˆåŠŸã™ã‚Œã°æˆ»ã‚Šå€¤ã¯å„è¡Œã®ãƒ‡ãƒ¼ã‚¿ã‚’ä¿æŒã™ã‚‹ãƒªã‚¹ãƒˆã®ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚Šã€å¤±æ•—ãªã‚‰ `NULL' ã§ã‚る。改行文字ã¯å‰Šé™¤ã•ã‚Œã‚‹ã€‚戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

ディレクトリã«å«ã¾ã‚Œã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã®ãƒªã‚¹ãƒˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbdirlist' を用ã„る。

+ +
+
CBLIST *cbdirlist(const char *name);
+
`name' ã¯ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®åå‰ã‚’指定ã™ã‚‹ã€‚æˆåŠŸã™ã‚Œã°æˆ»ã‚Šå€¤ã¯å„ファイルã®åå‰ã‚’ä¿æŒã™ã‚‹ãƒªã‚¹ãƒˆã®ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚Šã€å¤±æ•—ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

ファイルやディレクトリã®çŠ¶æ…‹ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbfilestat' を用ã„る。

+ +
+
int cbfilestat(const char *name, int *isdirp, int *sizep, int *mtimep);
+
`name' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ã‚„ディレクトリã®åå‰ã‚’指定ã™ã‚‹ã€‚`dirp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«ãƒ•ã‚¡ã‚¤ãƒ«ãŒãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã‹å¦ã‹ã‚’æ ¼ç´ã™ã‚‹ã€‚`sizep' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚`mtimep' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«ãƒ•ã‚¡ã‚¤ãƒ«ã®æœ€çµ‚更新時刻を格ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。ファイルãŒå­˜åœ¨ã—ãªã„å ´åˆã‚„パーミッションãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

ファイルã‹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã¨ãã®å†…容を削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbremove' を用ã„る。

+ +
+
int cbremove(const char *name);
+
`name' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ã‚„ディレクトリã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。ファイルãŒå­˜åœ¨ã—ãªã„å ´åˆã‚„パーミッションãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

URLを構æˆè¦ç´ ã«åˆ†è§£ã™ã‚‹ã«ã¯ã€é–¢æ•° `cburlbreak' を用ã„る。

+ +
+
CBMAP *cburlbreak(const char *str);
+
`str' ã¯URLã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。マップã®å„キーã¯è¦ç´ åã§ã‚る。キー "self" ã¯URLãれ自体を指示ã™ã‚‹ã€‚キー "scheme" ã¯URLã®ã‚¹ã‚­ãƒ¼ãƒ ã‚’指示ã™ã‚‹ã€‚キー "host" ã¯ã‚µãƒ¼ãƒã®ãƒ›ã‚¹ãƒˆåを指示ã™ã‚‹ã€‚キー "port" ã¯ã‚µãƒ¼ãƒã®ãƒãƒ¼ãƒˆç•ªå·ã‚’指示ã™ã‚‹ã€‚キー "authority" ã¯èªè¨¼æƒ…報を指示ã™ã‚‹ã€‚キー "path" ã¯ãƒªã‚½ãƒ¼ã‚¹ã®ãƒ‘スを指示ã™ã‚‹ã€‚キー "file" ã¯ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªéƒ¨åˆ†ã‚’除ã„ãŸãƒ•ã‚¡ã‚¤ãƒ«åを指示ã™ã‚‹ã€‚キー "query" ã¯ã‚¯ã‚¨ãƒªæ–‡å­—列を指示ã™ã‚‹ã€‚キー "fragment" ã¯ãƒ•ãƒ©ã‚°ãƒ¡ãƒ³ãƒˆæ–‡å­—列を指示ã™ã‚‹ã€‚サãƒãƒ¼ãƒˆã•ã‚Œã‚‹ã‚¹ã‚­ãƒ¼ãƒ ã¯HTTPã¨HTTPSã¨FTPã¨FILEã§ã‚る。絶対URLã«ã‚‚相対URLã«ã‚‚対応ã™ã‚‹ã€‚戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cbmapopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cbmapclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

相対URLを絶対URLを用ã„ã¦è§£æ±ºã™ã‚‹ã«ã¯ã€é–¢æ•° `cburlresolve' を用ã„る。

+ +
+
char *cburlresolve(const char *base, const char *target);
+
`base' ã¯ãƒ™ãƒ¼ã‚¹ãƒ­ã‚±ãƒ¼ã‚·ãƒ§ãƒ³ã®çµ¶å¯¾URLを指定ã™ã‚‹ã€‚`target' ã¯è§£æ±ºã™ã¹ãURLを指定ã™ã‚‹ã€‚戻り値ã¯è§£æ±ºã•ã‚ŒãŸURLã§ã‚る。ターゲットURLãŒç›¸å¯¾URLã®å ´åˆã€ãƒ™ãƒ¼ã‚¹ãƒ­ã‚±ãƒ¼ã‚·ãƒ§ãƒ³ã‹ã‚‰ã®ç›¸å¯¾ä½ç½®ã®URLã‚’è¿”ã™ã€‚ターゲットURLãŒçµ¶å¯¾URLã®å ´åˆã€ã‚¿ãƒ¼ã‚²ãƒƒãƒˆURLã®ã‚³ãƒ”ーを返ã™ã€‚戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

一連ã®ã‚ªãƒ–ジェクトをURLエンコーディングã§ç¬¦å·åŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `cburlencode' を用ã„る。

+ +
+
char *cburlencode(const char *ptr, int size);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯çµæžœã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

URLエンコーディングã§ç¬¦å·åŒ–ã•ã‚ŒãŸæ–‡å­—列を復元ã™ã‚‹ã«ã¯ã€é–¢æ•° `cburldecode' を用ã„る。

+ +
+
char *cburldecode(const char *str, int *sp);
+
`str' ã¯ç¬¦å·åŒ–ã•ã‚ŒãŸæ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

一連ã®ã‚ªãƒ–ジェクトをBase64エンコーディングã§ç¬¦å·åŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbbaseencode' を用ã„る。

+ +
+
char *cbbaseencode(const char *ptr, int size);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯çµæžœã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

Base64エンコーディングã§ç¬¦å·åŒ–ã•ã‚ŒãŸæ–‡å­—列を復元ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbbasedecode' を用ã„る。

+ +
+
char *cbbasedecode(const char *str, int *sp);
+
`str' ã¯ç¬¦å·åŒ–ã•ã‚ŒãŸæ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

一連ã®ã‚ªãƒ–ジェクトをquoted-printableエンコーディングã§ç¬¦å·åŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbquoteencode' を用ã„る。

+ +
+
char *cbquoteencode(const char *ptr, int size);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯çµæžœã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

quoted-printableエンコーディングã§ç¬¦å·åŒ–ã•ã‚ŒãŸæ–‡å­—列を復元ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbquotedecode' を用ã„る。

+ +
+
char *cbquotedecode(const char *str, int *sp);
+
`str' ã¯ç¬¦å·åŒ–ã•ã‚ŒãŸæ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

MIMEã®æ–‡å­—列をヘッダã¨ãƒœãƒ‡ã‚£ã«åˆ†å‰²ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmimebreak' を用ã„る。

+ +
+
char *cbmimebreak(const char *ptr, int size, CBMAP *attrs, int *sp);
+
`ptr' ã¯MIMEã®ãƒ‡ãƒ¼ã‚¿ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚`attrs' ã¯å±žæ€§ã‚’ä¿å­˜ã™ã‚‹ãŸã‚ã®ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ãŒã€`NULL' ã®å ´åˆã«ã¯åˆ©ç”¨ã•ã‚Œãªã„。マップã®å„キーã¯å°æ–‡å­—ã«æ­£è¦åŒ–ã•ã‚ŒãŸå±žæ€§åã§ã‚る。`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯ãƒœãƒ‡ã‚£ã®æ–‡å­—列ã§ã‚る。コンテントタイプãŒæŒ‡å®šã•ã‚Œã¦ã„ã‚‹å ´åˆã€ãƒžãƒƒãƒ—ã®ã‚­ãƒ¼ "TYPE" ã¯ãã®ã‚¿ã‚¤ãƒ—を指示ã™ã‚‹ã€‚文字コードãŒæŒ‡å®šã•ã‚Œã¦ã„ã‚‹å ´åˆã€ã‚­ãƒ¼ "CHARSET" ã¯ãã®ã‚³ãƒ¼ãƒ‰åを指示ã™ã‚‹ã€‚マルãƒãƒ‘ートã®åŒºåˆ‡ã‚Šæ–‡å­—列ãŒæŒ‡å®šã•ã‚Œã¦ã„ã‚‹å ´åˆã€ã‚­ãƒ¼ "BOUNDARY" ã¯ãã®æ–‡å­—列を指示ã™ã‚‹ã€‚コンテントディスãƒã‚¸ã‚·ãƒ§ãƒ³ãŒæŒ‡å®šã•ã‚Œã¦ã„ã‚‹å ´åˆã€ã‚­ãƒ¼ "DISPOSITION" ã¯ãã®æ–¹é‡ã‚’指示ã™ã‚‹ã€‚ファイルåãŒæŒ‡å®šã•ã‚Œã¦ã„ã‚‹å ´åˆã€ã‚­ãƒ¼ "FILENAME" ã¯ãã®åå‰ã‚’指示ã™ã‚‹ã€‚属性åãŒæŒ‡å®šã•ã‚Œã¦ã„ã‚‹å ´åˆã€ã‚­ãƒ¼ "NAME" ã¯ãã®åå‰ã‚’指示ã™ã‚‹ã€‚戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

MIMEã®ãƒžãƒ«ãƒãƒ‘ートデータã®æ–‡å­—列をå„パートã«åˆ†å‰²ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmimeparts' を用ã„る。

+ +
+
CBLIST *cbmimeparts(const char *ptr, int size, const char *boundary);
+
`ptr' ã¯MIMEã®ãƒ‡ãƒ¼ã‚¿ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚`boundary' ã¯åŒºåˆ‡ã‚Šæ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。リストã®å„è¦ç´ ã¯ãƒ‘ートã®æ–‡å­—列ã§ã‚る。戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

文字列をMIMEエンコーディングã§ç¬¦å·åŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmimeencode' を用ã„る。

+ +
+
char *cbmimeencode(const char *str, const char *encname, int base);
+
`str' ã¯æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`encname' ã¯æ–‡å­—コードåã®æ–‡å­—列を指定ã™ã‚‹ã€‚`base' ã¯Base64エンコードを使ã†ã‹å¦ã‹ã‚’指定ã™ã‚‹ã€‚å½ã®å ´åˆã¯quoted-printableãŒç”¨ã„られる。戻り値ã¯çµæžœã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

MIMEエンコーディングã§ç¬¦å·åŒ–ã•ã‚ŒãŸæ–‡å­—列を復元ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbmimedecode' を用ã„る。

+ +
+
char *cbmimedecode(const char *str, char *enp);
+
`str' ã¯ç¬¦å·åŒ–ã•ã‚ŒãŸæ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`enp' ã¯æ–‡å­—コードåを書ã込むãŸã‚ã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ãŒã€`NULL' ã®å ´åˆã¯åˆ©ç”¨ã•ã‚Œãªã„。ãƒãƒƒãƒ•ã‚¡ã®ã‚µã‚¤ã‚ºã¯32ãƒã‚¤ãƒˆä»¥ä¸Šã§ãªã‘ã‚Œã°ãªã‚‰ãªã„。戻り値ã¯çµæžœã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

CSVã®æ–‡å­—列を行ã«åˆ†å‰²ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbcsvrows' を用ã„る。

+ +
+
CBLIST *cbcsvrows(const char *str);
+
`str' ã¯CSVã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。リストã®å„è¦ç´ ã¯è¡Œã®æ–‡å­—列ã§ã‚る。戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。入力文字列ã®æ–‡å­—コードã¯US-ASCIIã€UTF-8ã€ISO-8859-*ã€EUC-*ã€Shift_JISã®ã©ã‚Œã‹ã§ã‚ã‚‹å¿…è¦ãŒã‚る。MS-Excelã¨äº’æ›ã—ã¦ã€ã“れらCSV用関数群ã¯ã€ãƒ€ãƒ–ルクォートã§å›²ã‚“ã§ã‚³ãƒ³ãƒžãªã©ã®ãƒ¡ã‚¿æ–‡å­—ã‚’å«ã‚ãŸã‚»ãƒ«ã‚’扱ã†ã“ã¨ãŒã§ãる。
+
+ +

CSVã®è¡Œã®æ–‡å­—列をセルã«åˆ†å‰²ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbcsvcells' を用ã„る。

+ +
+
CBLIST *cbcsvcells(const char *str);
+
`str' ã¯CSVã®è¡Œã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。リストã®å„è¦ç´ ã¯ã‚»ãƒ«å†…容をアンエスケープã—ãŸæ–‡å­—列ã§ã‚る。戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

CSVã®ãƒ¡ã‚¿æ–‡å­—をエスケープã—ãŸæ–‡å­—列を得るã«ã¯ã€é–¢æ•° `cbcsvescape' を用ã„る。

+ +
+
char *cbcsvescape(const char *str);
+
`str' ã¯å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ¡ã‚¿æ–‡å­—を無効化ã—ãŸçµæžœã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

XMLã®å®Ÿä½“å‚照をアンエスケープã—ãŸæ–‡å­—列を得るã«ã¯ã€é–¢æ•° `cbcsvunescape' を用ã„る。

+ +
+
char *cbcsvunescape(const char *str);
+
`str' ã¯å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ¡ã‚¿æ–‡å­—ã‚’ä¼´ã£ãŸçµæžœã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

XMLã®æ–‡å­—列をタグã¨ãƒ†ã‚­ã‚¹ãƒˆã‚»ã‚¯ã‚·ãƒ§ãƒ³ã«åˆ†å‰²ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbxmlbreak' を用ã„る。

+ +
+
CBLIST *cbxmlbreak(const char *str, int cr);
+
`str' ã¯XMLã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`cr' ã¯ã‚³ãƒ¡ãƒ³ãƒˆã‚’削除ã™ã‚‹ã‹å¦ã‹ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。リストã®å„è¦ç´ ã¯ã‚¿ã‚°ã‹ãƒ†ã‚­ã‚¹ãƒˆã‚»ã‚¯ã‚·ãƒ§ãƒ³ã®æ–‡å­—列ã§ã‚る。戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。入力文字列ã®æ–‡å­—コードã¯US-ASCIIã€UTF-8ã€ISO-8859-*ã€EUC-*ã€Shift_JISã®ã©ã‚Œã‹ã§ã‚ã‚‹å¿…è¦ãŒã‚る。ã“れらXML用関数群ã¯å¦¥å½“性検証を行ã†XMLパーザã§ã¯ãªã„ã®ã§ã€HTMLã‚„SGMLも扱ã†ã“ã¨ãŒã§ãる。
+
+ +

XMLã®ã‚¿ã‚°ã®å±žæ€§ã®ãƒžãƒƒãƒ—ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbxmlattrs' を用ã„る。

+ +
+
CBMAP *cbxmlattrs(const char *str);
+
`str' ã¯ã‚¿ã‚°ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。マップã®å„キーã¯å±žæ€§ã®åå‰ã§ã‚る。å„値ã¯ã‚¢ãƒ³ã‚¨ã‚¹ã‚±ãƒ¼ãƒ—ã•ã‚Œã‚‹ã€‚空文字列をキーã«ã™ã‚‹ã¨ã‚¿ã‚°ã®åå‰ã‚’å–り出ã™ã“ã¨ãŒã§ãる。戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cbmapopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cbmapclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

XMLã®ãƒ¡ã‚¿æ–‡å­—をエスケープã—ãŸæ–‡å­—列を得るã«ã¯ã€é–¢æ•° `cbxmlescape' を用ã„る。

+ +
+
char *cbxmlescape(const char *str);
+
`str' ã¯å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ¡ã‚¿æ–‡å­—を無効化ã—ãŸçµæžœã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。ã“ã®é–¢æ•°ã¯ `&'〠`<'ã€`>'ã€`"' ã®ã¿ã‚’変æ›ã™ã‚‹ã€‚戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

XMLã®å®Ÿä½“å‚照をアンエスケープã—ãŸæ–‡å­—列を得るã«ã¯ã€é–¢æ•° `cbxmlunescape' を用ã„る。

+ +
+
char *cbxmlunescape(const char *str);
+
`str' ã¯å¯¾è±¡ã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ¡ã‚¿æ–‡å­—ã‚’ä¼´ã£ãŸçµæžœã®æ–‡å­—列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚る。ã“ã®é–¢æ•°ã¯ `&amp;'ã€`&lt;'ã€`&gt;'ã€`&quot;' ã®ã¿ã‚’復元ã™ã‚‹ã€‚戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

ZLIBを用ã„ã¦ä¸€é€£ã®ã‚ªãƒ–ジェクトを圧縮ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbdeflate' を用ã„る。

+ +
+
char *cbdeflate(const char *ptr, int size, int *sp);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚`sp' ã®å‚照先ã«ã¯æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯QDBMãŒZLIBを有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

ZLIBを用ã„ã¦åœ§ç¸®ã•ã‚ŒãŸã‚ªãƒ–ジェクトを伸長ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbinflate' を用ã„る。

+ +
+
char *cbinflate(const char *ptr, int size, int *sp);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯QDBMãŒZLIBを有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

GZIPを用ã„ã¦ä¸€é€£ã®ã‚ªãƒ–ジェクトを圧縮ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbgzencode' を用ã„る。

+ +
+
char *cbgzencode(const char *ptr, int size, int *sp);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚`sp' ã®å‚照先ã«ã¯æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯QDBMãŒZLIBを有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

GZIPを用ã„ã¦åœ§ç¸®ã•ã‚ŒãŸã‚ªãƒ–ジェクトを伸長ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbgzdecode' を用ã„る。

+ +
+
char *cbgzdecode(const char *ptr, int size, int *sp);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯QDBMãŒZLIBを有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

一連ã®ã‚ªãƒ–ジェクトã®CRC32ãƒã‚§ãƒƒã‚¯ã‚µãƒ ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbgetcrc' を用ã„る。

+ +
+
unsigned int cbgetcrc(const char *ptr, int size);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯ã‚ªãƒ–ジェクトã®CRC32ãƒã‚§ãƒƒã‚¯ã‚µãƒ ã§ã‚る。ã“ã®é–¢æ•°ã¯QDBMãŒZLIBを有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

LZOを用ã„ã¦ä¸€é€£ã®ã‚ªãƒ–ジェクトを圧縮ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblzoencode' を用ã„る。

+ +
+
char *cblzoencode(const char *ptr, int size, int *sp);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚`sp' ã®å‚照先ã«ã¯æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯QDBMãŒLZOを有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

LZOを用ã„ã¦åœ§ç¸®ã•ã‚ŒãŸã‚ªãƒ–ジェクトを伸長ã™ã‚‹ã«ã¯ã€é–¢æ•° `cblzodecode' を用ã„る。

+ +
+
char *cblzodecode(const char *ptr, int size, int *sp);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯QDBMãŒLZOを有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

BZIP2を用ã„ã¦ä¸€é€£ã®ã‚ªãƒ–ジェクトを圧縮ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbbzencode' を用ã„る。

+ +
+
char *cbbzencode(const char *ptr, int size, int *sp);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚`sp' ã®å‚照先ã«ã¯æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯QDBMãŒBZIP2を有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

BZIP2を用ã„ã¦åœ§ç¸®ã•ã‚ŒãŸã‚ªãƒ–ジェクトを伸長ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbbzdecode' を用ã„る。

+ +
+
char *cbbzdecode(const char *ptr, int size, int *sp);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯QDBMãŒBZIP2を有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

文字列ã®æ–‡å­—コードを変æ›ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbiconv' を用ã„る。

+ +
+
char *cbiconv(const char *ptr, int size, const char *icode, const char *ocode, int *sp, int *mp);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚`icode' ã¯å…¥åŠ›æ–‡å­—列ã®æ–‡å­—コードã®åå‰ã‚’指定ã™ã‚‹ã€‚`outcode' ã¯å‡ºåŠ›æ–‡å­—列ã®æ–‡å­—コードã®åå‰ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚`mp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«å¤‰æ›ã«å¤±æ•—ã—ãŸæ–‡å­—æ•°ã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çµæžœã®é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。ã“ã®é–¢æ•°ã¯QDBMãŒICONVを有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

文字列ã®æ–‡å­—コードを自動判定ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbencname' を用ã„る。

+ +
+
const char *cbencname(const char *str, int size);
+
`ptr' ã¯é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãã®é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(ptr)' ã®å€¤ã¨ãªã‚‹ã€‚`icode' ã¯å…¥åŠ›æ–‡å­—列ã®æ–‡å­—コードã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ã‚¨ãƒ³ã‚³ãƒ¼ãƒ‰ã®åå‰ã®æ–‡å­—列ã§ã‚る。ç¾çŠ¶ã§ã¯ã€US-ASCIIã€ISO-2022-JPã€Shift_JISã€CP932ã€EUC-JPã€UTF-8ã€UTF-16ã€UTF-16BEãŠã‚ˆã³UTF-16LEã«å¯¾å¿œã—ã¦ã„る。ãã®ã„ãšã‚Œã§ã‚‚ãªã„å ´åˆã¯ã€ISO-8859-1ã¨åˆ¤å®šã™ã‚‹ã€‚ã“ã®é–¢æ•°ã¯QDBMãŒICONVを有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã®ã¿åˆ©ç”¨ã§ãる。
+
+ +

ローカル時間ã®ç§’å˜ä½ã®æ™‚差を得るã«ã¯ã€é–¢æ•° `cbjetlag' を用ã„る。

+ +
+
int cbjetlag(void);
+
戻り値ã¯ãƒ­ãƒ¼ã‚«ãƒ«æ™‚é–“ã®ç§’å˜ä½ã®æ™‚å·®ã§ã‚る。
+
+ +

ã‚る時間ã®ã‚°ãƒ¬ã‚´ãƒªã‚ªæš¦ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbcalendar' を用ã„る。

+ +
+
void cbcalendar(time_t t, int jl, int *yearp, int *monp, int *dayp, int *hourp, int *minp, int *secp);
+
`t' ã¯å¯¾è±¡ã®æ™‚間を指定ã™ã‚‹ãŒã€è² æ•°ãªã‚‰ç¾åœ¨æ™‚é–“ãŒä½¿ã‚れる。`jl' ã¯ã‚る場所ã®æ™‚差を秒å˜ä½ã§æŒ‡å®šã™ã‚‹ã€‚`yearp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«å¹´ã‚’æ ¼ç´ã™ã‚‹ã€‚`monp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æœˆã‚’æ ¼ç´ã™ã‚‹ã€‚1ã¯1月をæ„味ã—ã€12ã¯12月をæ„味ã™ã‚‹ã€‚`dayp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æ—¥ã‚’æ ¼ç´ã™ã‚‹ã€‚`hourp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æ™‚ã‚’æ ¼ç´ã™ã‚‹ã€‚`minp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«åˆ†ã‚’æ ¼ç´ã™ã‚‹ã€‚`secp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«ç§’ã‚’æ ¼ç´ã™ã‚‹ã€‚
+
+ +

ã‚る日付ã®æ›œæ—¥ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbdayofweek' を用ã„る。

+ +
+
int cbdayofweek(int year, int mon, int day);
+
`year' ã¯æ—¥ä»˜ã®å¹´ã‚’指定ã™ã‚‹ã€‚`mon' ã¯æ—¥ä»˜ã®æœˆã‚’指定ã™ã‚‹ã€‚`day' ã¯æ—¥ä»˜ã®æ—¥ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ›œæ—¥ã®å€¤ã§ã‚る。0ã¯æ—¥æ›œã‚’æ„味ã—ã€6ã¯åœŸæ›œã‚’æ„味ã™ã‚‹ã€‚
+
+ +

ã‚る日付をW3CDTFã®æ›¸å¼ã§è¡¨ã—ãŸæ–‡å­—列を得るã«ã¯ã€é–¢æ•° `cbdatestrwww' を用ã„る。

+ +
+
char *cbdatestrwww(time_t t, int jl);
+
`t' ã¯å¯¾è±¡ã®æ™‚間を指定ã™ã‚‹ãŒã€è² æ•°ãªã‚‰ç¾åœ¨æ™‚é–“ãŒä½¿ã‚れる。`jl' ã¯ã‚る場所ã®æ™‚差を秒å˜ä½ã§æŒ‡å®šã™ã‚‹ã€‚戻り値ã¯W3CDTFã®æ›¸å¼ï¼ˆYYYY-MM-DDThh:mm:ddTZD)ã®æ–‡å­—列ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

ã‚る日付をRFC 1123ã®æ›¸å¼ã§è¡¨ã—ãŸæ–‡å­—列を得るã«ã¯ã€é–¢æ•° `cbdatestrhttp' を用ã„る。

+ +
+
char *cbdatestrhttp(time_t t, int jl);
+
`t' ã¯å¯¾è±¡ã®æ™‚間を指定ã™ã‚‹ãŒã€è² æ•°ãªã‚‰ç¾åœ¨æ™‚é–“ãŒä½¿ã‚れる。`jl' ã¯ã‚る場所ã®æ™‚差を秒å˜ä½ã§æŒ‡å®šã™ã‚‹ã€‚戻り値ã¯RFC 1123ã®æ›¸å¼ï¼ˆWdy, DD-Mon-YYYY hh:mm:dd TZD)ã®æ–‡å­—列ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

10進数ã‹16進数ã‹W3CDTFã‹RFC 822(1123)ã®æ›¸å¼ã§è¡¨ã—ãŸæ–‡å­—列ã‹ã‚‰æ™‚é–“ã®å€¤ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `cbstrmktime' を用ã„る。

+ +
+
time_t cbstrmktime(const char *str);
+
`str' ã¯10進数ã‹16進数ã‹W3CDTFã‹RFC 822(1123)ã®æ›¸å¼ã§è¡¨ã—ãŸæ–‡å­—列を指定ã™ã‚‹ã€‚戻り値ã¯ãã®æ™‚é–“ã®å€¤ã‹ã€æ›¸å¼ãŒä¸æ­£ãªå ´åˆã¯ -1 ã§ã‚る。10進数㫠"s" を後置ã™ã‚‹ã¨ç§’å˜ä½ã‚’æ„味ã—ã€"m" を後置ã™ã‚‹ã¨åˆ†å˜ä½ã‚’æ„味ã—ã€"h" を後置ã™ã‚‹ã¨æ™‚å˜ä½ã‚’æ„味ã—ã€"d" を後置ã™ã‚‹ã¨æ—¥å˜ä½ã‚’æ„味ã™ã‚‹ã€‚
+
+ +

ユーザã¨ã‚·ã‚¹ãƒ†ãƒ ã®ãƒ—ロセス時間を得るã«ã¯ã€é–¢æ•° `cbproctime' を用ã„る。

+ +
+
void cbproctime(double *usrp, double *sysp);
+
`usrp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«ãƒ¦ãƒ¼ã‚¶æ™‚é–“ã‚’æ ¼ç´ã™ã‚‹ã€‚時間ã®å˜ä½ã¯ç§’ã§ã‚る。`sysp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«ã‚·ã‚¹ãƒ†ãƒ æ™‚é–“ã‚’æ ¼ç´ã™ã‚‹ã€‚時間ã®å˜ä½ã¯ç§’ã§ã‚る。
+
+ +

標準入出力ãŒãƒã‚¤ãƒŠãƒªãƒ¢ãƒ¼ãƒ‰ã§ã‚ã‚‹ã“ã¨ã‚’ä¿è¨¼ã™ã‚‹ã«ã¯ã€é–¢æ•° `cbstdiobin' を用ã„る。

+ +
+
void cbstdiobin(void);
+
ã“ã®é–¢æ•°ã¯DOSçš„ãªãƒ•ã‚¡ã‚¤ãƒ«ã‚·ã‚¹ãƒ†ãƒ ã®ä¸Šã®ã‚¢ãƒ—リケーションã§æœ‰ç”¨ã§ã‚る。
+
+ +

サンプルコード

+ +

以下ã®ã‚µãƒ³ãƒ—ルコードã¯å…¸åž‹çš„ãªåˆ©ç”¨ä¾‹ã§ã‚る。

+ +
#include <cabin.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(int argc, char **argv){
+  CBDATUM *datum;
+  CBLIST *list;
+  CBMAP *map;
+  char *buf1, *buf2;
+  int i;
+
+  /* データãƒãƒ³ãƒ‰ãƒ«ã‚’é–‹ã */
+  datum = cbdatumopen("123", -1);
+  /* データを連çµã™ã‚‹ */
+  cbdatumcat(datum, "abc", -1);
+  /* データを表示ã™ã‚‹ */
+  printf("%s\n", cbdatumptr(datum));
+  /* データãƒãƒ³ãƒ‰ãƒ«ã‚’é–‰ã˜ã‚‹ */
+  cbdatumclose(datum);
+
+  /* リストãƒãƒ³ãƒ‰ãƒ«ã‚’é–‹ã */
+  list = cblistopen();
+  /* リストã«è¦ç´ ã‚’追加ã™ã‚‹ */
+  cblistpush(list, "apple", -1);
+  cblistpush(list, "orange", -1);
+  /* å…¨ã¦ã®è¦ç´ ã‚’表示ã™ã‚‹ */
+  for(i = 0; i < cblistnum(list); i++){
+    printf("%s\n", cblistval(list, i, NULL));
+  }
+  /* リストãƒãƒ³ãƒ‰ãƒ«ã‚’é–‰ã˜ã‚‹ */
+  cblistclose(list);
+
+  /* マップãƒãƒ³ãƒ‰ãƒ«ã‚’é–‹ã */
+  map = cbmapopen();
+  /* マップã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã™ã‚‹ */
+  cbmapput(map, "dog", -1, "bowwow", -1, 1);
+  cbmapput(map, "cat", -1, "meow", -1, 1);
+  /* 値をå–å¾—ã—ã¦è¡¨ç¤ºã™ã‚‹ */
+  printf("%s\n", cbmapget(map, "dog", -1, NULL));
+  printf("%s\n", cbmapget(map, "cat", -1, NULL));
+  /* マップãƒãƒ³ãƒ‰ãƒ«ã‚’é–‰ã˜ã‚‹ */
+  cbmapclose(map);
+
+  /* Base64ã®ç¬¦å·åŒ–を行ㆠ*/
+  buf1 = cbbaseencode("I miss you.", -1);
+  printf("%s\n", buf1);
+  /* Base64ã®å¾©å…ƒã‚’行ㆠ*/
+  buf2 = cbbasedecode(buf1, NULL);
+  printf("%s\n", buf2);
+  /* リソースを解放ã™ã‚‹ */
+  free(buf2);
+  free(buf1);
+
+  /* å˜ç´”ãªãƒã‚¤ãƒ³ã‚¿ã‚’グローãƒãƒ«ã‚¬ãƒ™ãƒ¼ã‚¸ã‚³ãƒ¬ã‚¯ã‚¿ã«ç™»éŒ²ã™ã‚‹ */
+  buf1 = cbmemdup("Take it easy.", -1);
+  cbglobalgc(buf1, free);
+  /* ãƒã‚¤ãƒ³ã‚¿ã¯åˆ©ç”¨ã§ãã‚‹ãŒè§£æ”¾ã™ã‚‹å¿…è¦ã¯ãªã„ */
+  printf("%s\n", buf1);
+
+  /* リストをグローãƒãƒ«ã‚¬ãƒ™ãƒ¼ã‚¸ã‚³ãƒ¬ã‚¯ã‚¿ã«ç™»éŒ²ã™ã‚‹ */
+  list = cblistopen();
+  cbglobalgc(list, (void (*)(void *))cblistclose);
+  /* ãƒãƒ³ãƒ‰ãƒ«ã¯åˆ©ç”¨ã§ãã‚‹ãŒé–‰ã˜ã‚‹å¿…è¦ã¯ãªã„ */
+  cblistpush(list, "Don't hesitate.", -1);
+  for(i = 0; i < cblistnum(list); i++){
+    printf("%s\n", cblistval(list, i, NULL));
+  }
+
+  return 0;
+}
+
+ +

注記

+ +

Cabinを利用ã—ãŸãƒ—ログラムをビルドã™ã‚‹æ–¹æ³•ã¯ã€Depotã®å ´åˆã¨å…¨ãåŒã˜ã§ã‚る。

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

スレッド間ã§åŒæ™‚ã«åŒã˜ãƒãƒ³ãƒ‰ãƒ«ã«ã‚¢ã‚¯ã‚»ã‚¹ã—ãªã„é™ã‚Šã¯ã€`cbglobalgc' を除ã„ãŸCabinã®å„関数ã¯ã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ã§ã‚る。ãŸã ã—ã€`errno' ã‚„ `malloc' ç­‰ãŒã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ãªå‡¦ç†ç³»ã§ã‚ã‚‹ã“ã¨ãŒå‰æã¨ãªã‚‹ã€‚

+ +
+ +

Cabin用コマンド

+ +

Cabinã«å¯¾å¿œã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ãƒ©ã‚¤ãƒ³ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ã¯ä»¥ä¸‹ã®ã‚‚ã®ã§ã‚る。

+ +

コマンド `cbtest' ã¯Cabinã®æ©Ÿèƒ½ãƒ†ã‚¹ãƒˆã‚„性能テストã«ç”¨ã„るツールã§ã‚る。`time' コマンドã«ã‚ˆã£ã¦ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã®å®Ÿè¡Œæ™‚間を計るã¨ã‚ˆã„。以下ã®æ›¸å¼ã§ç”¨ã„る。`rnum' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã‚’指定ã™ã‚‹ã€‚

+ +
+
cbtest sort [-d] rnum
+
ソートアルゴリズムã®ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚
+
cbtest strstr [-d] rnum
+
文字列探索アルゴリズムã®ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚
+
cbtest list [-d] rnum
+
リストã®æ›¸ãè¾¼ã¿ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚
+
cbtest map [-d] rnum
+
マップã®æ›¸ãè¾¼ã¿ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚
+
cbtest wicked rnum
+
リストã¨ãƒžãƒƒãƒ—ã®å„種更新æ“作を無作為ã«é¸æŠžã—ã¦å®Ÿè¡Œã™ã‚‹ã€‚
+
cbtest misc
+
雑多ãªãƒ«ãƒ¼ãƒãƒ³ã®ãƒ†ã‚¹ãƒˆã‚’実行ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -d : çµæžœã®ãƒ‡ãƒ¼ã‚¿ã‚’読ã¿è¾¼ã‚“ã§è¡¨ç¤ºã™ã‚‹ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +

コマンド `cbcodec' ã¯CabinãŒæä¾›ã™ã‚‹ã‚¨ãƒ³ã‚³ãƒ¼ãƒ‰ãŠã‚ˆã³ãƒ‡ã‚³ãƒ¼ãƒ‰ã®æ©Ÿèƒ½ã‚’利用ã™ã‚‹ãƒ„ールã§ã‚る。以下ã®æ›¸å¼ã§ç”¨ã„る。`file' ã¯å…¥åŠ›ãƒ•ã‚¡ã‚¤ãƒ«ã‚’指定ã™ã‚‹ãŒã€çœç•¥ã•ã‚Œã‚Œã°æ¨™æº–入力を読ã¿è¾¼ã‚€ã€‚

+ +
+
cbcodec url [-d] [-br] [-rs base target] [-l] [-e expr] [file]
+
URLエンコードã¨ãã®ãƒ‡ã‚³ãƒ¼ãƒ‰ã‚’è¡Œã†ã€‚
+
cbcodec base [-d] [-l] [-c num] [-e expr] [file]
+
Base64エンコードã¨ãã®ãƒ‡ã‚³ãƒ¼ãƒ‰ã‚’è¡Œã†ã€‚
+
cbcodec quote [-d] [-l] [-c num] [-e expr] [file]
+
quoted-printableエンコードã¨ãã®ãƒ‡ã‚³ãƒ¼ãƒ‰ã‚’è¡Œã†ã€‚
+
cbcodec mime [-d] [-hd] [-bd] [-part num] [-l] [-ec code] [-qp] [-dc] [-e expr] [file]
+
MIMEエンコードã¨ãã®ãƒ‡ã‚³ãƒ¼ãƒ‰ã‚’è¡Œã†ã€‚
+
cbcodec csv [-d] [-t] [-l] [-e expr] [-html] [file]
+
CSVã®å‡¦ç†ã‚’è¡Œã†ã€‚デフォルトã§ã¯ãƒ¡ã‚¿æ–‡å­—ã®ã‚¨ã‚¹ã‚±ãƒ¼ãƒ—ã‚’è¡Œã†ã€‚
+
cbcodec xml [-d] [-p] [-l] [-e expr] [-tsv] [file]
+
XMLã®å‡¦ç†ã‚’è¡Œã†ã€‚デフォルトã§ã¯ãƒ¡ã‚¿æ–‡å­—ã®ã‚¨ã‚¹ã‚±ãƒ¼ãƒ—ã‚’è¡Œã†ã€‚
+
cbcodec zlib [-d] [-gz] [-crc] [file]
+
ZLIBã®åœ§ç¸®ã¨ãã®ä¼¸é•·ã‚’è¡Œã†ã€‚ZLIBを有効化ã—ã¦QDBMをビルドã—ãŸå ´åˆã«ã®ã¿åˆ©ç”¨å¯èƒ½ã§ã‚る。
+
cbcodec lzo [-d] [file]
+
LZOã®åœ§ç¸®ã¨ãã®ä¼¸é•·ã‚’è¡Œã†ã€‚LZOを有効化ã—ã¦QDBMをビルドã—ãŸå ´åˆã«ã®ã¿åˆ©ç”¨å¯èƒ½ã§ã‚る。
+
cbcodec bzip [-d] [file]
+
BZIP2ã®åœ§ç¸®ã¨ãã®ä¼¸é•·ã‚’è¡Œã†ã€‚BZIP2を有効化ã—ã¦QDBMをビルドã—ãŸå ´åˆã«ã®ã¿åˆ©ç”¨å¯èƒ½ã§ã‚る。
+
cbcodec iconv [-ic code] [-oc code] [-ol ltype] [-cn] [-um] [-wc] [file]
+
ICONVã«ã‚ˆã‚‹æ–‡å­—コードã®å¤‰æ›ã‚’è¡Œã†ã€‚ICONVを有効化ã—ã¦QDBMをビルドã—ãŸå ´åˆã«ã®ã¿åˆ©ç”¨å¯èƒ½ã§ã‚る。
+
cbcodec date [-wf] [-rf] [-utc] [str]
+
`str' ã§æŒ‡å®šã—ãŸæ—¥ä»˜ã®æ–‡å­—列ã®æ›¸å¼ã‚’変æ›ã™ã‚‹ã€‚デフォルトã§ã¯ã€UNIX時間を出力ã™ã‚‹ã€‚`str' ãŒçœç•¥ã•ã‚Œã‚‹ã¨ã€ç¾åœ¨æ—¥æ™‚を扱ã†ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -d : エンコード(エスケープ)ã§ã¯ãªãã€ãƒ‡ã‚³ãƒ¼ãƒ‰ï¼ˆã‚¢ãƒ³ã‚¨ã‚¹ã‚±ãƒ¼ãƒ—)を行ã†ã€‚
  • +
  • -br : URLを構æˆè¦ç´ ã«åˆ†è§£ã™ã‚‹ã€‚
  • +
  • -rs : 相対URLを解決ã™ã‚‹ã€‚
  • +
  • -l : 出力ã®æœ«å°¾ã«æ”¹è¡Œæ–‡å­—を加ãˆã‚‹ã€‚
  • +
  • -e expr : 入力データを直接指定ã™ã‚‹ã€‚
  • +
  • -c num : エンコードã®éš›ã®æ¡æ•°åˆ¶é™ã‚’指定ã™ã‚‹ã€‚
  • +
  • -hd : MIMEã®æ§‹æ–‡è§£æžã‚’è¡Œã„ã€ãƒ˜ãƒƒãƒ€ã‚’TSVå½¢å¼ã§æŠ½å‡ºã™ã‚‹ã€‚
  • +
  • -bd : MIMEã®æ§‹æ–‡è§£æžã‚’è¡Œã„ã€ãƒœãƒ‡ã‚£ã‚’抽出ã™ã‚‹ã€‚
  • +
  • -part num : MIMEã®æ§‹æ–‡è§£æžã‚’è¡Œã„ã€ç‰¹å®šã®ãƒ‘ートを抽出ã™ã‚‹ã€‚
  • +
  • -ec code : 入力ã®æ–‡å­—コードを指定ã™ã‚‹ã€‚デフォルトã¯UTF-8ã§ã‚る。
  • +
  • -qp : quoted-printableエンコードを用ã„る。デフォルトã¯Base64ã§ã‚る。
  • +
  • -dc : デコードçµæžœã®æ–‡å­—列ã§ãªãã€æ–‡å­—コードåを出力ã™ã‚‹ã€‚
  • +
  • -t : CSVã®æ§‹é€ ã‚’解æžã™ã‚‹ã€‚TSVã«å¤‰æ›ã—ã¦è¡¨ç¤ºã™ã‚‹ã€‚セル内ã®ã‚¿ãƒ–ã¨æ”¹è¡Œã¯å‰Šé™¤ã•ã‚Œã‚‹ã€‚
  • +
  • -html : CSVã®æ§‹é€ ã‚’解æžã™ã‚‹ã€‚HTMLã«å¤‰æ›ã—ã¦å‡ºåŠ›ã™ã‚‹ã€‚
  • +
  • -p : XMLã®æ§‹æ–‡è§£æžã‚’è¡Œã†ã€‚ã‚¿ã‚°ã¨ãƒ†ã‚­ã‚¹ãƒˆã‚»ã‚¯ã‚·ãƒ§ãƒ³ã‚’ヘッダã§åˆ†ã‘ã¦è¡¨ç¤ºã™ã‚‹ã€‚
  • +
  • -tsv : XMLã®æ§‹æ–‡è§£æžã‚’è¡Œã†ã€‚çµæžœã‚’TSVå½¢å¼ã§å‡ºåŠ›ã™ã‚‹ã€‚テキストセクションã®ã‚¿ãƒ–ã¨æ”¹è¡Œã¯URLエンコードã•ã‚Œã‚‹ã€‚
  • +
  • -gz : GZIPå½¢å¼ã‚’用ã„る。
  • +
  • -crc : CRC32ã®ãƒã‚§ãƒƒã‚¯ã‚µãƒ ã‚’ビッグエンディアンã®16進数ã§å‡ºåŠ›ã™ã‚‹ã€‚
  • +
  • -ic code : 入力ã®æ–‡å­—コードを指定ã™ã‚‹ã€‚デフォルトã ã¨è‡ªå‹•åˆ¤å®šã™ã‚‹ã€‚
  • +
  • -oc code : 出力ã®æ–‡å­—コードを指定ã™ã‚‹ã€‚デフォルトã ã¨UTF-8ã«ãªã‚‹ã€‚
  • +
  • -ol ltype : 改行文字を変æ›ã™ã‚‹ã€‚`unix'(LF)ã€`dos'(CRLF)ã€`mac'(CR) ã®ã©ã‚Œã‹ã‚’指定ã™ã‚‹ã€‚
  • +
  • -cn : 入力ã®æ–‡å­—コードを自動判定ã—ã€ãã®åå‰ã‚’表示ã™ã‚‹ã€‚
  • +
  • -wc : 入力ã®æ–‡å­—コードをUTF-8ã¨ä»®å®šã—ã€ãã®æ–‡å­—数を表示ã™ã‚‹ã€‚
  • +
  • -um : UCS-2ã®æ–‡å­—ã¨ã€C言語ã®æ–‡å­—列表ç¾ã§ã®UTF-16BEã¨UTF-8ã®å¯¾å¿œè¡¨ã‚’出力ã™ã‚‹ã€‚
  • +
  • -wf : W3CDTFã®æ›¸å¼ã§å‡ºåŠ›ã™ã‚‹ã€‚
  • +
  • -rf : RFC 1123ã®æ›¸å¼ã§å‡ºåŠ›ã™ã‚‹ã€‚
  • +
  • -utc : å”定世界時を出力ã™ã‚‹ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +
+ +

Villa: 上級API

+ +

概è¦

+ +

Villaã¯QDBMã®ä¸Šç´šAPIã§ã‚ã‚Šã€B+木ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’管ç†ã™ã‚‹ãƒ«ãƒ¼ãƒãƒ³ã‚’æä¾›ã™ã‚‹ã€‚å„レコードã¯ãƒ¦ãƒ¼ã‚¶ãŒæŒ‡å®šã—ãŸé †åºã§æ•´åˆ—ã•ã‚Œã¦æ ¼ç´ã•ã‚Œã‚‹ã€‚ãƒãƒƒã‚·ãƒ¥ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã§ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æ¤œç´¢ã¯ã‚­ãƒ¼ã®å®Œå…¨ä¸€è‡´ã«ã‚ˆã‚‹ã—ã‹ãªã‹ã£ãŸã€‚ã—ã‹ã—ã€Villaを用ã„ã‚‹ã¨ç¯„囲を指定ã—ã¦ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã™ã‚‹ã“ã¨ãŒã§ãる。å„レコードを順番ã«å‚ç…§ã™ã‚‹ã«ã¯ã‚«ãƒ¼ã‚½ãƒ«ã‚’用ã„る。データベースã«ã¯ã‚­ãƒ¼ãŒé‡è¤‡ã™ã‚‹è¤‡æ•°ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’æ ¼ç´ã™ã‚‹ã“ã¨ãŒã§ãる。ã¾ãŸã€ãƒˆãƒ©ãƒ³ã‚¶ã‚¯ã‚·ãƒ§ãƒ³æ©Ÿæ§‹ã«ã‚ˆã£ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ“作を一括ã—ã¦å映ã•ã›ãŸã‚Šç ´æ£„ã—ãŸã‚Šã™ã‚‹ã“ã¨ãŒã§ãる。

+ +

Villaã¯DepotãŠã‚ˆã³Cabinを基盤ã¨ã—ã¦å®Ÿè£…ã•ã‚Œã‚‹ã€‚Villaã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã¯Depotã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ãã®ã‚‚ã®ã§ã‚る。レコードã®æ¤œç´¢ã‚„æ ¼ç´ã®å‡¦ç†é€Ÿåº¦ã¯Depotよりé…ã„ãŒã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºã¯ã‚ˆã‚Šå°ã•ã„。

+ +

Villaを使ã†ãŸã‚ã«ã¯ã€`depot.h' 㨠`cabin.h' 㨠`villa.h' 㨠`stdlib.h' をインクルードã™ã¹ãã§ã‚る。通常ã€ã‚½ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®å†’頭付近ã§ä»¥ä¸‹ã®è¨˜è¿°ã‚’è¡Œã†ã€‚

+ +
+
#include <depot.h>
+
#include <cabin.h>
+
#include <villa.h>
+
#include <stdlib.h>
+
+ +

Villaã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†éš›ã«ã¯ã€`VILLA' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。ã“ã‚Œã¯ã€`stdio.h' ã®å„種ルーãƒãƒ³ãŒãƒ•ã‚¡ã‚¤ãƒ«å…¥å‡ºåŠ›ã« `FILE' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’用ã„ã‚‹ã®ã«ä¼¼ã¦ã„る。ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `vlopen' ã§é–‹ãã€é–¢æ•° `vlclose' ã§é–‰ã˜ã‚‹ã€‚ãƒãƒ³ãƒ‰ãƒ«ã®ãƒ¡ãƒ³ãƒã‚’直接å‚ç…§ã™ã‚‹ã“ã¨ã¯æŽ¨å¥¨ã•ã‚Œãªã„。データベースã«è‡´å‘½çš„ãªã‚¨ãƒ©ãƒ¼ãŒèµ·ããŸå ´åˆã¯ã€ä»¥å¾Œãã®ãƒãƒ³ãƒ‰ãƒ«ã«å¯¾ã™ã‚‹ `vlclose' を除ãå…¨ã¦ã®æ“作ã¯ä½•ã‚‚ã›ãšã«ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã™ã€‚ã²ã¨ã¤ã®ãƒ—ロセスã§è¤‡æ•°ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’åŒæ™‚ã«åˆ©ç”¨ã™ã‚‹ã“ã¨ã¯å¯èƒ½ã§ã‚ã‚‹ãŒã€åŒã˜ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®è¤‡æ•°ã®ãƒãƒ³ãƒ‰ãƒ«ã‚’利用ã—ã¦ã¯ãªã‚‰ãªã„。カーソルを使ã†å‰ã«ã¯ `vlcurfirst' ã‹ `vlcurlast' ã‹ `vlcurjump' ã®ã©ã‚Œã‹ã§åˆæœŸåŒ–ã™ã‚‹å¿…è¦ãŒã‚る。`vlcurput' 㨠`vlcurout' 以外ã®é–¢æ•°ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æ›´æ–°ã‚„削除をã—ãŸå¾Œã«ã‚‚カーソルをåˆæœŸåŒ–ã™ã‚‹å¿…è¦ãŒã‚る。

+ +

Villaã§ã‚‚Depotã¨åŒã˜ã外部変数 `dpecode' ã«ç›´å‰ã®ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ãŒè¨˜éŒ²ã•ã‚Œã‚‹ã€‚エラーコードã«å¯¾å¿œã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸æ–‡å­—列を得るã«ã¯ã€é–¢æ•° `dperrmsg' を用ã„る。

+ +

API

+ +

レコードã®é †ç•ªã‚’指定ã™ã‚‹ãŸã‚ã«ã¯ã€æ¯”較関数を定義ã™ã‚‹ã€‚比較関数ã«ã¯ä»¥ä¸‹ã®åž‹ã‚’用ã„る。

+ +
+
typedef int(*VLCFUNC)(const char *aptr, int asiz, const char *bptr, int bsiz);
+
`aptr' ã¯ä¸€æ–¹ã®ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`asiz' ã¯ãã®ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚`bptr' ã¯ä»–æ–¹ã®ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`bsiz' ã¯ãã®ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯å‰è€…ãŒå¤§ãã‘ã‚Œã°æ­£ã€å¾Œè€…ãŒå¤§ãã‘ã‚Œã°è² ã€ä¸¡è€…ãŒç­‰ä¾¡ãªã‚‰ 0 ã§ã‚る。
+
+ +

データベースã®ãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `vlopen' を用ã„る。

+ +
+
VILLA *vlopen(const char *name, int omode, VLCFUNC cmp);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚`omode' ã¯æŽ¥ç¶šãƒ¢ãƒ¼ãƒ‰ã‚’指定ã—ã€`VL_OREADER' ãªã‚‰ãƒªãƒ¼ãƒ€ã€`VL_OWRITER' ãªã‚‰ãƒ©ã‚¤ã‚¿ã¨ãªã‚‹ã€‚`VL_OWRITER' ã®å ´åˆã€`VL_OCREAT' ã¾ãŸã¯ `VL_OTRUNC' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãる。`VL_OCREAT' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãŒç„¡ã„å ´åˆã«æ–°è¦ä½œæˆã™ã‚‹ã“ã¨ã‚’指示ã—ã€`VL_OTRUNC' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãŒå­˜åœ¨ã—ã¦ã‚‚作り直ã™ã“ã¨ã‚’指示ã—ã€`VL_OZCOMP' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹å†…ã®ãƒªãƒ¼ãƒ•ã‚’ZLIBã§åœ§ç¸®ã™ã‚‹ã“ã¨ã‚’指示ã—ã€`VL_OYCOMP' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹å†…ã®ãƒªãƒ¼ãƒ•ã‚’LZOã§åœ§ç¸®ã™ã‚‹ã“ã¨ã‚’指示ã—ã€`VL_OXCOMP' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹å†…ã®ãƒªãƒ¼ãƒ•ã‚’BZIP2ã§åœ§ç¸®ã™ã‚‹ã“ã¨ã‚’指示ã™ã‚‹ã€‚`VL_OREADER' 㨠`VL_OWRITER' ã®ä¸¡æ–¹ã§ `VL_ONOLCK' ã¾ãŸã¯ `VL_OLCKNB' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ãŒã€å‰è€…ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãƒ­ãƒƒã‚¯ã‚’ã‹ã‘ãšã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ãã“ã¨ã‚’指示ã—ã€å¾Œè€…ã¯ãƒ–ロックã›ãšã«ãƒ­ãƒƒã‚¯ã‚’ã‹ã‘ã‚‹ã“ã¨ã‚’指示ã™ã‚‹ã€‚`cmp' ã¯æ¯”較関数を指定ã™ã‚‹ã€‚`VL_CMPLEX' ã¯ã‚­ãƒ¼ã‚’辞書順ã§æ¯”較ã™ã‚‹ã€‚`VL_CMPINT' ã¯ã‚­ãƒ¼ã‚’ `int' åž‹ã®ã‚ªãƒ–ジェクトã¨ã¿ãªã—ã¦æ¯”較ã™ã‚‹ã€‚`VL_CMPNUM' ã¯ã‚­ãƒ¼ã‚’ビッグエンディアンã®æ•°å€¤ã¨ã¿ãªã—ã¦æ¯”較ã™ã‚‹ã€‚`VL_CMPDEC' ã¯ã‚­ãƒ¼ã‚’10進数ã®æ•°å€¤ã‚’表ã™æ–‡å­—列ã¨ã¿ãªã—ã¦æ¯”較ã™ã‚‹ã€‚`VLCFUNC' åž‹ã®å®£è¨€ã«åŸºã¥ã関数ã§ã‚ã‚Œã°æ¯”較関数ã¨ã—ã¦ç”¨ã„ã‚‹ã“ã¨ãŒã§ãる。åŒã˜ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ã¯å¸¸ã«åŒã˜æ¯”較関数を用ã„ã‚‹å¿…è¦ãŒã‚る。戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚‹ã‹ã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。ライタ(読ã¿æ›¸ã両用モード)ã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’é–‹ãéš›ã«ã¯ãã®ãƒ•ã‚¡ã‚¤ãƒ«ã«å¯¾ã—ã¦æŽ’他ロックãŒã‹ã‘られã€ãƒªãƒ¼ãƒ€ï¼ˆèª­ã¿è¾¼ã¿å°‚用モード)ã§é–‹ãéš›ã«ã¯å…±æœ‰ãƒ­ãƒƒã‚¯ãŒã‹ã‘られる。ãã®éš›ã«ã¯è©²å½“ã®ãƒ­ãƒƒã‚¯ãŒã‹ã‘られるã¾ã§åˆ¶å¾¡ãŒãƒ–ロックã™ã‚‹ã€‚`VL_OZCOMP' 㨠`VL_OYCOMP' 㨠`VL_OXCOMP' ã¯QDBMãŒãã‚Œãžã‚ŒZLIBã¨LZOã¨BZIP2を有効ã«ã—ã¦ãƒ“ルドã•ã‚ŒãŸå ´åˆã«ã®ã¿åˆ©ç”¨ã§ãる。`VL_ONOLCK' を使ã†å ´åˆã€ã‚¢ãƒ—リケーションãŒæŽ’他制御ã®è²¬ä»»ã‚’è² ã†ã€‚
+
+ +

データベースã¨ã®æŽ¥ç¶šã‚’é–‰ã˜ã¦ãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlclose' を用ã„る。

+ +
+
int vlclose(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。データベースã®æ›´æ–°å†…容ã¯ã€æŽ¥ç¶šã‚’é–‰ã˜ãŸæ™‚点ã§åˆã‚ã¦ãƒ•ã‚¡ã‚¤ãƒ«ã¨åŒæœŸã•ã‚Œã‚‹ã€‚ライタã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã„ãŸå ´åˆã€é©åˆ‡ã«æŽ¥ç¶šã‚’é–‰ã˜ãªã„ã¨ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãŒç ´å£Šã•ã‚Œã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã§ããªããªã‚‹ã€‚トランザクションãŒæœ‰åŠ¹ã§ã‚³ãƒŸãƒƒãƒˆã•ã‚Œã¦ã„ãªã„å ´åˆã€ãã‚Œã¯ç ´æ£„ã•ã‚Œã‚‹ã€‚
+
+ +

レコードを追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlput' を用ã„る。

+ +
+
int vlput(VILLA *villa, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`vbuf' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`vsiz' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(vbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`dmode' ã¯ã‚­ãƒ¼ãŒæ—¢å­˜ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨é‡è¤‡ã—ãŸéš›ã®åˆ¶å¾¡ã‚’指定ã™ã‚‹ã€‚`VL_DOVER' ã¯æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’上書ãã—ã€`VL_DKEEP' ã¯æ—¢å­˜ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’残ã—ã¦ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã—ã€`VL_DCAT' ã¯æŒ‡å®šã•ã‚ŒãŸå€¤ã‚’既存ã®å€¤ã®æœ«å°¾ã«åŠ ãˆã€`VL_DDUP' ã¯ã‚­ãƒ¼ã®é‡è¤‡ã‚’許ã—ã¦æŒ‡å®šã•ã‚ŒãŸå€¤ã‚’最後ã®å€¤ã¨ã—ã¦åŠ ãˆã€`VL_DDUPR' ã¯ã‚­ãƒ¼ã®é‡è¤‡ã‚’許ã—ã¦æŒ‡å®šã•ã‚ŒãŸå€¤ã‚’最åˆã®å€¤ã¨ã—ã¦åŠ ãˆã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。データベースã®æ›´æ–°ã«ã‚ˆã£ã¦ã‚«ãƒ¼ã‚½ãƒ«ã¯ä½¿ç”¨ä¸èƒ½ã«ãªã‚‹ã€‚
+
+ +

レコードを削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlout' を用ã„る。

+ +
+
int vlout(VILLA *villa, const char *kbuf, int ksiz);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚é‡è¤‡ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ç¾¤ã®ã‚­ãƒ¼ãŒæŒ‡å®šã•ã‚ŒãŸå ´åˆã€ãã®æœ€åˆã®ã‚‚ã®ãŒå‰Šé™¤ã•ã‚Œã‚‹ã€‚データベースã®æ›´æ–°ã«ã‚ˆã£ã¦ã‚«ãƒ¼ã‚½ãƒ«ã¯ä½¿ç”¨ä¸èƒ½ã«ãªã‚‹ã€‚
+
+ +

レコードをå–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlget' を用ã„る。

+ +
+
char *vlget(VILLA *villa, const char *kbuf, int ksiz, int *sp);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚é‡è¤‡ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ç¾¤ã®ã‚­ãƒ¼ãŒæŒ‡å®šã•ã‚ŒãŸå ´åˆã€ãã®æœ€åˆã®ã‚‚ã®ãŒé¸æŠžã•ã‚Œã‚‹ã€‚戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

レコードã®å€¤ã®ã‚µã‚¤ã‚ºã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlvsiz' を用ã„る。

+ +
+
int vlvsiz(VILLA *villa, const char *kbuf, int ksiz);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯è©²å½“レコードã®å€¤ã®ã‚µã‚¤ã‚ºã§ã‚ã‚‹ãŒã€è©²å½“ãŒãªã„å ´åˆã‚„エラーã®å ´åˆã¯ -1 ã§ã‚る。複数ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒè©²å½“ã™ã‚‹å ´åˆã¯ã€æœ€åˆã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã®ã‚µã‚¤ã‚ºã‚’è¿”ã™ã€‚
+
+ +

キーã«ä¸€è‡´ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æ•°ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlvnum' を用ã„る。

+ +
+
int vlvnum(VILLA *villa, const char *kbuf, int ksiz);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯è©²å½“レコードã®å€¤ã®æ•°ã§ã‚ã‚Šã€è©²å½“ãŒãªã„å ´åˆã‚„エラーã®å ´åˆã¯ 0 ã§ã‚る。
+
+ +

キーã«ä¸€è‡´ã™ã‚‹è¤‡æ•°ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlputlist' を用ã„る。

+ +
+
int vlputlist(VILLA *villa, const char *kbuf, int ksiz, const CBLIST *vals);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`vals' ã¯å€¤ã®ãƒªã‚¹ãƒˆã®ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚リストã¯ç©ºã§ã‚ã£ã¦ã¯ãªã‚‰ãªã„。戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。データベースã®æ›´æ–°ã«ã‚ˆã£ã¦ã‚«ãƒ¼ã‚½ãƒ«ã¯ä½¿ç”¨ä¸èƒ½ã«ãªã‚‹ã€‚
+
+ +

キーã«ä¸€è‡´ã™ã‚‹å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `vloutlist' を用ã„る。

+ +
+
int vloutlist(VILLA *villa, const char *kbuf, int ksiz);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚データベースã®æ›´æ–°ã«ã‚ˆã£ã¦ã‚«ãƒ¼ã‚½ãƒ«ã¯ä½¿ç”¨ä¸èƒ½ã«ãªã‚‹ã€‚
+
+ +

キーã«ä¸€è‡´ã™ã‚‹å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlgetlist' を用ã„る。

+ +
+
CBLIST *vlgetlist(VILLA *villa, const char *kbuf, int ksiz);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚戻り値ã¯ä¸€è‡´ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã®ãƒªã‚¹ãƒˆã®ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚‹ã‹ã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

キーã«ä¸€è‡´ã™ã‚‹å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é€£çµã—ãŸå€¤ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlgetcat' を用ã„る。

+ +
+
char *vlgetcat(VILLA *villa, const char *kbuf, int ksiz, int *sp);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰é€£çµã—ãŸå€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

カーソルを最åˆã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ç§»å‹•ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `vlcurfirst' を用ã„る。

+ +
+
int vlcurfirst(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。データベースãŒç©ºã®å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

カーソルを最後ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ç§»å‹•ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `vlcurlast' を用ã„る。

+ +
+
int vlcurlast(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。データベースãŒç©ºã®å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

カーソルをå‰ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ç§»å‹•ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `vlcurprev' を用ã„る。

+ +
+
int vlcurprev(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。å‰ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

カーソルを次ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ç§»å‹•ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `vlcurnext' を用ã„る。

+ +
+
int vlcurnext(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。次ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

カーソルを特定ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å‰å¾Œã«ç§»å‹•ã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `vlcurjump' を用ã„る。

+ +
+
int vlcurjump(VILLA *villa, const char *kbuf, int ksiz, int jmode);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`kbuf' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`ksiz' ã¯ã‚­ãƒ¼ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(kbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`jmode' ã¯è©³ç´°ãªèª¿æ•´ã‚’指定ã™ã‚‹ã€‚`VL_JFORWARD' ã¯ã‚­ãƒ¼ãŒåŒã˜ãƒ¬ã‚³ãƒ¼ãƒ‰ç¾¤ã®æœ€åˆã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ã‚«ãƒ¼ã‚½ãƒ«ãŒè¨­å®šã•ã‚Œã€ã¾ãŸå®Œå…¨ã«ä¸€è‡´ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã¯æ¬¡ã®å€™è£œã«ã‚«ãƒ¼ã‚½ãƒ«ãŒè¨­å®šã•ã‚Œã‚‹ã“ã¨ã‚’æ„味ã™ã‚‹ã€‚`VL_JBACKWORD' ã¯ã‚­ãƒ¼ãŒåŒã˜ãƒ¬ã‚³ãƒ¼ãƒ‰ç¾¤ã®æœ€å¾Œã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ã‚«ãƒ¼ã‚½ãƒ«ãŒè¨­å®šã•ã‚Œã€ã¾ãŸå®Œå…¨ã«ä¸€è‡´ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã¯å‰ã®å€™è£œã«ã‚«ãƒ¼ã‚½ãƒ«ãŒè¨­å®šã•ã‚Œã‚‹ã“ã¨ã‚’æ„味ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。æ¡ä»¶ã«ä¸€è‡´ã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

カーソルã®ã‚るレコードã®ã‚­ãƒ¼ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlcurkey' を用ã„る。

+ +
+
char *vlcurkey(VILLA *villa, int *sp);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

カーソルã®ã‚るレコードã®å€¤ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlcurkey' を用ã„る。

+ +
+
char *vlcurval(VILLA *villa, int *sp);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`sp' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãã®å‚照先ã«æŠ½å‡ºã—ãŸé ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’æ ¼ç´ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰å€¤ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚戻り値ã®é ˜åŸŸã¯ã€å®Ÿéš›ã«ã¯1ãƒã‚¤ãƒˆå¤šã確ä¿ã—ã¦çµ‚端文字ãŒç½®ã‹ã‚Œã‚‹ã®ã§ã€æ–‡å­—列ã¨ã—ã¦åˆ©ç”¨ã§ãる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

カーソルã®ã‚るレコードã®å‘¨è¾ºã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’挿入ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlcurput' を用ã„る。

+ +
+
int vlcurput(VILLA *villa, const char *vbuf, int vsiz, int cpmode);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`vbuf' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’指定ã™ã‚‹ã€‚`vsiz' ã¯å€¤ã®ãƒ‡ãƒ¼ã‚¿é ˜åŸŸã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã‹ã€è² æ•°ãªã‚‰ `strlen(vbuf)' ã®å€¤ã¨ãªã‚‹ã€‚`cpmode' ã¯è©³ç´°ãªèª¿æ•´ã‚’指定ã™ã‚‹ã€‚`VL_CPCURRENT' ã¯ç¾åœ¨ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’上書ãã™ã‚‹ã“ã¨ã‚’指示ã—ã€`VL_CPBEFORE' ã¯ã‚«ãƒ¼ã‚½ãƒ«ã®ç›´å‰ã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’挿入ã™ã‚‹ã“ã¨ã‚’指示ã—ã€`VL_CPAFTER' ã¯ã‚«ãƒ¼ã‚½ãƒ«ã®ç›´å¾Œã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’挿入ã™ã‚‹ã“ã¨ã‚’指示ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚挿入æ“作ã®å¾Œã«ã¯ã€ã‚«ãƒ¼ã‚½ãƒ«ã¯æŒ¿å…¥ã•ã‚ŒãŸãƒ¬ã‚³ãƒ¼ãƒ‰ã®ä½ç½®ã«ç§»å‹•ã™ã‚‹ã€‚
+
+ +

カーソルã®ã‚るレコードを削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlcurout' を用ã„る。

+ +
+
int vlcurout(VILLA *villa);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。該当ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚削除æ“作ã®å¾Œã«ã¯ã€å¯èƒ½ã§ã‚ã‚Œã°ã‚«ãƒ¼ã‚½ãƒ«ã¯æ¬¡ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ç§»å‹•ã™ã‚‹ã€‚
+
+ +

性能を調整ã™ã‚‹ãƒ‘ラメータを指定ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlsettuning' を用ã„る。

+ +
+
void vlsettuning(VILLA *villa, int lrecmax, int nidxmax, int lcnum, int ncnum);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`lrecmax' ã¯B+木ã®ã²ã¨ã¤ã®ãƒªãƒ¼ãƒ•ã«å…¥ã‚Œã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ãŒä½¿ã‚れる。`nidxmax' ã¯B+木ã®éžãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã«å…¥ã‚Œã‚‹ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ãŒä½¿ã‚れる。`lcnum' ã¯ã‚­ãƒ£ãƒƒã‚·ãƒ¥ã«å…¥ã‚Œã‚‹ãƒªãƒ¼ãƒ•ã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ãŒä½¿ã‚れる。`ncnum' ã¯ã‚­ãƒ£ãƒƒã‚·ãƒ¥ã«å…¥ã‚Œã‚‹éžãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ãŒã€0 以下ãªã‚‰ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå€¤ãŒä½¿ã‚れる。デフォルトã®è¨­å®šã¯ `vlsettuning(49, 192, 1024, 512)' ã«ç›¸å½“ã™ã‚‹ã€‚性能調整ã®ãƒ‘ラメータã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ä¿å­˜ã•ã‚Œãªã„ã®ã§ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã度ã«æŒ‡å®šã™ã‚‹å¿…è¦ãŒã‚る。
+
+ +

データベースã®ãƒ•ãƒªãƒ¼ãƒ–ロックプールã®ã‚µã‚¤ã‚ºè¨­å®šã™ã‚‹ã«ã¯ã€é–¢æ•° `vlsetfbpsiz' を用ã„る。

+ +
+
int vlsetfbpsiz(VILLA *villa, int size);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`size' ã¯ãƒ•ãƒªãƒ¼ãƒ–ロックプールã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。フリーブロックプールã®ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆã®ã‚µã‚¤ã‚ºã¯256ã§ã‚る。サイズをより大ããã™ã‚‹ã¨ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ä¸Šæ›¸ãã‚’ç¹°ã‚Šè¿”ã™éš›ã®ç©ºé–“効率ã¯ä¸ŠãŒã‚‹ãŒã€æ™‚間効率ãŒä¸‹ãŒã‚‹ã€‚
+
+ +

データベースを更新ã—ãŸå†…容をファイルã¨ãƒ‡ãƒã‚¤ã‚¹ã«åŒæœŸã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `vlsync' を用ã„る。

+ +
+
int vlsync(VILLA *villa);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‰ã˜ãªã„ã†ã¡ã«åˆ¥ãƒ—ロセスã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’利用ã•ã›ã‚‹å ´åˆã«å½¹ç«‹ã¤ã€‚トランザクションãŒæœ‰åŠ¹ãªé–“ã¯ã“ã®é–¢æ•°ã‚’使用ã™ã¹ãã§ã¯ãªã„。
+
+ +

データベースを最é©åŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `vloptimize' を用ã„る。

+ +
+
int vloptimize(VILLA *villa);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。レコードを削除ã—ãŸã‚Šã€ç½®æ›ãƒ¢ãƒ¼ãƒ‰ã‚„連çµãƒ¢ãƒ¼ãƒ‰ã§æ›¸ãè¾¼ã¿ã‚’ç¹°ã‚Šè¿”ã—ãŸã‚Šã™ã‚‹å ´åˆã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹å†…ã«ä¸è¦ãªé ˜åŸŸãŒè“„ç©ã™ã‚‹ãŒã€ã“ã®é–¢æ•°ã¯ãれを解消ã™ã‚‹ã®ã«å½¹ç«‹ã¤ã€‚トランザクションãŒæœ‰åŠ¹ãªé–“ã¯ã“ã®é–¢æ•°ã‚’使用ã™ã¹ãã§ã¯ãªã„。
+
+ +

データベースã®åå‰ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `vlname' を用ã„る。

+ +
+
char *vlname(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰åå‰ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

データベースファイルã®ã‚µã‚¤ã‚ºã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `vlfsiz' を用ã„る。

+ +
+
int vlfsiz(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。I/Oãƒãƒƒãƒ•ã‚¡ã«ã‚ˆã‚Šã€æˆ»ã‚Šå€¤ã¯å®Ÿéš›ã®ã‚µã‚¤ã‚ºã‚ˆã‚Šå°ã•ããªã‚‹å ´åˆãŒã‚る。
+
+ +

B+木ã®ãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã®æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `vllnum' を用ã„る。

+ +
+
int vllnum(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã®æ•°ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

B+木ã®éžãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã®æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `vlnnum' を用ã„る。

+ +
+
int vlnnum(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰éžãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã®æ•°ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

データベースã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `vlrnum' を用ã„る。

+ +
+
int vlrnum(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

データベースãƒãƒ³ãƒ‰ãƒ«ãŒãƒ©ã‚¤ã‚¿ã‹ã©ã†ã‹ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `vlwritable' を用ã„る。

+ +
+
int vlwritable(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ©ã‚¤ã‚¿ãªã‚‰çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

データベースã«è‡´å‘½çš„エラーãŒèµ·ããŸã‹ã©ã†ã‹ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `vlfatalerror' を用ã„る。

+ +
+
int vlfatalerror(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯è‡´å‘½çš„エラーãŒã‚ã‚Œã°çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

データベースファイルã®inode番å·ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `vlinode' を用ã„る。

+ +
+
int vlinode(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®inode番å·ã§ã‚る。
+
+ +

データベースã®æœ€çµ‚更新時刻を得るã«ã¯ã€é–¢æ•° `vlmtime' を用ã„る。

+ +
+
time_t vlmtime(VILLA *villa);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æœ€çµ‚更新時刻ã§ã‚る。
+
+ +

トランザクションを開始ã™ã‚‹ã«ã¯ã€é–¢æ•° `vltranbegin' を用ã„る。

+ +
+
int vltranbegin(VILLA *villa);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒžãƒ«ãƒã‚¹ãƒ¬ãƒƒãƒ‰ã§ã®ç›¸äº’排他制御を行ã‚ãªã„ã®ã§ã€ã‚¢ãƒ—リケーションãŒãã®è²¬ä»»ã‚’è² ã†ã€‚一ã¤ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã§åŒæ™‚ã«æœ‰åŠ¹ã«ã§ãるトランザクションã¯ä¸€ã¤ã ã‘ã§ã‚る。
+
+ +

トランザクションをコミットã™ã‚‹ã«ã¯ã€é–¢æ•° `vltrancommit' を用ã„る。

+ +
+
int vltrancommit(VILLA *villa);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。トランザクションã®ä¸­ã§ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ›´æ–°ã¯ã‚³ãƒŸãƒƒãƒˆãŒæˆåŠŸã—ãŸæ™‚ã«ç¢ºå®šã™ã‚‹ã€‚
+
+ +

トランザクションを破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `vltranabort' を用ã„る。

+ +
+
int vltranabort(VILLA *villa);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。トランザクションã®ä¸­ã§ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ›´æ–°ã¯ã‚¢ãƒœãƒ¼ãƒˆã—ãŸæ™‚ã«ã¯ç ´æ£„ã•ã‚Œã‚‹ã€‚データベースã®çŠ¶æ…‹ã¯ãƒˆãƒ©ãƒ³ã‚¶ã‚¯ã‚·ãƒ§ãƒ³ã®å‰ã®çŠ¶æ…‹ã«ãƒ­ãƒ¼ãƒ«ãƒãƒƒã‚¯ã•ã‚Œã‚‹ã€‚
+
+ +

データベースファイルを削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlremove' を用ã„る。

+ +
+
int vlremove(const char *name);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

壊れãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’修復ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlrepair' を用ã„る。

+ +
+
int vlrepair(const char *name, VLCFUNC cmp);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚`cmp' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®æ¯”較関数を指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。修復ã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å…¨ãƒ¬ã‚³ãƒ¼ãƒ‰ãŒå…ƒæ¥ã‚‚ã—ãã¯æœŸå¾…ã•ã‚Œã‚‹çŠ¶æ…‹ã«æˆ»ã‚‹ä¿è¨¼ã¯ãªã„。
+
+ +

å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’エンディアンéžä¾å­˜ã®ãƒ‡ãƒ¼ã‚¿ã¨ã—ã¦ãƒ€ãƒ³ãƒ—ã™ã‚‹ã«ã¯ã€é–¢æ•° `vlexportdb' を用ã„る。

+ +
+
int vlexportdb(VILLA *villa, const char *name);
+
`villa' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`name' ã¯å‡ºåŠ›ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

エンディアンéžä¾å­˜ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’ロードã™ã‚‹ã«ã¯ã€é–¢æ•° `vlimportdb' を用ã„る。

+ +
+
int vlimportdb(VILLA *villa, const char *name);
+
`villa' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚データベースã¯ç©ºã§ãªã‘ã‚Œã°ãªã‚‰ãªã„。`name' ã¯å…¥åŠ›ãƒ•ã‚¡ã‚¤ãƒ«ã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

サンプルコード

+ +

åå‰ã¨å¯¾å¿œã•ã›ã¦é›»è©±ç•ªå·ã‚’æ ¼ç´ã—ã€ãれを検索ã™ã‚‹ã‚¢ãƒ—リケーションã®ã‚µãƒ³ãƒ—ルコードを以下ã«ç¤ºã™ã€‚

+ +
#include <depot.h>
+#include <cabin.h>
+#include <villa.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define NAME     "mikio"
+#define NUMBER   "000-1234-5678"
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  VILLA *villa;
+  char *val;
+
+  /* データベースを開ã */
+  if(!(villa = vlopen(DBNAME, VL_OWRITER | VL_OCREAT, VL_CMPLEX))){
+    fprintf(stderr, "vlopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* レコードを格ç´ã™ã‚‹ */
+  if(!vlput(villa, NAME, -1, NUMBER, -1, VL_DOVER)){
+    fprintf(stderr, "vlput: %s\n", dperrmsg(dpecode));
+  }
+
+  /* レコードをå–å¾—ã™ã‚‹ */
+  if(!(val = vlget(villa, NAME, -1, NULL))){
+    fprintf(stderr, "vlget: %s\n", dperrmsg(dpecode));
+  } else {
+    printf("Name: %s\n", NAME);
+    printf("Number: %s\n", val);
+    free(val);
+  }
+
+  /* データベースを閉ã˜ã‚‹ */
+  if(!vlclose(villa)){
+    fprintf(stderr, "vlclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

文字列ã®å‰æ–¹ä¸€è‡´æ¤œç´¢ã‚’è¡Œã†ã‚¢ãƒ—リケーションã®ã‚µãƒ³ãƒ—ルコードを以下ã«ç¤ºã™ã€‚

+ +
#include <depot.h>
+#include <cabin.h>
+#include <villa.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define DBNAME   "words"
+#define PREFIX   "apple"
+
+int main(int argc, char **argv){
+  VILLA *villa;
+  char *key, *val;
+
+  /* データベースを開ã */
+  if(!(villa = vlopen(DBNAME, VL_OWRITER | VL_OCREAT, VL_CMPLEX))){
+    fprintf(stderr, "vlopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* レコードを格ç´ã™ã‚‹ */
+  if(!vlput(villa, "applet", -1, "little application", -1, VL_DDUP) ||
+     !vlput(villa, "aurora", -1, "polar wonderwork", -1, VL_DDUP) ||
+     !vlput(villa, "apple", -1, "delicious fruit", -1, VL_DDUP) ||
+     !vlput(villa, "amigo", -1, "good friend", -1, VL_DDUP) ||
+     !vlput(villa, "apple", -1, "big city", -1, VL_DDUP)){
+    fprintf(stderr, "vlput: %s\n", dperrmsg(dpecode));
+  }
+
+  /* カーソルを候補ã®å…ˆé ­ã«ç½®ã */
+  vlcurjump(villa, PREFIX, -1, VL_JFORWARD);
+
+  /* カーソルを走査ã™ã‚‹ */
+  while((key = vlcurkey(villa, NULL)) != NULL){
+    if(strstr(key, PREFIX) != key){
+      free(key);
+      break;
+    }
+    if(!(val = vlcurval(villa, NULL))){
+      fprintf(stderr, "vlcurval: %s\n", dperrmsg(dpecode));
+      free(key);
+      break;
+    }
+    printf("%s: %s\n", key, val);
+    free(val);
+    free(key);
+    vlcurnext(villa);
+  }
+
+  /* データベースを閉ã˜ã‚‹ */
+  if(!vlclose(villa)){
+    fprintf(stderr, "vlclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

注記

+ +

Villaを利用ã—ãŸãƒ—ログラムをビルドã™ã‚‹æ–¹æ³•ã¯ã€Depotã®å ´åˆã¨å…¨ãåŒã˜ã§ã‚る。

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

POSIXスレッドを有効ã«ã—ã¦QDBMをビルドã—ãŸå ´åˆã€å¤–部変数 `dpecode' ã¯ã‚¹ãƒ¬ãƒƒãƒ‰å›ºæœ‰ãƒ‡ãƒ¼ã‚¿ã¸ã®å‚ç…§ã¨ã—ã¦æ‰±ã‚ã‚Œã€Villaã®å„関数ã¯ãƒªã‚¨ãƒ³ãƒˆãƒ©ãƒ³ãƒˆã«ãªã‚‹ã€‚ãã®å ´åˆã€ã‚¹ãƒ¬ãƒƒãƒ‰é–“ã§åŒæ™‚ã«åŒã˜ãƒãƒ³ãƒ‰ãƒ«ã«ã‚¢ã‚¯ã‚»ã‚¹ã—ãªã„é™ã‚Šã¯ã€å„関数ã¯ã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ã§ã‚る。ãŸã ã—ã€`errno' ã‚„ `malloc' ç­‰ãŒã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ãªå‡¦ç†ç³»ã§ã‚ã‚‹ã“ã¨ãŒå‰æã¨ãªã‚‹ã€‚

+ +

Vista: 拡張上級API

+ +

Vistaã¯Villaã‚’æ‹¡å¼µã—ãŸAPIã§ã‚る。VillaãŒ2GB以上ã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚’扱ã†ã“ã¨ãŒã§ããªã„ã¨ã„ã†æ¬ ç‚¹ã‚’補ã†ãŸã‚ã«ã€Vistaã§ã¯Depotã§ã¯ãªãCuriaを用ã„ã¦å†…部データベースを管ç†ã™ã‚‹ã€‚Vistaã¯Villaã¨åŒã˜ãB+木ã®ãƒ‡ãƒ¼ã‚¿æ§‹é€ ã¨ãã®æ“作をæä¾›ã™ã‚‹ãŒã€ãã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¯ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã§å®Ÿç¾ã•ã‚Œã‚‹ã€‚

+ +

Vistaを使ã†ã«ã¯ã€`villa.h' ã®ä»£ã‚ã‚Šã« `vista.h' をインクルードã™ã‚Œã°ã‚ˆã„。Vistaã¯Villaã®ã‚·ãƒ³ãƒœãƒ«ã‚’マクロã§ã‚ªãƒ¼ãƒãƒ¼ãƒ©ã‚¤ãƒ‰ã—ã¦å®Ÿè£…ã•ã‚Œã¦ã„ã‚‹ãŸã‚ã€Villaã¨å…¨ãåŒæ§˜ã®APIã§åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ãる。ã™ãªã‚ã¡ã€åŒæ–¹ã®ã‚·ã‚°ãƒãƒãƒ£ã¯å…¨ãåŒã˜ã§ã‚る。ãŸã ã—ã€ãã®å‰¯ä½œç”¨ã¨ã—ã¦ã€Vistaを使ã†ãƒ¢ã‚¸ãƒ¥ãƒ¼ãƒ«ï¼ˆã‚³ãƒ³ãƒ‘イルユニット)ã¯Villaを利用ã™ã‚‹ã“ã¨ãŒã§ããªã„(`villa.h' をインクルードã—ã¦ã¯ãªã‚‰ãªã„)。

+ +
+ +

Villa用コマンド

+ +

Villaã«å¯¾å¿œã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ãƒ©ã‚¤ãƒ³ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ã¯ä»¥ä¸‹ã®ã‚‚ã®ã§ã‚る。

+ +

コマンド `vlmgr' ã¯Villaã‚„ãã®ã‚¢ãƒ—リケーションã®ãƒ‡ãƒãƒƒã‚°ã«å½¹ç«‹ã¤ãƒ„ールã§ã‚る。データベースを更新ã—ãŸã‚Šã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®çŠ¶æ…‹ã‚’調ã¹ãŸã‚Šã™ã‚‹æ©Ÿèƒ½ã‚’æŒã¤ã€‚シェルスクリプトã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚¢ãƒ—リケーションを作るã®ã«ã‚‚利用ã§ãる。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`key' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã€`val' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’指定ã™ã‚‹ã€‚

+ +
+
vlmgr create [-cz|-cy|-cx] name
+
データベースファイルを作æˆã™ã‚‹ã€‚
+
vlmgr put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat|-dup] name key val
+
キーã¨å€¤ã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’追加ã™ã‚‹ã€‚
+
vlmgr out [-l] [-kx|-ki] name key
+
キーã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’削除ã™ã‚‹ã€‚
+
vlmgr get [-nl] [-l] [-kx|-ki] [-ox] [-n] name key
+
キーã«å¯¾å¿œã™ã‚‹ãƒ¬ã‚³ãƒ¼ãƒ‰ã®å€¤ã‚’å–å¾—ã—ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
vlmgr list [-nl] [-k|-v] [-kx|-ki] [-ox] [-top key] [-bot key] [-gt] [-lt] [-max num] [-desc] name
+
データベース内ã®å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ã‚­ãƒ¼ã¨å€¤ã‚’タブã¨æ”¹è¡Œã§åŒºåˆ‡ã£ã¦æ¨™æº–出力ã™ã‚‹ã€‚
+
vlmgr optimize name
+
データベースを最é©åŒ–ã™ã‚‹ã€‚
+
vlmgr inform [-nl] name
+
データベースã®é›‘多ãªæƒ…報を出力ã™ã‚‹ã€‚
+
vlmgr remove name
+
データベースファイルを削除ã™ã‚‹ã€‚
+
vlmgr repair [-ki] name
+
壊れãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’修復ã™ã‚‹ã€‚
+
vlmgr exportdb [-ki] name file
+
å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’エンディアンéžä¾å­˜ã®ãƒ‡ãƒ¼ã‚¿ã¨ã—ã¦ãƒ€ãƒ³ãƒ—ã™ã‚‹ã€‚
+
vlmgr importdb [-ki] name file
+
エンディアンéžä¾å­˜ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’ロードã™ã‚‹ã€‚
+
vlmgr version
+
QDBMã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³æƒ…報を標準出力ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -cz : データベースã®ãƒªãƒ¼ãƒ•ã‚’ZLIBã§åœ§ç¸®ã™ã‚‹ã€‚
  • +
  • -cy : データベースã®ãƒªãƒ¼ãƒ•ã‚’LZOã§åœ§ç¸®ã™ã‚‹ã€‚
  • +
  • -cx : データベースã®ãƒªãƒ¼ãƒ•ã‚’BZIP2ã§åœ§ç¸®ã™ã‚‹ã€‚
  • +
  • -l : キーã«ä¸€è‡´ã™ã‚‹å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’処ç†å¯¾è±¡ã¨ã™ã‚‹ã€‚
  • +
  • -kx : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—㦠`key' を扱ã†ã€‚
  • +
  • -ki : 10進数ã«ã‚ˆã‚‹æ•°å€¤è¡¨ç¾ã¨ã—㦠`key' を扱ã†ã€‚
  • +
  • -vx : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—㦠`val' を扱ã†ã€‚
  • +
  • -vi : 10進数ã«ã‚ˆã‚‹æ•°å€¤è¡¨ç¾ã¨ã—㦠`val' を扱ã†ã€‚
  • +
  • -vf : åå‰ãŒ `val' ã®ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ‡ãƒ¼ã‚¿ã‚’値ã¨ã—ã¦èª­ã¿è¾¼ã‚€ã€‚
  • +
  • -keep : 既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã‚­ãƒ¼ãŒé‡è¤‡æ™‚ã«ä¸Šæ›¸ãã›ãšã«ã‚¨ãƒ©ãƒ¼ã«ã™ã‚‹ã€‚
  • +
  • -cat : 既存ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã‚­ãƒ¼ãŒé‡è¤‡æ™‚ã«å€¤ã‚’末尾ã«è¿½åŠ ã™ã‚‹ã€‚
  • +
  • -dup : レコードã®ã‚­ãƒ¼ãŒé‡è¤‡ã™ã‚‹ã®ã‚’許ã™ã€‚
  • +
  • -nl : ファイルロックをã‹ã‘ãšã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã。
  • +
  • -top key : リストã®æœ€å°ã®ã‚­ãƒ¼ã‚’指定ã™ã‚‹ã€‚
  • +
  • -bot key : リストã®æœ€å¤§ã®ã‚­ãƒ¼ã‚’指定ã™ã‚‹ã€‚
  • +
  • -gt : 最å°ã®ã‚­ãƒ¼ã‚’リストã«å«ã‚ãªã„。
  • +
  • -lt : 最大ã®ã‚­ãƒ¼ã‚’リストã«å«ã‚ãªã„。
  • +
  • -max num : リストã™ã‚‹æœ€å¤§æ•°ã‚’指定ã™ã‚‹ã€‚
  • +
  • -desc : リストをé™é †ã§è¡Œã†ã€‚
  • +
  • -ox : 2æ¡å˜ä½ã®16進数ã«ã‚ˆã‚‹ãƒã‚¤ãƒŠãƒªè¡¨ç¾ã¨ã—ã¦æ¨™æº–出力を行ã†ã€‚
  • +
  • -n : 標準出力ã®æœ«å°¾ã«ä»˜åŠ ã•ã‚Œã‚‹æ”¹è¡Œæ–‡å­—ã®å‡ºåŠ›ã‚’抑制ã™ã‚‹ã€‚
  • +
  • -k : キーã®ã¿ã‚’出力ã™ã‚‹ã€‚
  • +
  • -v : 値ã®ã¿ã‚’出力ã™ã‚‹ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚環境変数 `QDBMDBGFD' ã®å€¤ã¨ã—ã¦ã€å¤‰æ•° `dpecode' ã®å¤‰æ›´å±¥æ­´ã‚’出力ã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—タを指定ã“ã¨ãŒã§ãる。

+ +

コマンド `vltest' ã¯Villaã®æ©Ÿèƒ½ãƒ†ã‚¹ãƒˆã‚„性能テストã«ç”¨ã„るツールã§ã‚る。ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã«ã‚ˆã£ã¦ç”Ÿæˆã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ `vlmgr' ã«ã‚ˆã£ã¦è§£æžã—ãŸã‚Šã€`time' コマンドã«ã‚ˆã£ã¦ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã®å®Ÿè¡Œæ™‚間を計ã£ãŸã‚Šã™ã‚‹ã¨ã‚ˆã„。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`rnum' ã¯ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã€`pnum' ã¯ã‚­ãƒ¼ã®ãƒ‘ターン数を指定ã™ã‚‹ã€‚

+ +
+
vltest write [-int] [-cz|-cy|-cx] [-tune lrecmax nidxmax lcnum ncnum] [-fbp num] name rnum
+
`00000001'ã€`00000002' ã®ã‚ˆã†ã«å¤‰åŒ–ã™ã‚‹8ãƒã‚¤ãƒˆã®ã‚­ãƒ¼ã¨é©å½“ãª8ãƒã‚¤ãƒˆã®å€¤ã‚’連続ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«è¿½åŠ ã™ã‚‹ã€‚
+
vltest read [-int] [-vc] name
+
上記ã§ç”Ÿæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å…¨ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’検索ã™ã‚‹ã€‚
+
vltest rdup [-int] [-cz|-cy|-cx] [-cc] [-tune lrecmax nidxmax lcnum ncnum] [-fbp num] name rnum pnum
+
キーãŒã‚る程度é‡è¤‡ã™ã‚‹ã‚ˆã†ã«ãƒ¬ã‚³ãƒ¼ãƒ‰ã®è¿½åŠ ã‚’è¡Œã„ã€é‡è¤‡ãƒ¢ãƒ¼ãƒ‰ã§å‡¦ç†ã™ã‚‹ã€‚
+
vltest combo [-cz|-cy|-cx] name
+
å„種æ“作ã®çµ„ã¿åˆã‚ã›ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚
+
vltest wicked [-cz|-cy|-cx] name rnum
+
å„種更新æ“作を無作為ã«é¸æŠžã—ã¦å®Ÿè¡Œã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -int : `int' åž‹ã®ã‚ªãƒ–ジェクトをキーã¨å€¤ã«ç”¨ã„ã€æ¯”較関数もãã‚Œã«åˆã‚ã›ã‚‹ã€‚
  • +
  • -cz : データベースã®ãƒªãƒ¼ãƒ•ã‚’ZLIBã§åœ§ç¸®ã™ã‚‹ã€‚
  • +
  • -cy : データベースã®ãƒªãƒ¼ãƒ•ã‚’LZOã§åœ§ç¸®ã™ã‚‹ã€‚
  • +
  • -cx : データベースã®ãƒªãƒ¼ãƒ•ã‚’BZIP2ã§åœ§ç¸®ã™ã‚‹ã€‚
  • +
  • -vc : æ®ç™ºæ€§ã‚­ãƒ£ãƒƒã‚·ãƒ¥ã‚’å‚ç…§ã™ã‚‹ã€‚
  • +
  • -cc : 連çµãƒ¢ãƒ¼ãƒ‰ã¨é‡è¤‡ãƒ¢ãƒ¼ãƒ‰ã‚’無作為ã«é¸æŠžã™ã‚‹ã€‚
  • +
  • -tune lrecmax nidxmax lcnum ncnum : 性能パラメータを指定ã™ã‚‹ã€‚
  • +
  • -fbp num : フリーブロックプールã®ã‚µã‚¤ã‚ºã‚’指定ã™ã‚‹ã€‚
  • +
  • -c : Cabinã®ãƒžãƒƒãƒ—を使ã£ã¦æ¯”較テストを行ã†ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚環境変数 `QDBMDBGFD' ã®å€¤ã¨ã—ã¦ã€å¤‰æ•° `dpecode' ã®å¤‰æ›´å±¥æ­´ã‚’出力ã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—タを指定ã“ã¨ãŒã§ãる。

+ +

コマンド `vltsv' ã¯ã‚¿ãƒ–区切りã§ã‚­ãƒ¼ã¨å€¤ã‚’表ç¾ã—ãŸè¡Œã‹ã‚‰ãªã‚‹TSVファイルã¨Villaã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’相互変æ›ã™ã‚‹ã€‚ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯ã€QDBMã®ä»–ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã‚„ä»–ã®DBMã¨ã®é–“ã§ãƒ‡ãƒ¼ã‚¿ã®äº¤æ›ã‚’è¡Œã†éš›ã«å½¹ç«‹ã¤ã€‚ã¾ãŸã€ãƒã‚¤ãƒˆã‚ªãƒ¼ãƒ€ã®é•ã†ã‚·ã‚¹ãƒ†ãƒ ã®é–“ã§ãƒ‡ãƒ¼ã‚¿ã‚’交æ›ã™ã‚‹éš›ã«ã‚‚役立ã¤ã€‚以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åを指定ã™ã‚‹ã€‚`export' サブコマンドã§ã¯TSVã®ãƒ‡ãƒ¼ã‚¿ã¯æ¨™æº–入力ã‹ã‚‰èª­ã¿è¾¼ã‚€ã€‚`import' サブコマンドã§ã¯TSVã®ãƒ‡ãƒ¼ã‚¿ãŒæ¨™æº–出力ã«æ›¸ã出ã•ã‚Œã‚‹ã€‚

+ +
+
vltsv import [-bin] name
+
TSVファイルを読ã¿è¾¼ã‚“ã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã™ã‚‹ã€‚
+
vltsv export [-bin] name
+
データベースã®å…¨ã¦ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’TSVファイルã¨ã—ã¦å‡ºåŠ›ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -bin : Base64å½¢å¼ã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’扱ã†ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +

Villaã®ã‚³ãƒžãƒ³ãƒ‰ç¾¤ã‚’駆使ã™ã‚‹ã¨ã€ç°¡å˜ãªãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚·ã‚¹ãƒ†ãƒ ãŒæ§‹ç¯‰ã§ãる。例ãˆã° `/etc/password' をユーザåã§æ¤œç´¢ã™ã‚‹ãŸã‚ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã™ã‚‹ã«ã¯ã€ä»¥ä¸‹ã®ã‚ˆã†ã«ã™ã‚‹ã€‚

+ +
cat /etc/passwd | tr ':' '\t' | vltsv import casket
+
+ +

ãã—ã¦ã€`mikio' ã¨ã„ã†ãƒ¦ãƒ¼ã‚¶ã®æƒ…報をå–り出ã™ã«ã¯ã€ä»¥ä¸‹ã®ã‚ˆã†ã«ã™ã‚‹ã€‚

+ +
vlmgr get casket mikio
+
+ +

ã“れらã®ã‚³ãƒžãƒ³ãƒ‰ã¨åŒç­‰ã®æ©Ÿèƒ½ã‚’Villaã®APIを用ã„ã¦å®Ÿè£…ã™ã‚‹ã“ã¨ã‚‚容易ã§ã‚る。

+ +

コマンド `qmttest' ã¯Depotã¨Curiaã¨Villaã®ãƒžãƒ«ãƒã‚¹ãƒ¬ãƒƒãƒ‰ã«ãŠã‘る安全性を調査ã™ã‚‹ã€‚ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯POSIXスレッドを有効ã«ã—ã¦QDBMをビルドã—ãŸå ´åˆã«ã®ã¿ãƒžãƒ«ãƒã‚¹ãƒ¬ãƒƒãƒ‰ã§å‹•ä½œã™ã‚‹ã€‚以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã®æŽ¥é ­è¾žã‚’指定ã™ã‚‹ã€‚`rnum' ã¯å„データベースã«æ›¸ã込むレコード数を指定ã™ã‚‹ã€‚`tnum' ã¯ã‚¹ãƒ¬ãƒƒãƒ‰æ•°ã‚’指定ã™ã‚‹ã€‚

+ +
+
qmttest name rnum tnum
+
マルãƒã‚¹ãƒ¬ãƒƒãƒ‰ã«ãŠã‘る安全性を調査ã™ã‚‹ã€‚
+
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +
+ +

Odeum: 転置API

+ +

概è¦

+ +

Odeumã¯è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’扱ã†APIã§ã‚る。転置インデックスã¨ã¯ã€æ¯é›†å›£ã®æ–‡æ›¸ç¾¤ã«å«ã¾ã‚Œã‚‹èªžã‚’抽出ã—ã¦ã€å„語をキーã¨ã—ã€ãã®èªžã‚’å«ã‚€æ–‡æ›¸ã®ãƒªã‚¹ãƒˆã‚’検索ã™ã‚‹ãŸã‚ã®ãƒ‡ãƒ¼ã‚¿æ§‹é€ ã§ã‚る。転置インデックスを用ã„ã‚‹ã¨ã€å…¨æ–‡æ¤œç´¢ã‚·ã‚¹ãƒ†ãƒ ã‚’容易ã«å®Ÿç¾ã™ã‚‹ã“ã¨ãŒã§ãる。Odeumã¯æ–‡æ›¸ã‚’語や属性ã®é›†åˆã¨ã—ã¦æ‰±ã†ãŸã‚ã®æŠ½è±¡ãƒ‡ãƒ¼ã‚¿åž‹ã‚’æä¾›ã™ã‚‹ã€‚ãã‚Œã¯ã€å„アプリケーションãŒOdeumã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ–‡æ›¸ã‚’æ ¼ç´ã™ã‚‹éš›ã‚„ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‹ã‚‰æ–‡æ›¸ã‚’検索ã™ã‚‹éš›ã«ç”¨ã„られる。

+ +

Odeumã¯å…ƒæ¥ã®æ–‡æ›¸ãƒ‡ãƒ¼ã‚¿ã‹ã‚‰ãƒ†ã‚­ã‚¹ãƒˆã‚’抽出ã™ã‚‹æ–¹æ³•ã¯æä¾›ã—ãªã„。ãã‚Œã¯ã‚¢ãƒ—リケーションãŒå®Ÿè£…ã™ã‚‹å¿…è¦ãŒã‚る。Odeumã¯ãƒ†ã‚­ã‚¹ãƒˆã‚’分解ã—ã¦èªžç¾¤ã‚’抽出ã™ã‚‹ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£ã‚’æä¾›ã™ã‚‹ãŒã€ãã‚Œã¯ç©ºç™½ã§èªžãŒåˆ†å‰²ã•ã‚Œã‚‹è‹±èªžãªã©ã®è¨€èªžã‚’指å‘ã—ã¦ã„る。形態素解æžã‚„N-gram解æžãŒå¿…è¦ãªæ—¥æœ¬èªžãªã©ã®è¨€èªžã‚’扱ã†éš›ã‚„ã€ã‚¹ãƒ†ãƒŸãƒ³ã‚°ãªã©ã®ã‚ˆã‚Šé«˜åº¦ãªè‡ªç„¶è¨€èªžå‡¦ç†ã‚’è¡Œã†éš›ã«ã¯ã€ã‚¢ãƒ—リケーションã¯ç‹¬è‡ªã®è§£æžæ–¹æ³•ã‚’é©ç”¨ã™ã‚‹ã“ã¨ãŒã§ãる。検索çµæžœã¯æ–‡æ›¸ã®ID番å·ã¨ãã®ã‚¹ã‚³ã‚¢ã‚’メンãƒã«æŒã¤æ§‹é€ ä½“ã‚’è¦ç´ ã¨ã™ã‚‹é…列ã¨ã—ã¦å¾—られる。複数ã®èªžã‚’用ã„ã¦æ¤œç´¢ã‚’è¡Œã†ãŸã‚ã«ã€Odeumã¯çµæžœã®é…列ã®é›†åˆæ¼”ç®—ã‚’è¡Œã†ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£ã‚’æä¾›ã™ã‚‹ã€‚

+ +

Odeumã¯Curiaã¨Cabinã¨Villaを基盤ã¨ã—ã¦å®Ÿè£…ã•ã‚Œã‚‹ã€‚Odeumã§ã¯ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªåを指定ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’構築ã™ã‚‹ã€‚特定ã®ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®ç›´ä¸‹ã«Curiaã‚„Villaã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’構築ã™ã‚‹ã€‚例ãˆã°ã€`casket' ã¨ã„ã†åå‰ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’作æˆã™ã‚‹å ´åˆã€`casket/docs'ã€`casket/index' ãŠã‚ˆã³ `casket/rdocs' ãŒç”Ÿæˆã•ã‚Œã‚‹ã€‚`docs' ã¯Curiaã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã§ã‚る。キーã¯æ–‡æ›¸ã®ID番å·ã§ã‚ã‚Šã€å€¤ã¯URIç­‰ã®æ–‡æ›¸å±žæ€§ã§ã‚る。`index' ã¯Curiaã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã§ã‚る。キーã¯èªžã®æ­£è¦å½¢ã§ã‚ã‚Šã€å€¤ã¯ãã®èªžã‚’å«ã‚€æ–‡æ›¸ã®ID番å·ã¨ãã®ã‚¹ã‚³ã‚¢ã‚’è¦ç´ ã¨ã™ã‚‹é…列ã§ã‚る。`rdocs' ã¯Villaã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã§ã‚る。キーã¯æ–‡æ›¸ã®URIã§ã‚ã‚Šã€å€¤ã¯æ–‡æ›¸ã®ID番å·ã§ã‚る。

+ +

Odeumを使ã†ãŸã‚ã«ã¯ã€`depot.h' 㨠`cabin.h' 㨠`odeum.h' 㨠`stdlib.h' をインクルードã™ã¹ãã§ã‚る。通常ã€ã‚½ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®å†’頭付近ã§ä»¥ä¸‹ã®è¨˜è¿°ã‚’è¡Œã†ã€‚

+ +
+
#include <depot.h>
+
#include <cabin.h>
+
#include <odeum.h>
+
#include <stdlib.h>
+
+ +

Odeumã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’扱ã†éš›ã«ã¯ã€`ODEUM' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `odopen' ã§é–‹ãã€é–¢æ•° `odclose' ã§é–‰ã˜ã‚‹ã€‚ãƒãƒ³ãƒ‰ãƒ«ã®ãƒ¡ãƒ³ãƒã‚’直接å‚ç…§ã™ã‚‹ã“ã¨ã¯æŽ¨å¥¨ã•ã‚Œãªã„。データベースã«è‡´å‘½çš„ãªã‚¨ãƒ©ãƒ¼ãŒèµ·ããŸå ´åˆã¯ã€ä»¥å¾Œãã®ãƒãƒ³ãƒ‰ãƒ«ã«å¯¾ã™ã‚‹ `odclose' を除ãå…¨ã¦ã®æ“作ã¯ä½•ã‚‚ã›ãšã«ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã™ã€‚ã²ã¨ã¤ã®ãƒ—ロセスã§è¤‡æ•°ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’åŒæ™‚ã«åˆ©ç”¨ã™ã‚‹ã“ã¨ã¯å¯èƒ½ã§ã‚ã‚‹ãŒã€åŒã˜ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®è¤‡æ•°ã®ãƒãƒ³ãƒ‰ãƒ«ã‚’利用ã—ã¦ã¯ãªã‚‰ãªã„。

+ +

å„文書を扱ã†éš›ã«ã¯ã€`ODDOC' åž‹ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã‚’ãƒãƒ³ãƒ‰ãƒ«ã¨ã—ã¦ç”¨ã„る。ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `oddocopen' ã§é–‹ãã€é–¢æ•° `oddocclose' ã§é–‰ã˜ã‚‹ã€‚ãƒãƒ³ãƒ‰ãƒ«ã®ãƒ¡ãƒ³ãƒã‚’直接å‚ç…§ã™ã‚‹ã“ã¨ã¯æŽ¨å¥¨ã•ã‚Œãªã„。文書ã¯å±žæ€§ã¨èªžã®é›†åˆã‹ã‚‰ãªã‚‹ã€‚語ã¯æ­£è¦å½¢ã¨å‡ºç¾å½¢ã®ãƒšã‚¢ã¨ã—ã¦è¡¨ç¾ã•ã‚Œã‚‹ã€‚

+ +

Odeumã§ã‚‚Depotã¨åŒã˜ã外部変数 `dpecode' ã«ç›´å‰ã®ã‚¨ãƒ©ãƒ¼ã‚³ãƒ¼ãƒ‰ãŒè¨˜éŒ²ã•ã‚Œã‚‹ã€‚エラーコードã«å¯¾å¿œã™ã‚‹ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸æ–‡å­—列を得るã«ã¯ã€é–¢æ•° `dperrmsg' を用ã„る。

+ +

API

+ +

検索çµæžœã‚’扱ã†ãŸã‚ã«ã¯ã€`ODPAIR' åž‹ã®æ§‹é€ ä½“を用ã„る。

+ +
+
typedef struct { int id; int score; } ODPAIR;
+
`id' ã¯æ–‡æ›¸ã®ID番å·ã§ã‚る。`score' ã¯æ–‡æ›¸ã«å«ã¾ã‚Œã‚‹æ¤œç´¢èªžã®æ•°ã‚’å…ƒã«ç®—出ã•ã‚Œã‚‹ã‚¹ã‚³ã‚¢ã§ã‚る。
+
+ +

データベースã®ãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `odopen' を用ã„る。

+ +
+
ODEUM *odopen(const char *name, int omode);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®åå‰ã‚’指定ã™ã‚‹ã€‚`omode' ã¯æŽ¥ç¶šãƒ¢ãƒ¼ãƒ‰ã‚’指定ã—ã€`OD_OREADER' ãªã‚‰ãƒªãƒ¼ãƒ€ã€`OD_OWRITER' ãªã‚‰ãƒ©ã‚¤ã‚¿ã¨ãªã‚‹ã€‚`OD_OWRITER' ã®å ´åˆã€`OD_OCREAT' ã¾ãŸã¯ `OD_OTRUNC' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãる。`OD_OCREAT' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãŒç„¡ã„å ´åˆã«æ–°è¦ä½œæˆã™ã‚‹ã“ã¨ã‚’指示ã—ã€`OD_OTRUNC' ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãŒå­˜åœ¨ã—ã¦ã‚‚作り直ã™ã“ã¨ã‚’指示ã™ã‚‹ã€‚`OD_OREADER' 㨠`OD_OWRITER' ã®ä¸¡æ–¹ã§ `OD_ONOLCK' ã‹ `OD_OLCKNB' ã¨ã®ãƒ“ット論ç†å’Œã«ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ãŒã€å‰è€…ã¯ãƒ•ã‚¡ã‚¤ãƒ«ãƒ­ãƒƒã‚¯ã‚’ã‹ã‘ãšã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ãã“ã¨ã‚’指示ã—ã€å¾Œè€…ã¯ãƒ–ロックã›ãšã«ãƒ­ãƒƒã‚¯ã‚’ã‹ã‘ã‚‹ã“ã¨ã‚’指示ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚‹ã‹ã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。ライタ(読ã¿æ›¸ã両用モード)ã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’é–‹ãéš›ã«ã¯ãã®ãƒ•ã‚¡ã‚¤ãƒ«ã«å¯¾ã—ã¦æŽ’他ロックãŒã‹ã‘られã€ãƒªãƒ¼ãƒ€ï¼ˆèª­ã¿è¾¼ã¿å°‚用モード)ã§é–‹ãéš›ã«ã¯å…±æœ‰ãƒ­ãƒƒã‚¯ãŒã‹ã‘られる。ãã®éš›ã«ã¯è©²å½“ã®ãƒ­ãƒƒã‚¯ãŒã‹ã‘られるã¾ã§åˆ¶å¾¡ãŒãƒ–ロックã™ã‚‹ã€‚`OD_ONOLCK' を使ã†å ´åˆã€ã‚¢ãƒ—リケーションãŒæŽ’他制御ã®è²¬ä»»ã‚’è² ã†ã€‚
+
+ +

データベースã¨ã®æŽ¥ç¶šã‚’é–‰ã˜ã¦ãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `odclose' を用ã„る。

+ +
+
int odclose(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。データベースã®æ›´æ–°å†…容ã¯ã€æŽ¥ç¶šã‚’é–‰ã˜ãŸæ™‚点ã§åˆã‚ã¦ãƒ•ã‚¡ã‚¤ãƒ«ã¨åŒæœŸã•ã‚Œã‚‹ã€‚ライタã§ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‹ã„ãŸå ´åˆã€é©åˆ‡ã«æŽ¥ç¶šã‚’é–‰ã˜ãªã„ã¨ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãŒç ´å£Šã•ã‚Œã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã§ããªããªã‚‹ã€‚
+
+ +

文書を追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `odput' を用ã„る。

+ +
+
int odput(ODEUM *odeum, const ODDOC *doc, int wmax, int over);
+
`odeum' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`doc' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`wmax' ã¯æ–‡æ›¸ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã™ã‚‹èªžã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ãŒã€è² æ•°ãªã‚‰ç„¡åˆ¶é™ã¨ãªã‚‹ã€‚`over' ã¯é‡è¤‡ã—ãŸæ–‡æ›¸ã®ä¸Šæ›¸ãã‚’è¡Œã†ã‹å¦ã‹ã‚’指定ã™ã‚‹ã€‚ãã‚ŒãŒå½ã§æ–‡æ›¸ã®URIãŒé‡è¤‡ã—ãŸå ´åˆã¯ã‚¨ãƒ©ãƒ¼ã¨ãªã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。
+
+ +

URIã§æŒ‡å®šã—ãŸæ–‡æ›¸ã‚’削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `odout' を用ã„る。

+ +
+
int odout(ODEUM *odeum, const char *uri);
+
`odeum' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`uri' ã¯æ–‡æ›¸ã®URIã®æ–‡å­—列を指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。該当ã™ã‚‹æ–‡æ›¸ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

ID番å·ã§æŒ‡å®šã—ãŸæ–‡æ›¸ã‚’削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `odoutbyid' を用ã„る。

+ +
+
int odoutbyid(ODEUM *odeum, int id);
+
`odeum' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`id' ã¯æ–‡æ›¸ã®ID番å·ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。該当ã™ã‚‹æ–‡æ›¸ãŒãªã„å ´åˆã‚‚å½ã‚’è¿”ã™ã€‚
+
+ +

URIã§æŒ‡å®šã—ãŸæ–‡æ›¸ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `odget' を用ã„る。

+ +
+
ODDOC *odget(ODEUM *odeum, const char *uri);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`uri' ã¯æ–‡æ›¸ã®URIã®æ–‡å­—列を指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰è©²å½“ã®æ–‡æ›¸ã®ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®æ–‡æ›¸ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `oddocopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `oddocclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

ID番å·ã§æŒ‡å®šã—ãŸæ–‡æ›¸ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `odgetbyid' を用ã„る。

+ +
+
ODDOC *odgetbyid(ODEUM *odeum, int id);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`id' ã¯æ–‡æ›¸ã®ID番å·ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰è©²å½“ã®æ–‡æ›¸ã®ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。該当ã®æ–‡æ›¸ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `oddocopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `oddocclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

URIã§æŒ‡å®šã—ãŸæ–‡æ›¸ã®IDã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `odgetidbyuri' を用ã„る。

+ +
+
int odgetidbyuri(ODEUM *odeum, const char *uri);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`uri' ã¯æ–‡æ›¸ã®URIã®æ–‡å­—列を指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰è©²å½“ã®æ–‡æ›¸ã®IDã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。該当ã®æ–‡æ›¸ãŒãªã„å ´åˆã‚‚ -1 ã‚’è¿”ã™ã€‚
+
+ +

ID番å·ã§æŒ‡å®šã—ãŸæ–‡æ›¸ãŒå­˜åœ¨ã—ã¦ã„ã‚‹ã‹èª¿ã¹ã‚‹ã«ã¯ã€é–¢æ•° `odcheck' を用ã„る。

+ +
+
int odcheck(ODEUM *odeum, int id);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`id' ã¯æ–‡æ›¸ã®ID番å·ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ–‡æ›¸ãŒå­˜åœ¨ã™ã‚Œã°çœŸã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

転置インデックスを検索ã—ã¦ç‰¹å®šã®èªžã‚’å«ã‚€æ–‡æ›¸ç¾¤ã‚’知るã«ã¯ã€é–¢æ•° `odsearch' を用ã„る。

+ +
+
ODPAIR *odsearch(ODEUM *odeum, const char *word, int max, int *np);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`word' ã¯æ¤œç´¢èªžã‚’指定ã™ã‚‹ã€‚`max' ã¯å–り出ã™æ–‡æ›¸ã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ã€‚`np' ã®å‚照先ã«ã¯ã€æˆ»ã‚Šå€¤ã®é…列ã®è¦ç´ æ•°ãŒæ ¼ç´ã•ã‚Œã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰é…列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。ãã®é…列ã®å„è¦ç´ ã¯æ–‡æ›¸ã®ID番å·ã¨ã‚¹ã‚³ã‚¢ã®ãƒšã‚¢ã§ã‚ã‚Šã€ã‚¹ã‚³ã‚¢ã®é™é †ã§ä¸¦ã¹ã‚‰ã‚Œã‚‹ã€‚検索語ã«è©²å½“ã™ã‚‹æ–‡æ›¸ãŒä¸€ã¤ã‚‚ãªã‹ã£ãŸã¨ã—ã¦ã‚‚エラーã«ã¯ãªã‚‰ãšã«ã€ç©ºã®é…列を返ã™ã€‚戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。é…列ã®å„è¦ç´ ã«ã¯æ—¢ã«å‰Šé™¤ã•ã‚ŒãŸæ–‡æ›¸ã®ãƒ‡ãƒ¼ã‚¿ã‚‚å«ã¾ã‚Œã‚‹ã“ã¨ã«æ³¨æ„ã™ã¹ãã§ã‚る。
+
+ +

特定ã®èªžã‚’å«ã‚€æ–‡æ›¸ã®æ•°ã‚’知るã«ã¯ã€é–¢æ•° `odsearchdnum' を用ã„る。

+ +
+
int odsearchdnum(ODEUM *odeum, const char *word);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`word' ã¯æ¤œç´¢èªžã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰æ¤œç´¢èªžã‚’å«ã‚€æ–‡æ›¸ã®æ•°ã§ã‚ã‚Šã€è©²å½“ãŒãªã„å ´åˆã‚„エラーã®å ´åˆã¯ -1 ã§ã‚る。ã“ã®é–¢æ•°ã¯è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®å®Ÿãƒ‡ãƒ¼ã‚¿ã‚’読ã¿è¾¼ã¾ãªã„ã®ã§åŠ¹çŽ‡ãŒã‚ˆã„。
+
+ +

データベースã®ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‚’åˆæœŸåŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `oditerinit' を用ã„る。

+ +
+
int oditerinit(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。イテレータã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã•ã‚ŒãŸå…¨ã¦ã®æ–‡æ›¸ã‚’å‚ç…§ã™ã‚‹ãŸã‚ã«ç”¨ã„られる。
+
+ +

データベースã®ã‚¤ãƒ†ãƒ¬ãƒ¼ã‚¿ã‹ã‚‰æ¬¡ã®æ–‡æ›¸ã‚’å–り出ã™ã«ã¯ã€é–¢æ•° `oditernext' を用ã„る。

+ +
+
ODDOC *oditernext(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。イテレータãŒæœ€å¾Œã¾ã§ãã¦è©²å½“ã®æ–‡æ›¸ãŒãªã„å ´åˆã‚‚ `NULL' ã‚’è¿”ã™ã€‚ã“ã®é–¢æ•°ã‚’ç¹°ã‚Šè¿”ã—ã¦å‘¼ã¶ã“ã¨ã«ã‚ˆã£ã¦å…¨ã¦ã®æ–‡æ›¸ã‚’一度ãšã¤å‚ç…§ã™ã‚‹ã“ã¨ãŒã§ãる。ãŸã ã—ã€ç¹°ã‚Šè¿”ã—ã®é–“ã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æ›´æ–°ãŒã‚ã£ãŸå ´åˆã¯ãã®é™ã‚Šã§ã¯ãªã„。ãªãŠã€å–り出ã™ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é †åºã¯åˆ¶å¾¡ã§ããšã€æ ¼ç´ã—ãŸé †ç•ªã§ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’å–り出ã›ã‚‹ã¨ã¯é™ã‚‰ãªã„。戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯ã€é–¢æ•° `oddocopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `oddocclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

データベースを更新ã—ãŸå†…容をファイルã¨ãƒ‡ãƒã‚¤ã‚¹ã«åŒæœŸã•ã›ã‚‹ã«ã¯ã€é–¢æ•° `odsync' を用ã„る。

+ +
+
int odsync(ODEUM *odeum);
+
`odeum' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。ã“ã®é–¢æ•°ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‰ã˜ãªã„ã†ã¡ã«åˆ¥ãƒ—ロセスã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’利用ã•ã›ã‚‹å ´åˆã«å½¹ç«‹ã¤ã€‚
+
+ +

データベースを最é©åŒ–ã™ã‚‹ã«ã¯ã€é–¢æ•° `odoptimize' を用ã„る。

+ +
+
int odoptimize(ODEUM *odeum);
+
`odeum' ã¯ãƒ©ã‚¤ã‚¿ã§æŽ¥ç¶šã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。転置インデックスã«ãŠã‘る削除ã•ã‚ŒãŸæ–‡æ›¸ã®è¦ç´ ã¯å‰Šé™¤ã•ã‚Œã‚‹ã€‚
+
+ +

データベースã®åå‰ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odname' を用ã„る。

+ +
+
char *odname(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰åå‰ã‚’æ ¼ç´ã—ãŸé ˜åŸŸã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

データベースファイルã®ã‚µã‚¤ã‚ºã®åˆè¨ˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odfsiz' を用ã„る。

+ +
+
double odfsiz(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºã®åˆè¨ˆã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1.0 ã§ã‚る。
+
+ +

転置インデックス内ã®ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã®åˆè¨ˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odbnum' を用ã„る。

+ +
+
int odbnum(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã®åˆè¨ˆã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

転置インデックス内ã®ãƒã‚±ãƒƒãƒˆé…列ã®åˆ©ç”¨æ¸ˆã¿ã®è¦ç´ æ•°ã®åˆè¨ˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odbusenum' を用ã„る。

+ +
+
int odbusenum(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒã‚±ãƒƒãƒˆé…列ã®åˆ©ç”¨æ¸ˆã¿ã®è¦ç´ æ•°ã®åˆè¨ˆã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ + +

データベースã«æ ¼ç´ã•ã‚ŒãŸæ–‡æ›¸æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `oddnum' を用ã„る。

+ +
+
int oddnum(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã•ã‚ŒãŸæ–‡æ›¸ã®æ•°ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。
+
+ +

データベースã«æ ¼ç´ã•ã‚ŒãŸå˜èªžæ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odwnum' を用ã„る。

+ +
+
int odwnum(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã•ã‚ŒãŸèªžã®æ•°ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ -1 ã§ã‚る。I/Oãƒãƒƒãƒ•ã‚¡ã«ã‚ˆã‚Šã€æˆ»ã‚Šå€¤ã¯å®Ÿéš›ã®ã‚µã‚¤ã‚ºã‚ˆã‚Šå°ã•ããªã‚‹å ´åˆãŒã‚る。
+
+ +

データベースãƒãƒ³ãƒ‰ãƒ«ãŒãƒ©ã‚¤ã‚¿ã‹ã©ã†ã‹ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `odwritable' を用ã„る。

+ +
+
int odwritable(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ©ã‚¤ã‚¿ãªã‚‰çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

データベースã«è‡´å‘½çš„エラーãŒèµ·ããŸã‹ã©ã†ã‹ã‚’調ã¹ã‚‹ã«ã¯ã€é–¢æ•° `odfatalerror' を用ã„る。

+ +
+
int odfatalerror(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯è‡´å‘½çš„エラーãŒã‚ã‚Œã°çœŸã§ã‚ã‚Šã€ãã†ã§ãªã‘ã‚Œã°å½ã§ã‚る。
+
+ +

データベースディレクトリã®inode番å·ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odinode' を用ã„る。

+ +
+
int odinode(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®inode番å·ã§ã‚る。
+
+ +

データベースã®æœ€çµ‚更新時刻を得るã«ã¯ã€é–¢æ•° `odmtime' を用ã„る。

+ +
+
time_t odmtime(ODEUM *odeum);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®æœ€çµ‚更新時刻ã§ã‚る。
+
+ +

複数ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’マージã™ã‚‹ã«ã¯ã€é–¢æ•° `odmerge' を用ã„る。

+ +
+
int odmerge(const char *name, const CBLIST *elemnames);
+
`name' ã¯ä½œæˆã™ã‚‹ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®åå‰ã‚’指定ã™ã‚‹ã€‚`elemnames' ã¯è¦ç´ ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®åå‰ã®ãƒªã‚¹ãƒˆã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。åŒã˜URLã‚’æŒã¤è¤‡æ•°ã®æ–‡æ›¸ãŒç¾ã‚ŒãŸå ´åˆã€æœ€åˆã«ç¾ã‚ŒãŸã‚‚ã®ãŒæŽ¡ç”¨ã•ã‚Œã€æ®‹ã‚Šã¯ç„¡è¦–ã•ã‚Œã‚‹ã€‚
+
+ +

データベースディレクトリを削除ã™ã‚‹ã«ã¯ã€é–¢æ•° `odremove' を用ã„る。

+ +
+
int odremove(const char *name);
+
`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®åå‰ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰çœŸã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰å½ã§ã‚る。データベースディレクトリã®ä¸­ã«ã¯QDBMã®ä»–ã®APIã«ã‚ˆã‚‹ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’ç½®ãã“ã¨ãŒã§ãã‚‹ãŒã€ãれらもã“ã®é–¢æ•°ã«ã‚ˆã£ã¦å‰Šé™¤ã•ã‚Œã‚‹ã€‚
+
+ +

文書ãƒãƒ³ãƒ‰ãƒ«ã‚’作æˆã™ã‚‹ã«ã¯ã€é–¢æ•° `oddocopen' を用ã„る。

+ +
+
ODDOC *oddocopen(const char *uri);
+
`uri' ã¯æ–‡æ›¸ã®URIを指定ã™ã‚‹ã€‚戻り値ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。新ã—ã„文書ã®ID番å·ã¯å®šç¾©ã•ã‚Œãªã„。ãã‚Œã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã—ãŸéš›ã«å®šç¾©ã•ã‚Œã‚‹ã€‚
+
+ +

文書ãƒãƒ³ãƒ‰ãƒ«ã‚’破棄ã™ã‚‹ã«ã¯ã€é–¢æ•° `oddocclose' を用ã„る。

+ +
+
void oddocclose(ODDOC *doc);
+
`doc' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚é–‰ã˜ãŸãƒãƒ³ãƒ‰ãƒ«ã®é ˜åŸŸã¯è§£æ”¾ã•ã‚Œã‚‹ã®ã§ã€ä»¥å¾Œã¯åˆ©ç”¨ã§ããªããªã‚‹ã€‚
+
+ +

文書ã«å±žæ€§ã‚’追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `oddocaddattr' を用ã„る。

+ +
+
void oddocaddattr(ODDOC *doc, const char *name, const char *value);
+
`doc' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`name' ã¯å±žæ€§åã®æ–‡å­—列を指定ã™ã‚‹ã€‚`value' ã¯å±žæ€§å€¤ã®æ–‡å­—列を指定ã™ã‚‹ã€‚
+
+ +

文書ã«èªžã‚’追加ã™ã‚‹ã«ã¯ã€é–¢æ•° `oddocaddword' を用ã„る。

+ +
+
void oddocaddword(ODDOC *doc, const char *normal, const char *asis);
+
`doc' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`normal' ã¯èªžã®æ­£è¦å½¢ã®æ–‡å­—列を指定ã™ã‚‹ã€‚æ­£è¦å½¢ã¯è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®ã‚­ãƒ¼ã¨ã—ã¦æ‰±ã‚れる。正è¦å½¢ãŒç©ºæ–‡å­—列ã®å ´åˆã€ãã®èªžã¯è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã«å映ã•ã‚Œãªã„。`asis' ã¯èªžã®å‡ºç¾å½¢ã®æ–‡å­—列を指定ã™ã‚‹ã€‚出ç¾å½¢ã¯ã‚¢ãƒ—リケーションãŒæ–‡æ›¸ã‚’å–å¾—ã—ãŸéš›ã«åˆ©ç”¨ã•ã‚Œã‚‹ã€‚
+
+ +

文書ã®IDã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `oddocid' を用ã„る。

+ +
+
int oddocid(const ODDOC *doc);
+
`doc' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ–‡æ›¸ã®ID番å·ã§ã‚る。
+
+ +

文書ã®URIã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `oddocuri' を用ã„る。

+ +
+
const char *oddocuri(const ODDOC *doc);
+
`doc' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ–‡æ›¸ã®URIã®æ–‡å­—列ã§ã‚る。
+
+ +

文書ã®å±žæ€§å€¤ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `oddocgetattr' を用ã„る。

+ +
+
const char *oddocgetattr(const ODDOC *doc, const char *name);
+
`doc' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`name' ã¯å±žæ€§åã®æ–‡å­—列を指定ã™ã‚‹ã€‚戻り値ã¯å±žæ€§å€¤ã®æ–‡å­—列ã§ã‚ã‚‹ã‹ã€è©²å½“ãŒãªã‘れ㰠`NULL' ã§ã‚る。
+
+ +

文書内ã®èªžç¾¤ã®æ­£è¦å½¢ã®ãƒªã‚¹ãƒˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `oddocnwords' を用ã„る。

+ +
+
const CBLIST *oddocnwords(const ODDOC *doc);
+
`doc' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£è¦å½¢ã®èªžç¾¤ã‚’æ ¼ç´ã—ãŸãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。
+
+ +

文書内ã®èªžç¾¤ã®å‡ºç¾å½¢ã®ãƒªã‚¹ãƒˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `oddocawords' を用ã„る。

+ +
+
const CBLIST *oddocawords(const ODDOC *doc);
+
`doc' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯å‡ºç¾å½¢ã®èªžç¾¤ã‚’æ ¼ç´ã—ãŸãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。
+
+ +

文書ã®ã‚­ãƒ¼ãƒ¯ãƒ¼ãƒ‰ã®æ­£è¦å½¢ã¨ãã®ã‚¹ã‚³ã‚¢ã®ãƒžãƒƒãƒ—ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `oddocscores' を用ã„る。

+ +
+
CBMAP *oddocscores(const ODDOC *doc, int max, ODEUM *odeum);
+
`doc' ã¯æ–‡æ›¸ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`max' ã¯å–å¾—ã™ã‚‹ã‚­ãƒ¼ãƒ¯ãƒ¼ãƒ‰ã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ã€‚`odeum' ㌠`NULL' ã§ãªã‘ã‚Œã°ã€ãれを用ã„ã¦é‡ã¿ã¥ã‘ã®ãŸã‚ã®IDFãŒç®—出ã•ã‚Œã‚‹ã€‚戻り値ã¯ã‚­ãƒ¼ãƒ¯ãƒ¼ãƒ‰ã¨ãã®ã‚¹ã‚³ã‚¢ã‚’æ ¼ç´ã—ãŸãƒžãƒƒãƒ—ãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。スコアã¯10進数ã®æ–‡å­—列ã§è¡¨ç¾ã•ã‚Œã‚‹ã€‚戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cbmapopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cbmapclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

テキストを分解ã—ã¦èªžç¾¤ã®å‡ºç¾å½¢ã®ãƒªã‚¹ãƒˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odbreaktext' を用ã„る。

+ +
+
CBLIST *odbreaktext(const char *text);
+
`text' ã¯ãƒ†ã‚­ã‚¹ãƒˆã®æ–‡å­—列を指定ã™ã‚‹ã€‚戻り値ã¯èªžç¾¤ã®å‡ºç¾å½¢ã®ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã§ã‚る。語群ã¯ç©ºç™½æ–‡å­—ã¨ãƒ”リオドやコンマ等ã®åŒºåˆ‡ã‚Šæ–‡å­—ã§åˆ†å‰²ã•ã‚Œã‚‹ã€‚戻り値ã®ãƒãƒ³ãƒ‰ãƒ«ã¯é–¢æ•° `cblistopen' ã§é–‹ã‹ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `cblistclose' ã§é–‰ã˜ã‚‹ã¹ãã§ã‚る。
+
+ +

語ã®æ­£è¦å½¢ã‚’å–å¾—ã™ã‚‹ã«ã¯ã€é–¢æ•° `odnormalizeword' を用ã„る。

+ +
+
char *odnormalizeword(const char *asis);
+
`asis' ã¯èªžã®å‡ºç¾å½¢ã®æ–‡å­—列を指定ã™ã‚‹ã€‚戻り値ã¯èªžã®æ­£è¦å½¢ã®æ–‡å­—列ã§ã‚る。ASCIIコードã®ã‚¢ãƒ«ãƒ•ã‚¡ãƒ™ãƒƒãƒˆã¯å°æ–‡å­—ã«çµ±ä¸€ã•ã‚Œã‚‹ã€‚区切り文字ã®ã¿ã‹ã‚‰ãªã‚‹æ–‡å­—ã¯ç©ºæ–‡å­—列ã¨ã—ã¦æ‰±ã‚れる。戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

二ã¤ã®æ–‡æ›¸é›†åˆã‹ã‚‰ãã®å…±é€šé›†åˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odpairsand' を用ã„る。

+ +
+
ODPAIR *odpairsand(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np);
+
`apairs' ã¯å‰è€…ã®æ–‡æ›¸é›†åˆã®é…列を指定ã™ã‚‹ã€‚`anum' ã¯å‰è€…ã®é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`apairs' ã¯å¾Œè€…ã®æ–‡æ›¸é›†åˆã®é…列を指定ã™ã‚‹ã€‚`anum' ã¯å¾Œè€…ã®é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`np' ã®å‚照先ã«ã¯ã€æˆ»ã‚Šå€¤ã®é…列ã®è¦ç´ æ•°ãŒæ ¼ç´ã•ã‚Œã‚‹ã€‚戻り値ã¯æ–°ã—ã„文書集åˆã®é…列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€å„è¦ç´ ã¯äºŒã¤ã®é›†åˆã«å…±é€šã—ã¦å±žã™ã‚‹ã‚‚ã®ã§ã‚る。å„è¦ç´ ã¯ã‚¹ã‚³ã‚¢ã®é™é †ã§ä¸¦ã¹ã‚‰ã‚Œã‚‹ã€‚戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

二ã¤ã®æ–‡æ›¸é›†åˆã‹ã‚‰ãã®å’Œé›†åˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odpairsor' を用ã„る。

+ +
+
ODPAIR *odpairsor(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np);
+
`apairs' ã¯å‰è€…ã®æ–‡æ›¸é›†åˆã®é…列を指定ã™ã‚‹ã€‚`anum' ã¯å‰è€…ã®é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`apairs' ã¯å¾Œè€…ã®æ–‡æ›¸é›†åˆã®é…列を指定ã™ã‚‹ã€‚`anum' ã¯å¾Œè€…ã®é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`np' ã®å‚照先ã«ã¯ã€æˆ»ã‚Šå€¤ã®é…列ã®è¦ç´ æ•°ãŒæ ¼ç´ã•ã‚Œã‚‹ã€‚戻り値ã¯æ–°ã—ã„文書集åˆã®é…列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€å„è¦ç´ ã¯äºŒã¤ã®é›†åˆã®ä¸¡æ–¹ã‚ã‚‹ã„ã¯ã©ã¡ã‚‰ã‹ä¸€æ–¹ã«å±žã™ã‚‹ã‚‚ã®ã§ã‚る。å„è¦ç´ ã¯ã‚¹ã‚³ã‚¢ã®é™é †ã§ä¸¦ã¹ã‚‰ã‚Œã‚‹ã€‚戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

二ã¤ã®æ–‡æ›¸é›†åˆã‹ã‚‰ãã®å·®é›†åˆã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odpairsnotand' を用ã„る。

+ +
+
ODPAIR *odpairsnotand(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np);
+
`apairs' ã¯å‰è€…ã®æ–‡æ›¸é›†åˆã®é…列を指定ã™ã‚‹ã€‚`anum' ã¯å‰è€…ã®é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`apairs' ã¯å¾Œè€…ã®æ–‡æ›¸é›†åˆã®é…列を指定ã™ã‚‹ã€‚`anum' ã¯å¾Œè€…ã®é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚`np' ã®å‚照先ã«ã¯ã€æˆ»ã‚Šå€¤ã®é…列ã®è¦ç´ æ•°ãŒæ ¼ç´ã•ã‚Œã‚‹ã€‚戻り値ã¯æ–°ã—ã„文書集åˆã®é…列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€å„è¦ç´ ã¯å‰è€…ã®é›†åˆã«ã¯å±žã™ã‚‹ãŒå¾Œè€…ã®é›†åˆã«ã¯å±žã•ãªã„ã‚‚ã®ã§ã‚る。å„è¦ç´ ã¯ã‚¹ã‚³ã‚¢ã®é™é †ã§ä¸¦ã¹ã‚‰ã‚Œã‚‹ã€‚戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。
+
+ +

文書集åˆã‚’スコアã®é™é †ã§ä¸¦ã¹ã‚‹ã«ã¯ã€é–¢æ•° `odpairssort' を用ã„る。

+ +
+
void odpairssort(ODPAIR *pairs, int pnum);
+
`pairs' ã¯æ–‡æ›¸é›†åˆã®é…列を指定ã™ã‚‹ã€‚`pnum' ã¯ãã®é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚
+
+ +

ã‚ã‚‹æ•°ã®è‡ªç„¶å¯¾æ•°ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odlogarithm' を用ã„る。

+ +
+
double odlogarithm(double x);
+
`x' ã¯ã‚る数を指定ã™ã‚‹ã€‚戻り値ã¯ãã®æ•°ã®è‡ªç„¶å¯¾æ•°ã§ã‚る。もã—ãã®æ•°ãŒ 1.0 以下ã§ã‚ã‚Œã°ã€æˆ»ã‚Šå€¤ã¯ 0.0 ã¨ãªã‚‹ã€‚ã“ã®é–¢æ•°ã¯ã‚¢ãƒ—リケーションãŒæ¤œç´¢çµæžœã®IDFを算出ã™ã‚‹éš›ã«ä¾¿åˆ©ã§ã‚る。
+
+ +

二ã¤ã®ãƒ™ã‚¯ãƒˆãƒ«ã®ãªã™è§’ã®ä½™å¼¦ã‚’å¾—ã‚‹ã«ã¯ã€é–¢æ•° `odvectorcosine' を用ã„る。

+ +
+
double odvectorcosine(const int *avec, const int *bvec, int vnum);
+
`avec' ã¯å‰è€…ã®æ•°å€¤é…列を指定ã™ã‚‹ã€‚`bvec' ã¯å¾Œè€…ã®æ•°å€¤é…列を指定ã™ã‚‹ã€‚`vnum' ã¯å„々ã®é…列ã®è¦ç´ æ•°ã‚’指定ã™ã‚‹ã€‚戻り値ã¯äºŒã¤ã®ãƒ™ã‚¯ãƒˆãƒ«ã®ãªã™è§’ã®ä½™å¼¦ã§ã‚る。ã“ã®é–¢æ•°ã¯ã‚¢ãƒ—リケーションãŒæ–‡æ›¸ã®é¡žä¼¼åº¦ã‚’算出ã™ã‚‹éš›ã«ä¾¿åˆ©ã§ã‚る。
+
+ +

性能を調整ã™ã‚‹å¤§åŸŸçš„ãªãƒ‘ラメータを指定ã™ã‚‹ã«ã¯ã€é–¢æ•° `odsettuning' を用ã„る。

+ +
+
void odsettuning(int ibnum, int idnum, int cbnum, int csiz);
+
`ibnum' ã¯è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®ãƒã‚±ãƒƒãƒˆæ•°ã‚’指定ã™ã‚‹ã€‚`idnum' ã¯è»¢ç½®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®åˆ†å‰²æ•°ã‚’指定ã™ã‚‹ã€‚`cbnum' ã¯ãƒ€ãƒ¼ãƒ†ã‚£ãƒãƒƒãƒ•ã‚¡ã®ãƒã‚±ãƒƒãƒˆæ•°ã‚’指定ã™ã‚‹ã€‚`csiz' ã¯ãƒ€ãƒ¼ãƒ†ã‚£ãƒãƒƒãƒ•ã‚¡ã«ä½¿ã†ãƒ¡ãƒ¢ãƒªã®æœ€å¤§ãƒã‚¤ãƒˆæ•°ã‚’指定ã™ã‚‹ã€‚デフォルトã®è¨­å®šã¯ `odsettuning(32749, 7, 262139, 8388608)' ã«ç›¸å½“ã™ã‚‹ã€‚ã“ã®é–¢æ•°ã¯ãƒãƒ³ãƒ‰ãƒ«ã‚’é–‹ãå‰ã«å‘¼ã³å‡ºã™ã¹ãã§ã‚る。
+
+ +

テキストを分解ã—ã¦å‡ºç¾å½¢ã¨æ­£è¦å½¢ã‚’別々ã®ãƒªã‚¹ãƒˆã«æ ¼ç´ã™ã‚‹ã«ã¯ã€é–¢æ•° `odanalyzetext' を用ã„る。

+ +
+
void odanalyzetext(ODEUM *odeum, const char *text, CBLIST *awords, CBLIST *nwords);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`text' ã¯ãƒ†ã‚­ã‚¹ãƒˆã®æ–‡å­—列を指定ã™ã‚‹ã€‚`awords' ã¯å‡ºç¾åž‹ã‚’æ ¼ç´ã™ã‚‹ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`nwords' ã¯æ­£è¦åž‹ã‚’æ ¼ç´ã™ã‚‹ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ãŒã€`NULL' ãªã‚‰ç„¡è¦–ã•ã‚Œã‚‹ã€‚語群ã¯ç©ºç™½æ–‡å­—ã¨ãƒ”リオドやコンマ等ã®åŒºåˆ‡ã‚Šæ–‡å­—ã§åˆ†å‰²ã•ã‚Œã‚‹ã€‚
+
+ +

関数 `odanalyzetext' ã§ä½¿ã‚れる文字ã®åˆ†é¡žã‚’設定ã™ã‚‹ã«ã¯ã€é–¢æ•° `odsetcharclass' を用ã„る。

+ +
+
void odsetcharclass(ODEUM *odeum, const char *spacechars, const char *delimchars, const char *gluechars);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`spachechars' ã¯ç©ºç™½æ–‡å­—ã‚’å«ã‚€æ–‡å­—列を指定ã™ã‚‹ã€‚`delimchars' ã¯åŒºåˆ‡ã‚Šæ–‡å­—ã‚’å«ã‚€æ–‡å­—列を指定ã™ã‚‹ã€‚`gluechars' ã¯æŽ¥ç€æ–‡å­—ã‚’å«ã‚€æ–‡å­—列を指定ã™ã‚‹ã€‚
+
+ +

å°ã•ãªå•ã„åˆã‚ã›è¨€èªžã‚’使ã£ã¦æ¤œç´¢ã‚’è¡Œã†ã«ã¯ã€é–¢æ•° `odquery' を用ã„る。

+ +
+
ODPAIR *odquery(ODEUM *odeum, const char *query, int *np, CBLIST *errors);
+
`odeum' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚`query' ã¯å•ã„åˆã‚ã›è¨€èªžã®æ–‡å­—列を指定ã™ã‚‹ã€‚`np' ã®å‚照先ã«ã¯ã€æˆ»ã‚Šå€¤ã®é…列ã®è¦ç´ æ•°ãŒæ ¼ç´ã•ã‚Œã‚‹ã€‚`error' ã¯ã‚¨ãƒ©ãƒ¼ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸ã‚’æ ¼ç´ã™ã‚‹ãƒªã‚¹ãƒˆãƒãƒ³ãƒ‰ãƒ«ã‚’指定ã™ã‚‹ã€‚戻り値ã¯æ­£å¸¸ãªã‚‰é…列ã¸ã®ãƒã‚¤ãƒ³ã‚¿ã§ã‚ã‚Šã€ã‚¨ãƒ©ãƒ¼ãªã‚‰ `NULL' ã§ã‚る。ãã®é…列ã®å„è¦ç´ ã¯æ–‡æ›¸ã®ID番å·ã¨ã‚¹ã‚³ã‚¢ã®ãƒšã‚¢ã§ã‚ã‚Šã€ã‚¹ã‚³ã‚¢ã®é™é †ã§ä¸¦ã¹ã‚‰ã‚Œã‚‹ã€‚検索語ã«è©²å½“ã™ã‚‹æ–‡æ›¸ãŒä¸€ã¤ã‚‚ãªã‹ã£ãŸã¨ã—ã¦ã‚‚エラーã«ã¯ãªã‚‰ãšã«ã€ç©ºã®é…列を返ã™ã€‚戻り値ã®é ˜åŸŸã¯ `malloc' ã§ç¢ºä¿ã•ã‚Œã‚‹ã®ã§ã€ä¸è¦ã«ãªã£ãŸã‚‰ `free' ã§è§£æ”¾ã™ã‚‹ã¹ãã§ã‚る。é…列ã®å„è¦ç´ ã«ã¯æ—¢ã«å‰Šé™¤ã•ã‚ŒãŸæ–‡æ›¸ã®ãƒ‡ãƒ¼ã‚¿ã‚‚å«ã¾ã‚Œã‚‹ã“ã¨ã«æ³¨æ„ã™ã¹ãã§ã‚る。
+
+ +

サンプルコード

+ +

文書をデータベースã«æ ¼ç´ã™ã‚‹ã‚µãƒ³ãƒ—ルコードを以下ã«ç¤ºã™ã€‚

+ +
#include <depot.h>
+#include <cabin.h>
+#include <odeum.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define DBNAME   "index"
+
+int main(int argc, char **argv){
+  ODEUM *odeum;
+  ODDOC *doc;
+  CBLIST *awords;
+  const char *asis;
+  char *normal;
+  int i;
+
+  /* データベースを開ã */
+  if(!(odeum = odopen(DBNAME, OD_OWRITER | OD_OCREAT))){
+    fprintf(stderr, "odopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* 文書ãƒãƒ³ãƒ‰ãƒ«ã‚’å–å¾—ã™ã‚‹ */
+  doc = oddocopen("http://www.foo.bar/baz.txt");
+
+  /* 文書ã®å±žæ€§ã‚’設定ã™ã‚‹ */
+  oddocaddattr(doc, "title", "Balcony Scene");
+  oddocaddattr(doc, "author", "Shakespeare");
+
+  /* テキストを分解ã—ã¦èªžã®ãƒªã‚¹ãƒˆã‚’å¾—ã‚‹ */
+  awords = odbreaktext("Parting is such sweet sorrow.");
+
+  /* å„語を文書ãƒãƒ³ãƒ‰ãƒ«ã«è¨­å®šã™ã‚‹ */
+  for(i = 0; i < cblistnum(awords); i++){
+    /* 語ã®ãƒªã‚¹ãƒˆã‹ã‚‰ä¸€èªžã‚’å–り出㙠*/
+    asis = cblistval(awords, i, NULL);
+    /* 出ç¾å½¢ã‹ã‚‰æ­£è¦å½¢ã‚’生æˆã™ã‚‹ */
+    normal = odnormalizeword(asis);
+    /* 語を文書ãƒãƒ³ãƒ‰ãƒ«ã«è¨­å®šã™ã‚‹ */
+    oddocaddword(doc, normal, asis);
+    /* æ­£è¦å½¢ã®é ˜åŸŸã‚’解放ã™ã‚‹ */
+    free(normal);
+  }
+
+  /* 文書をデータベースã«ç™»éŒ²ã™ã‚‹ */
+  if(!odput(odeum, doc, -1, 1)){
+    fprintf(stderr, "odput: %s\n", dperrmsg(dpecode));
+  }
+
+  /* 語ã®ãƒªã‚¹ãƒˆã‚’解放ã™ã‚‹ */
+  cblistclose(awords);
+
+  /* 文書ãƒãƒ³ãƒ‰ãƒ«ã‚’解放ã™ã‚‹ */
+  oddocclose(doc);
+
+  /* データベースを閉ã˜ã‚‹ */
+  if(!odclose(odeum)){
+    fprintf(stderr, "odclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

データベース内ã®æ–‡æ›¸ã‚’検索ã™ã‚‹ã‚µãƒ³ãƒ—ルコードを以下ã«ç¤ºã™ã€‚

+ +
#include <depot.h>
+#include <cabin.h>
+#include <odeum.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define DBNAME   "index"
+
+int main(int argc, char **argv){
+  ODEUM *odeum;
+  ODPAIR *pairs;
+  ODDOC *doc;
+  const CBLIST *words;
+  const char *title, *author, *asis;
+  int i, j, pnum;
+
+  /* データベースをå–å¾—ã™ã‚‹ */
+  if(!(odeum = odopen(DBNAME, OD_OREADER))){
+    fprintf(stderr, "odopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* 文書ã®æ¤œç´¢ã‚’行ㆠ*/
+  if((pairs = odsearch(odeum, "sorrow", -1, &pnum)) != NULL){
+
+    /* 文書ã®é…列を走査ã™ã‚‹ */
+    for(i = 0; i < pnum; i++){
+      /* 文書ãƒãƒ³ãƒ‰ãƒ«ã‚’å–å¾—ã™ã‚‹ */
+      if(!(doc = odgetbyid(odeum, pairs[i].id))) continue;
+      /* 文書ã®å±žæ€§ã‚’表示ã™ã‚‹ */
+      printf("URI: %s\n", oddocuri(doc));
+      title = oddocgetattr(doc, "title");
+      if(title) printf("TITLE: %s\n", title);
+      author = oddocgetattr(doc, "author");
+      if(author) printf("AUTHOR: %s\n", author);
+      /* 文書内ã®èªžã‚’出ç¾å½¢ã§è¡¨ç¤ºã™ã‚‹ */
+      printf("WORDS:");
+      words = oddocawords(doc);
+      for(j = 0; j < cblistnum(words); j++){
+        asis = cblistval(words, j, NULL);
+        printf(" %s", asis);
+      }
+      putchar('\n');
+      /* 文書ãƒãƒ³ãƒ‰ãƒ«ã‚’解放ã™ã‚‹ */
+      oddocclose(doc);
+    }
+
+    /* 文書ã®é…列を解放ã™ã‚‹ */
+    free(pairs);
+
+  } else {
+    fprintf(stderr, "odsearch: %s\n", dperrmsg(dpecode));
+  }
+
+  /* データベースを閉ã˜ã‚‹ */
+  if(!odclose(odeum)){
+    fprintf(stderr, "odclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

注記

+ +

Odeumを利用ã—ãŸãƒ—ログラムをビルドã™ã‚‹æ–¹æ³•ã¯ã€Depotã®å ´åˆã¨å…¨ãåŒã˜ã§ã‚る。

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

POSIXスレッドを有効ã«ã—ã¦QDBMをビルドã—ãŸå ´åˆã€å¤–部変数 `dpecode' ã¯ã‚¹ãƒ¬ãƒƒãƒ‰å›ºæœ‰ãƒ‡ãƒ¼ã‚¿ã¸ã®å‚ç…§ã¨ã—ã¦æ‰±ã‚ã‚Œã€Odeumã®å„関数ã¯ãƒªã‚¨ãƒ³ãƒˆãƒ©ãƒ³ãƒˆã«ãªã‚‹ã€‚ãã®å ´åˆã€ã‚¹ãƒ¬ãƒƒãƒ‰é–“ã§åŒæ™‚ã«åŒã˜ãƒãƒ³ãƒ‰ãƒ«ã«ã‚¢ã‚¯ã‚»ã‚¹ã—ãªã„é™ã‚Šã¯ã€å„関数ã¯ã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ã§ã‚る。ãŸã ã—ã€`errno' ã‚„ `malloc' ç­‰ãŒã‚¹ãƒ¬ãƒƒãƒ‰ã‚»ãƒ¼ãƒ•ãªå‡¦ç†ç³»ã§ã‚ã‚‹ã“ã¨ãŒå‰æã¨ãªã‚‹ã€‚

+ +

ZLIBを有効ã«ã—ã¦QDBMをビルドã—ãŸå ´åˆã€æ–‡æ›¸å±žæ€§ç”¨ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹å†…ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã¯åœ§ç¸®ã•ã‚Œã¦ä¿å­˜ã•ã‚Œã‚‹ã€‚ãã®å ´åˆã€ã‚µã‚¤ã‚ºãŒ30%以下ã«ãªã‚‹ã€‚ã—ãŸãŒã£ã¦ã€Odeumを利用ã™ã‚‹å ´åˆã¯ZLIBを有効ã«ã—ãŸæ–¹ãŒã‚ˆã„。ZLIBを有効ã«ã—ã¦ä½œæˆã—ãŸOdeumã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’ã€ZLIBを有効ã«ã—ã¦ã„ãªã„環境ã§åˆ©ç”¨ã™ã‚‹ã“ã¨ã¯ã§ããšã€ã¾ãŸãã®é€†ã‚‚åŒæ§˜ã§ã‚る。ZLIBãŒæœ‰åŠ¹ã§ãªãLZOãŒæœ‰åŠ¹ãªå ´åˆã¯ã€ZLIBã®å¤‰ã‚ã‚Šã«LZOãŒç”¨ã„られる。

+ +

å•ã„åˆã‚ã›è¨€èªž

+ +

関数 `odquery' ã®å•ã„åˆã‚ã›è¨€èªžã¯ä»¥ä¸‹ã®æ–‡æ³•ã«åŸºã¥ã。

+ +
expr ::= subexpr ( op subexpr )*
+subexpr ::= WORD
+subexpr ::= LPAREN expr RPAREN
+
+ +

演算å­ã¨ã—ã¦ã¯ "&"(AND)㨠"|"(OR)㨠"!"(NOTAND)ãŒåˆ©ç”¨ã§ãる。ã¾ãŸã€æ‹¬å¼§ "()" を使ã†ã“ã¨ã§æ¼”ç®—å­ã®è©•ä¾¡é †åºã‚’制御ã™ã‚‹ã“ã¨ãŒã§ãる。å•ã„åˆã‚ã›ã®æ–‡å­—列ã¯é–¢æ•° `odanalyzetext' を用ã„ã¦åˆ†è§£ã•ã‚Œã‚‹ã®ã§ã€"&"ã€"|"ã€"!"ã€"("ã€")" ã¯åŒºåˆ‡ã‚Šæ–‡å­—ã¨ã—ã¦è¨­å®šã•ã‚Œã¦ã„ã‚‹å¿…è¦ãŒã‚る。ã¾ãŸã€ç©ºç™½ã§å˜èªžã‚’区切ã£ã¦ã‚‚ "&" ã§åŒºåˆ‡ã£ãŸã®ã¨åŒã˜ã“ã¨ã«ãªã‚‹ã€‚ã¤ã¾ã‚Š "joe blow" 㯠"joe & blow" ã¨åŒã˜ã§ã‚る。

+ +

å•ã„åˆã‚ã›æ–‡å­—列ã®æ–‡å­—コードã¯å¯¾è±¡æ–‡æ›¸ã®æ–‡å­—コードã¨ä¸€è‡´ã—ã¦ã„ã‚‹å¿…è¦ãŒã‚る。ã¾ãŸã€ç©ºç™½æ–‡å­—ã¨åŒºåˆ‡ã‚Šæ–‡å­—ã¨æŽ¥ç€æ–‡å­—ã«æŒ‡å®šã§ãã‚‹ã®ã¯1ãƒã‚¤ãƒˆæ–‡å­—ã ã‘ã§ã‚る。

+ +
+ +

Odeum用コマンド

+ +

Odeumã«å¯¾å¿œã™ã‚‹ã‚³ãƒžãƒ³ãƒ‰ãƒ©ã‚¤ãƒ³ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ã¯ä»¥ä¸‹ã®ã‚‚ã®ã§ã‚る。

+ +

コマンド `odmgr' ã¯Odeumã‚„ãã®ã‚¢ãƒ—リケーションã®ãƒ‡ãƒãƒƒã‚°ã«å½¹ç«‹ã¤ãƒ„ールã§ã‚る。データベースを更新ã—ãŸã‚Šã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®çŠ¶æ…‹ã‚’調ã¹ãŸã‚Šã™ã‚‹æ©Ÿèƒ½ã‚’æŒã¤ã€‚シェルスクリプトã§å…¨æ–‡æ¤œç´¢ã‚·ã‚¹ãƒ†ãƒ ã‚’作るã®ã«ã‚‚利用ã§ãる。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`file' ã¯ãƒ•ã‚¡ã‚¤ãƒ«åã€`expr' ã¯æ–‡æ›¸ã®URIã‹ID番å·ã€`words' ã¯æ¤œç´¢èªžã€`elems' ã¯è¦ç´ ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’指定ã™ã‚‹ã€‚

+ +
+
odmgr create name
+
データベースファイルを作æˆã™ã‚‹ã€‚
+
odmgr put [-uri str] [-title str] [-author str] [-date str] [-wmax num] [-keep] name [file]
+
ファイルを読ã¿è¾¼ã‚“ã§æ–‡æ›¸ã‚’追加ã™ã‚‹ã€‚`file' ã‚’çœç•¥ã™ã‚‹ã¨æ¨™æº–入力を読ã¿è¾¼ã‚€ãŒã€ãã®å ´åˆã¯URIã®æŒ‡å®šãŒå¿…é ˆã¨ãªã‚‹ã€‚
+
odmgr out [-id] name expr
+
URIã«å¯¾å¿œã™ã‚‹æ–‡æ›¸ã‚’削除ã™ã‚‹ã€‚
+
odmgr get [-id] [-t|-h] name expr
+
URIã«å¯¾å¿œã™ã‚‹æ–‡æ›¸ã‚’表示ã™ã‚‹ã€‚出力ã¯æ–‡æ›¸ã®ID番å·ã¨URIã¨ã‚¹ã‚³ã‚¢ã‚’タブã§åŒºåˆ‡ã£ãŸã‚‚ã®ã§ã‚る。
+
odmgr search [-max num] [-or] [-idf] [-t|-h|-n] name words...
+
指定ã—ãŸèªžã‚’å«ã‚€æ–‡æ›¸ã‚’検索ã™ã‚‹ã€‚出力ã®ç¬¬1è¡Œã¯ã€æ¤œç´¢èªžå…¨ä½“ã®è©²å½“æ•°ã¨å„検索語ãŠã‚ˆã³ãã®è©²å½“数をタブã§åŒºåˆ‡ã£ãŸã‚‚ã®ã§ã‚る。第2行以é™ã¯ã€è©²å½“ã®å„文書ã®ID番å·ã¨URIã¨ã‚¹ã‚³ã‚¢ã‚’タブã§åŒºåˆ‡ã£ãŸã‚‚ã®ã§ã‚る。
+
odmgr list [-t|-h] name
+
データベース内ã®å…¨ã¦ã®æ–‡æ›¸ã‚’表示ã™ã‚‹ã€‚出力ã®å„è¡Œã¯æ–‡æ›¸ã®ID番å·ã¨URIã¨ã‚¹ã‚³ã‚¢ã‚’タブã§åŒºåˆ‡ã£ãŸã‚‚ã®ã§ã‚る。
+
odmgr optimize name
+
データベースを最é©åŒ–ã™ã‚‹ã€‚
+
odmgr inform name
+
データベースã®é›‘多ãªæƒ…報を出力ã™ã‚‹ã€‚
+
odmgr merge name elems...
+
複数ã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’マージã™ã‚‹ã€‚
+
odmgr remove name
+
データベースディレクトリを削除ã™ã‚‹ã€‚
+
odmgr break [-h|-k|-s] [file]
+
ファイルを読ã¿è¾¼ã‚“ã§ã€ãƒ†ã‚­ã‚¹ãƒˆã‚’語ã«åˆ†è§£ã—ã¦å‡ºåŠ›ã™ã‚‹ã€‚出力ã®å„è¡Œã¯å„語ã®æ­£è¦å½¢ã¨å‡ºç¾å½¢ã‚’タブã§åŒºåˆ‡ã£ãŸã‚‚ã®ã§ã‚る。
+
odmgr version
+
QDBMã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³æƒ…報を出力ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -uri str : 文書ã®URIを明示的ã«æŒ‡å®šã™ã‚‹ã€‚
  • +
  • -title str : 文書ã®ã‚¿ã‚¤ãƒˆãƒ«ã‚’指定ã™ã‚‹ã€‚
  • +
  • -author str : 文書ã®è‘—者åを指定ã™ã‚‹ã€‚
  • +
  • -date str : 文書ã®æ›´æ–°æ—¥æ™‚を指定ã™ã‚‹ã€‚
  • +
  • -wmax num : æ ¼ç´ã™ã‚‹èªžã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ã€‚
  • +
  • -keep : åŒã˜URIã®æ–‡æ›¸ãŒæ—¢å­˜ã§ã‚ã‚Œã°ä¸Šæ›¸ãã‚’è¡Œã‚ãªã„。
  • +
  • -id : URIã§ãªãID番å·ã§æ–‡æ›¸ã‚’指定ã™ã‚‹ã€‚
  • +
  • -t : 文書ã®è©³ç´°æƒ…報をタブ区切りã§å‡ºåŠ›ã™ã‚‹ã€‚
  • +
  • -h : 文書ã®è©³ç´°æƒ…報を人間ãŒèª­ã¿ã‚„ã™ã„å½¢å¼ã§å‡ºåŠ›ã™ã‚‹ã€‚
  • +
  • -k : 文書ã®ã‚­ãƒ¼ãƒ¯ãƒ¼ãƒ‰ã®ã¿ã‚’出力ã™ã‚‹ã€‚
  • +
  • -s : 文書ã®è¦ç´„ã®ã¿ã‚’出力ã™ã‚‹ã€‚
  • +
  • -max num : 出力ã™ã‚‹æ–‡æ›¸ã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ã€‚
  • +
  • -or : AND検索ã§ãªãOR検索を行ã†ã€‚
  • +
  • -idf : IDFã§ã‚¹ã‚³ã‚¢ã‚’é‡ã¿ã¥ã‘ã™ã‚‹ã€‚
  • +
  • -n : 文書ã®IDã¨ã‚¹ã‚³ã‚¢ã®ã¿ã‚’表示ã™ã‚‹ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚環境変数 `QDBMDBGFD' ã®å€¤ã¨ã—ã¦ã€å¤‰æ•° `dpecode' ã®å¤‰æ›´å±¥æ­´ã‚’出力ã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—タを指定ã“ã¨ãŒã§ãる。

+ +

コマンド `odtest' ã¯Odeumã®æ©Ÿèƒ½ãƒ†ã‚¹ãƒˆã‚„性能テストã«ç”¨ã„るツールã§ã‚る。ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã«ã‚ˆã£ã¦ç”Ÿæˆã•ã‚ŒãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’ `odmgr' ã«ã‚ˆã£ã¦è§£æžã—ãŸã‚Šã€`time' コマンドã«ã‚ˆã£ã¦ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã®å®Ÿè¡Œæ™‚間を計ã£ãŸã‚Šã™ã‚‹ã¨ã‚ˆã„。以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`dnum' ã¯æ–‡æ›¸æ•°ã€`wnum' ã¯æ–‡æ›¸æ¯Žã®èªžæ•°ã€`pnum' ã¯èªžã®ãƒ‘ターン数を指定ã™ã‚‹ã€‚

+ +
+
odtest write [-tune ibnum idnum cbnum csiz] name dnum wnum pnum
+
無作為ãªå±žæ€§ã¨èªžã‚’æŒã¤æ–‡æ›¸ã‚’連続ã—ã¦ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«è¿½åŠ ã™ã‚‹ã€‚
+
odtest read name
+
上記ã§ç”Ÿæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å…¨æ–‡æ›¸ã‚’検索ã™ã‚‹ã€‚
+
odtest combo name
+
å„種æ“作ã®çµ„ã¿åˆã‚ã›ãƒ†ã‚¹ãƒˆã‚’è¡Œã†ã€‚
+
odtest wicked name dnum
+
å„種更新æ“作を無作為ã«é¸æŠžã—ã¦å®Ÿè¡Œã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -tune ibnum idnum cbnum csiz : 性能パラメータを指定ã™ã‚‹ã€‚
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚環境変数 `QDBMDBGFD' ã®å€¤ã¨ã—ã¦ã€å¤‰æ•° `dpecode' ã®å¤‰æ›´å±¥æ­´ã‚’出力ã™ã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ãƒ‡ã‚£ã‚¹ã‚¯ãƒªãƒ—タを指定ã“ã¨ãŒã§ãる。

+ +

コマンド `odidx' ã¯ãƒ­ãƒ¼ã‚«ãƒ«ãƒ•ã‚¡ã‚¤ãƒ«ã‚·ã‚¹ãƒ†ãƒ ä¸Šã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚’読ã¿è¾¼ã‚“ã§Odeumã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ç™»éŒ²ã™ã‚‹ãƒ¦ãƒ¼ãƒ†ã‚£ãƒªãƒ†ã‚£ã§ã‚る。ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯Webサイトã®å…¨æ–‡æ¤œç´¢ã‚·ã‚¹ãƒ†ãƒ ã‚’構築ã™ã‚‹éš›ã«å½¹ç«‹ã¤ã€‚サãƒãƒ¼ãƒˆã•ã‚Œã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆã¯ãƒ—レーンテキストã¨HTMLã§ã‚る。サãƒãƒ¼ãƒˆã•ã‚Œã‚‹æ–‡å­—コードã¯US-ASCIIã¨ISO-8859-1ã§ã‚る。å„文書ã®URIã«ã¯ãƒ•ã‚¡ã‚¤ãƒ«ã®ãƒ‘スãŒæŒ‡å®šã•ã‚Œã‚‹ã€‚å„文書ã«ã¯ã€`title' 㨠`date' ã¨ã„ã†å±žæ€§ãŒä»˜ä¸Žã•ã‚Œã‚‹ã€‚æ—¢ã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ç™»éŒ²ã—ã¦ã‚るファイルを登録ã—よã†ã¨ã—ãŸå ´åˆã€æ›´æ–°æ™‚刻ãŒæ–°ã—ã‘ã‚Œã°ç™»éŒ²ã•ã‚Œã€ãã†ã§ãªã‘ã‚Œã°ç„¡è¦–ã•ã‚Œã‚‹ã€‚更新時刻ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®ä¸­ã® '_mtime' ã¨ã„ã†ã‚µãƒ–データベースã«è¨˜éŒ²ã•ã‚Œã‚‹ã€‚スコア情報ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®ä¸­ã® `_score' ã¨ã„ã†ã‚µãƒ–データベースã«è¨˜éŒ²ã•ã‚Œã‚‹ã€‚以下ã®æ›¸å¼ã§ç”¨ã„る。`name' ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹åã€`dir' ã¯ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªåを指定ã™ã‚‹ã€‚

+ +
+
odidx register [-l file] [-wmax num] [-tsuf sufs] [-hsuf sufs] name [dir]
+
特定ã®ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªä»¥ä¸‹ã®ãƒ•ã‚¡ã‚¤ãƒ«ç¾¤ã‚’データベース登録ã™ã‚‹ã€‚`dir' ãŒçœç•¥ã•ã‚ŒãŸå ´åˆã€ã‚«ãƒ¬ãƒ³ãƒˆãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªãŒæŒ‡å®šã•ã‚Œã‚‹ã€‚
+
odidx relate name
+
データベースã®å„文書ã«é–¢é€£æ–‡æ›¸æ¤œç´¢ã®ãŸã‚ã®ã‚¹ã‚³ã‚¢æƒ…報を付加ã™ã‚‹ã€‚
+
odidx purge name
+
ファイルシステムã«å­˜åœ¨ã—ãªã„文書をデータベースã‹ã‚‰å‰Šé™¤ã™ã‚‹ã€‚
+
+ +

å„オプションã¯ä»¥ä¸‹ã®æ©Ÿèƒ½ã‚’æŒã¤ã€‚

+ +
    +
  • -l file : 登録ã™ã¹ãファイルã®ãƒ‘スã®ãƒªã‚¹ãƒˆã‚’ファイルã‹ã‚‰èª­ã¿è¾¼ã‚€ã€‚`-' を指定ã—ãŸå ´åˆã€æ¨™æº–入力ãŒèª­ã¿è¾¼ã¾ã‚Œã‚‹ã€‚
  • +
  • -wmax num : データベースã«æ ¼ç´ã™ã‚‹èªžã®æœ€å¤§æ•°ã‚’指定ã™ã‚‹ã€‚
  • +
  • -tsuf sufs : プレーンテキストファイルã®æ‹¡å¼µå­ã‚’カンマ区切りã§æŒ‡å®šã™ã‚‹ã€‚デフォルト㯠`-tsuf .txt,.text' ã¨åŒæ„ã§ã‚る。
  • +
  • -hsuf sufs : HTMLファイルã®æ‹¡å¼µå­ã‚’カンマ区切りã§æŒ‡å®šã™ã‚‹ã€‚デフォルト㯠`-hsuf .html,.htm' ã¨åŒæ„ã§ã‚る。
  • +
+ +

ã“ã®ã‚³ãƒžãƒ³ãƒ‰ã¯å‡¦ç†ãŒæ­£å¸¸ã«çµ‚了ã™ã‚Œã° 0 ã‚’è¿”ã—ã€ã‚¨ãƒ©ãƒ¼ãŒã‚ã‚Œã°ãれ以外ã®å€¤ã‚’è¿”ã—ã¦çµ‚了ã™ã‚‹ã€‚

+ +

Odeumã®ã‚³ãƒžãƒ³ãƒ‰ç¾¤ã‚’駆使ã™ã‚‹ã¨ã€å…¨æ–‡æ¤œç´¢ã‚·ã‚¹ãƒ†ãƒ ã‚’ç°¡å˜ã«å®Ÿç¾ã™ã‚‹ã“ã¨ãŒã§ãる。例ãˆã° `/home/mikio' 以下ã«ã‚ã‚Šã€ã‹ã¤ `.txt' ã‹ `.c' ã‹ `.h' ã¨ã„ã†æŽ¥å°¾è¾žã‚’æŒã¤ãƒ•ã‚¡ã‚¤ãƒ«ç¾¤ã‚’ `casket' ã¨ã„ã†åå‰ã®ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã«ç™»éŒ²ã™ã‚‹ãªã‚‰ã€ä»¥ä¸‹ã®ã‚ˆã†ã«ã™ã‚‹ã€‚

+ +
odidx register -tsuf ".txt,.c,.h" -hsuf "" casket /home/mikio
+
+ +

ãã—ã¦ã€`unix' ãŠã‚ˆã³ `posix' ã¨ã„ã†èªžã‚’å«ã‚€æ–‡æ›¸ã‚’検索ã—ã€ä¸Šä½8件を表示ã™ã‚‹ã«ã¯ã€ä»¥ä¸‹ã®ã‚ˆã†ã«ã™ã‚‹ã€‚

+ +
odmgr search -max 8 -h casket "unix posix"
+
+ +

`odidx' ã§ç”Ÿæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¯ã€QDBMã«ä»˜éŒ²ã•ã‚Œã‚‹å…¨æ–‡æ¤œç´¢ã®ãŸã‚ã®CGIスクリプト `qfts.cgi' ã§ãã®ã¾ã¾åˆ©ç”¨ã™ã‚‹ã“ã¨ãŒã§ãる。

+ +
+ +

ファイルフォーマット

+ +

Depotã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆ

+ +

DepotãŒç®¡ç†ã™ã‚‹ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®å†…容ã¯ã€ãƒ˜ãƒƒãƒ€éƒ¨ã€ãƒã‚±ãƒƒãƒˆéƒ¨ã€ãƒ¬ã‚³ãƒ¼ãƒ‰éƒ¨ã®ä¸‰ã¤ã«å¤§åˆ¥ã•ã‚Œã‚‹ã€‚

+ +

ヘッダ部ã¯ãƒ•ã‚¡ã‚¤ãƒ«ã®å…ˆé ­ã‹ã‚‰ 48 ãƒã‚¤ãƒˆã®å›ºå®šé•·ã§ã¨ã‚‰ã‚Œã€ä»¥ä¸‹ã®æƒ…å ±ãŒè¨˜éŒ²ã•ã‚Œã‚‹ã€‚

+ +
    +
  1. マジックナンム: オフセット 0 ã‹ã‚‰å§‹ã¾ã‚‹ã€‚ビッグエンディアン用ãªã‚‰æ–‡å­—列 "[DEPOT]\n\f" を内容ã¨ã—ã€ãƒªãƒˆãƒ«ã‚¨ãƒ³ãƒ‡ã‚£ã‚¢ãƒ³ç”¨ãªã‚‰æ–‡å­—列 "[depot]\n\f" を内容ã¨ã™ã‚‹ã€‚
  2. +
  3. ãƒãƒ¼ã‚¸ãƒ§ãƒ³ç•ªå· : オフセット 12 ã‹ã‚‰å§‹ã¾ã‚‹ã€‚ライブラリã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ç•ªå·ã‚’10進数ã§è¡¨ç¾ã—ãŸæ–‡å­—列を内容ã¨ã™ã‚‹ã€‚
  4. +
  5. ラッパー用フラグ : オフセット 16 ã‹ã‚‰å§‹ã¾ã‚‹ã€‚`int' åž‹ã®æ•´æ•°ã§ã‚る。
  6. +
  7. ファイルサイズ : オフセット 24 ã‹ã‚‰å§‹ã¾ã‚‹ã€‚`int' åž‹ã®æ•´æ•°ã§ã‚る。
  8. +
  9. ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•° : オフセット 32 ã‹ã‚‰å§‹ã¾ã‚‹ã€‚`int' åž‹ã®æ•´æ•°ã§ã‚る。
  10. +
  11. レコード数 : オフセット 40 ã‹ã‚‰å§‹ã¾ã‚‹ã€‚`int' åž‹ã®æ•´æ•°ã§ã‚る。
  12. +
+ +

ãƒã‚±ãƒƒãƒˆéƒ¨ã¯ãƒ˜ãƒƒãƒ€éƒ¨ã®ç›´å¾Œã«ãƒã‚±ãƒƒãƒˆé…列ã®è¦ç´ æ•°ã«å¿œã˜ãŸå¤§ãã•ã§ã¨ã‚‰ã‚Œã€ãƒã‚§ãƒ¼ãƒ³ã®å…ˆé ­è¦ç´ ã®ã‚ªãƒ•ã‚»ãƒƒãƒˆãŒå„è¦ç´ ã«è¨˜éŒ²ã•ã‚Œã‚‹ã€‚

+ +

レコード部ã¯ãƒã‚±ãƒƒãƒˆéƒ¨ã®ç›´å¾Œã‹ã‚‰ãƒ•ã‚¡ã‚¤ãƒ«ã®æœ«å°¾ã¾ã§ã‚’å ã‚ã€å„レコードã®ä»¥ä¸‹ã®æƒ…報をæŒã¤è¦ç´ ãŒè¨˜éŒ²ã•ã‚Œã‚‹ã€‚

+ +
    +
  1. フラグ : `int' åž‹ã®æ•´æ•°ã§ã‚る。
  2. +
  3. キーã®ç¬¬äºŒãƒãƒƒã‚·ãƒ¥å€¤ : `int' åž‹ã®æ•´æ•°ã§ã‚る。
  4. +
  5. キーã®ã‚µã‚¤ã‚º : `int' åž‹ã®æ•´æ•°ã§ã‚る。
  6. +
  7. 値ã®ã‚µã‚¤ã‚º : `int' åž‹ã®æ•´æ•°ã§ã‚る。
  8. +
  9. パディングã®ã‚µã‚¤ã‚º : `int' åž‹ã®æ•´æ•°ã§ã‚る。
  10. +
  11. å·¦ã®å­ã®ä½ç½® : `int' åž‹ã®æ•´æ•°ã§ã‚る。
  12. +
  13. å³ã®å­ã®ä½ç½® : `int' åž‹ã®æ•´æ•°ã§ã‚る。
  14. +
  15. キーã®å®Ÿãƒ‡ãƒ¼ã‚¿ : キーã®ã‚µã‚¤ã‚ºã§å®šç¾©ã•ã‚Œã‚‹é•·ã•ã‚’æŒã¤ä¸€é€£ã®ãƒã‚¤ãƒˆã§ã‚る。
  16. +
  17. 値ã®å®Ÿãƒ‡ãƒ¼ã‚¿ : 値ã®ã‚µã‚¤ã‚ºã§å®šç¾©ã•ã‚Œã‚‹é•·ã•ã‚’æŒã¤ä¸€é€£ã®ãƒã‚¤ãƒˆã§ã‚る。
  18. +
  19. パディング : 値ã®ã‚µã‚¤ã‚ºã¨ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã«ã‚ˆã‚Šç®—出ã•ã‚Œã‚‹é•·ã•ã‚’æŒã¤ä¸€é€£ã®ãƒã‚¤ãƒˆã§ã‚る。
  20. +
+ +

Villaã®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆ

+ +

Villaã®æ‰±ã†å…¨ã¦ã®ãƒ‡ãƒ¼ã‚¿ã¯Depotã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«è¨˜éŒ²ã•ã‚Œã‚‹ã€‚記録ã•ã‚Œã‚‹ãƒ‡ãƒ¼ã‚¿ã¯ã€ãƒ¡ã‚¿ãƒ‡ãƒ¼ã‚¿ã¨è«–ç†ãƒšãƒ¼ã‚¸ã«åˆ†é¡žã•ã‚Œã‚‹ã€‚è«–ç†ãƒšãƒ¼ã‚¸ã¯ãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã¨éžãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã«åˆ†é¡žã•ã‚Œã‚‹ã€‚メタデータã¯ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ç­‰ã®ç®¡ç†æƒ…報を記録ã™ã‚‹ã‚‚ã®ã§ã€ã‚­ãƒ¼ã¨å€¤ã¨ã‚‚ã« `int' åž‹ã§ã‚る。リーフノードã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’ä¿æŒã™ã‚‹ã€‚éžãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã¯ãƒšãƒ¼ã‚¸ã‚’å‚ç…§ã™ã‚‹ç–Žã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’ä¿æŒã™ã‚‹ã€‚

+ +

Villaã¯ã€å°ã•ã„自然数を直列化ã—ã¦æ‰±ã†éš›ã«è¨˜æ†¶é ˜åŸŸã‚’節約ã™ã‚‹ãŸã‚ã«ã€å¯å¤‰é•·æ•´æ•°ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆï¼ˆBER圧縮)を用ã„る。å¯å¤‰é•·æ•´æ•°ã®ã‚ªãƒ–ジェクトã¯ã€é ˜åŸŸã®å…ˆé ­ã‹ã‚‰è§£æžã—ã€å€¤ãŒæ­£ã®ãƒã‚¤ãƒˆã‚’読んã ã‚‰ãã“ã§çµ‚端ã¨ã™ã‚‹ã€‚å„ãƒã‚¤ãƒˆã¯çµ¶å¯¾å€¤ã§è©•ä¾¡ã•ã‚Œã€ãƒªãƒˆãƒ«ã‚¨ãƒ³ãƒ‡ã‚£ã‚¢ãƒ³ã®128進数ã¨ã—ã¦ç®—出ã•ã‚Œã‚‹ã€‚

+ +

レコードã¯ãƒ¦ãƒ¼ã‚¶ãƒ‡ãƒ¼ã‚¿ã®è«–ç†çš„ãªå˜ä½ã§ã‚る。キーãŒé‡è¤‡ã™ã‚‹è«–ç†ãƒ¬ã‚³ãƒ¼ãƒ‰ã¯ç‰©ç†çš„ã«ã¯å˜ä¸€ã®ãƒ¬ã‚³ãƒ¼ãƒ‰ã«ã¾ã¨ã‚られる。物ç†ãƒ¬ã‚³ãƒ¼ãƒ‰ã¯ä»¥ä¸‹ã®å½¢å¼ã§ç›´åˆ—化ã•ã‚Œã‚‹ã€‚

+ +
    +
  1. キーã®ã‚µã‚¤ã‚º : å¯å¤‰é•·æ•´æ•°åž‹ã§ã‚る。
  2. +
  3. キーã®å®Ÿãƒ‡ãƒ¼ã‚¿ : キーã®ã‚µã‚¤ã‚ºã§å®šç¾©ã•ã‚Œã‚‹é•·ã•ã‚’æŒã¤ä¸€é€£ã®ãƒã‚¤ãƒˆã§ã‚る。
  4. +
  5. 値ã®æ•° : å¯å¤‰é•·æ•´æ•°åž‹ã§ã‚る。
  6. +
  7. 値ã®ãƒªã‚¹ãƒˆ : 以下ã®è¡¨ç¾ã‚’値ã®æ•°ã ã‘ç¹°ã‚Šè¿”ã—ãŸä¸€é€£ã®ãƒã‚¤ãƒˆã§ã‚る。
      +
    1. サイズ : å¯å¤‰é•·æ•´æ•°åž‹ã§ã‚る。
    2. +
    3. 実データ : サイズã§å®šç¾©ã•ã‚Œã‚‹é•·ã•ã‚’æŒã¤ä¸€é€£ã®ãƒã‚¤ãƒˆã§ã‚る。
    4. +
  8. +
+ +

リーフノードã¯ãƒ¬ã‚³ãƒ¼ãƒ‰ã®é›†åˆã‚’æ ¼ç´ã™ã‚‹ãŸã‚ã®ç‰©ç†çš„ãªå˜ä½ã§ã‚る。リーフノード㯠`int' åž‹ã®IDをキーã¨ã—ã€ä»¥ä¸‹ã®å€¤ã‚’æŒã¤ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã—ã¦Depotã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã•ã‚Œã‚‹ã€‚レコードã¯å¸¸ã«ã‚­ãƒ¼ã®æ˜‡é †ã«æ•´åˆ—ã—ãŸçŠ¶æ…‹ã§ä¿æŒã•ã‚Œã‚‹ã€‚

+ +
    +
  1. å‰ã®ãƒªãƒ¼ãƒ•ã®ID : å¯å¤‰é•·æ•´æ•°åž‹ã§ã‚る。
  2. +
  3. 次ã®ãƒªãƒ¼ãƒ•ã®ID : å¯å¤‰é•·æ•´æ•°åž‹ã§ã‚る。
  4. +
  5. レコードã®ãƒªã‚¹ãƒˆ : 直列化ã—ãŸãƒ¬ã‚³ãƒ¼ãƒ‰ã‚’連çµã—ãŸã‚‚ã®ã€‚
  6. +
+ +

インデックスã¯ãƒšãƒ¼ã‚¸ã‚’探索ã™ã‚‹ãŸã‚ã®ãƒã‚¤ãƒ³ã‚¿ã®è«–ç†çš„ãªå˜ä½ã§ã‚る。インデックスã¯ä»¥ä¸‹ã®å½¢å¼ã§ç›´åˆ—化ã•ã‚Œã‚‹ã€‚

+ +
    +
  1. å‚照先ã®ãƒšãƒ¼ã‚¸ã®ID : å¯å¤‰é•·æ•´æ•°åž‹ã§ã‚る。
  2. +
  3. キーã®ã‚µã‚¤ã‚º : å¯å¤‰é•·æ•´æ•°åž‹ã§ã‚る。
  4. +
  5. キーã®å®Ÿãƒ‡ãƒ¼ã‚¿ : キーã®ã‚µã‚¤ã‚ºã§å®šç¾©ã•ã‚Œã‚‹é•·ã•ã‚’æŒã¤ä¸€é€£ã®ãƒã‚¤ãƒˆã§ã‚る。
  6. +
+ +

éžãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã¯ã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã®é›†åˆã‚’æ ¼ç´ã™ã‚‹ãŸã‚ã®ç‰©ç†çš„ãªå˜ä½ã§ã‚る。éžãƒªãƒ¼ãƒ•ãƒŽãƒ¼ãƒ‰ã¯ `int' åž‹ã®IDをキーã¨ã—ã€ä»¥ä¸‹ã®å€¤ã‚’æŒã¤ãƒ¬ã‚³ãƒ¼ãƒ‰ã¨ã—ã¦Depotã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«æ ¼ç´ã•ã‚Œã‚‹ã€‚インデックスã¯å¸¸ã«ã‚­ãƒ¼ã®æ˜‡é †ã«æ•´åˆ—ã—ãŸçŠ¶æ…‹ã§ä¿æŒã•ã‚Œã‚‹ã€‚

+ +
    +
  1. 最åˆã®å­ãƒŽãƒ¼ãƒ‰ã®ID : å¯å¤‰é•·æ•´æ•°åž‹ã§ã‚る。
  2. +
  3. インデックスã®ãƒªã‚¹ãƒˆ : 直列化ã—ãŸã‚¤ãƒ³ãƒ‡ãƒƒã‚¯ã‚¹ã‚’連çµã—ãŸã‚‚ã®ã€‚
  4. +
+ +

注記

+ +

データベースファイルã¯ã‚¹ãƒ‘ースã§ã¯ãªã„ã®ã§ã€é€šå¸¸ã®ãƒ•ã‚¡ã‚¤ãƒ«ã¨åŒæ§˜ã«è¤‡è£½ç­‰ã®æ“作を行ã†ã“ã¨ãŒã§ãる。Depotã¯ãƒã‚¤ãƒˆã‚ªãƒ¼ãƒ€ã®èª¿æ•´ã‚’ã—ãªã„ã§ãƒ•ã‚¡ã‚¤ãƒ«ã®èª­ã¿æ›¸ãã‚’è¡Œã£ã¦ã„ã‚‹ã®ã§ã€ãƒã‚¤ãƒˆã‚ªãƒ¼ãƒ€ã®ç•°ãªã‚‹ç’°å¢ƒã«ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’移設ã—ã¦ã‚‚ãã®ã¾ã¾ã§ã¯åˆ©ç”¨ã§ããªã„。

+ +

Depotã‚„Villaã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã‚’ãƒãƒƒãƒˆãƒ¯ãƒ¼ã‚¯ã§é…布ã™ã‚‹éš›ã«ã¯ã€MIMEタイプを `application/x-qdbm' ã«ã—ã¦ã»ã—ã„。ファイルåã®æŽ¥å°¾è¾žã¯ `.qdb' ã«ã—ã¦ã»ã—ã„。Curiaã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’ãƒãƒƒãƒˆãƒ¯ãƒ¼ã‚¯ã§é…布ã™ã‚‹éš›ã«ã¯ã€TARå½¢å¼ç­‰ã‚’用ã„ãŸã‚¢ãƒ¼ã‚«ã‚¤ãƒ–ã«å¤‰æ›ã—ã¦è¡Œã†ã“ã¨ãŒã§ãる。

+ +

データベースファイルã®ãƒžã‚¸ãƒƒã‚¯ãƒŠãƒ³ãƒã‚’ `file' コマンドã«è­˜åˆ¥ã•ã›ãŸã„å ´åˆã¯ã€`magic' ファイルã«ä»¥ä¸‹ã®è¡Œã‚’追記ã™ã‚‹ã¨ã‚ˆã„。

+ +
0       string          [DEPOT]\n\f     QDBM, big endian
+>12     string          x               \b, version=%s
+>19     byte            ^1              \b, Hash
+>19     byte            &1              \b, B+ tree
+>19     byte            &2              \b (deflated:ZLIB)
+>19     byte            &4              \b (deflated:LZO)
+>19     byte            &8              \b (deflated:BZIP2)
+>24     belong          x               \b, filesize=%d
+>32     belong          x               \b, buckets=%d
+>40     belong          x               \b, records=%d
+0       string          [depot]\n\f     QDBM, little endian
+>12     string          x               \b, version=%s
+>16     byte            ^1              \b, Hash
+>16     byte            &1              \b, B+ tree
+>16     byte            &2              \b (deflated:ZLIB)
+>16     byte            &4              \b (deflated:LZO)
+>16     byte            &8              \b (deflated:BZIP2)
+>24     lelong          x               \b, filesize=%d
+>32     lelong          x               \b, buckets=%d
+>40     lelong          x               \b, records=%d
+
+ +
+ +

移æ¤æ–¹æ³•

+ +

QDBMã¯POSIX互æ›ã®å…¨ã¦ã®ãƒ—ラットフォームã§å‹•ä½œã™ã‚‹ã“ã¨ã‚’目標ã¨ã—ã¦ã„る。ãŸã ã—ã€ã„ãã¤ã‹ã®APIãŒå®Ÿè£…ã•ã‚Œã¦ã„ãªã„プラットフォームã§ã‚‚動作ã™ã‚‹ã“ã¨ãŒæœ›ã¾ã—ã„。ã¾ãŸã€GCC以外ã®ã‚³ãƒ³ãƒ‘イラを利用ã—ã¦ã‚‚ビルドãŒã§ãã‚‹ã“ã¨ãŒæœ›ã¾ã—ã„。様々ãªãƒ—ラットフォームã¸ã®ç§»æ¤ä½œæ¥­ã¯ã€æ–°ã—ã„ `Makefile' を追加ã—ãŸã‚Šã‚½ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ä¸€éƒ¨ã‚’修正ã—ãŸã‚Šã™ã‚‹ã“ã¨ã«ã‚ˆã£ã¦ãªã•ã‚Œã‚‹ã€‚C言語ã®APIã§ã‚ã‚Œã°ã€ãŠãらã以下ã®ãƒ•ã‚¡ã‚¤ãƒ«ã®ã„ãã¤ã‹ã‚’修正ã™ã‚‹ã“ã¨ã«ãªã‚‹ã€‚ã‚‚ã—ãã¯ãれらを基ã«æ–°ã—ã„ファイルを作ã£ã¦ã‚‚よã„。

+ +
    +
  • Makefile.in : `./configure' ã«åˆ©ç”¨ã•ã‚Œã€`Makefile' ã®ãƒ™ãƒ¼ã‚¹ã¨ãªã‚‹ã€‚
  • +
  • myconf.h : システムä¾å­˜ã®è¨­å®šãƒ•ã‚¡ã‚¤ãƒ«ã€‚
  • +
  • depot.h : 基本APIã®ãƒ˜ãƒƒãƒ€ã€‚
  • +
  • curia.h : æ‹¡å¼µAPIã®ãƒ˜ãƒƒãƒ€ã€‚
  • +
  • relic.h : NDBM互æ›APIã®ãƒ˜ãƒƒãƒ€ã€‚
  • +
  • hovel.h : GDBM互æ›APIã®ãƒ˜ãƒƒãƒ€ã€‚
  • +
  • cabin.h : ユーティリティAPIã®ãƒ˜ãƒƒãƒ€ã€‚
  • +
  • villa.h : 上級APIã®ãƒ˜ãƒƒãƒ€ã€‚
  • +
  • vista.h : 拡張上級APIã®ãƒ˜ãƒƒãƒ€ã€‚
  • +
  • odeum.h : 転置APIã®ãƒ˜ãƒƒãƒ€ã€‚
  • +
  • myconf.c : システムä¾å­˜ã®å®Ÿè£…。
  • +
  • depot.c : 基本APIã®å®Ÿè£…。
  • +
  • curia.c : æ‹¡å¼µAPIã®å®Ÿè£…。
  • +
  • relic.c : NDBM互æ›APIã®å®Ÿè£…。
  • +
  • hovel.c : GDBM互æ›APIã®å®Ÿè£…。
  • +
  • cabin.c : ユーティリティAPIã®å®Ÿè£…。
  • +
  • villa.c : 上級APIã®å®Ÿè£…。
  • +
  • vista.c : 拡張上級APIã®å®Ÿè£…。
  • +
  • odeum.c : 転置APIã®å®Ÿè£…。
  • +
+ +

`fcntl' コールã«ã‚ˆã‚‹ãƒ•ã‚¡ã‚¤ãƒ«ãƒ­ãƒƒã‚¯ãŒã‚µãƒãƒ¼ãƒˆã•ã‚Œã¦ã„ãªã„プラットフォームã§ã¯ã€`Makefile' ã§å®šç¾©ã•ã‚Œã‚‹ `CFLAGS' マクロ㫠`-DMYNOLOCK' を追加ã™ã‚‹ã¨ã‚ˆã„。ãã®éš›ã«ã¯ãƒ—ロセス間ã®æŽ’他制御を行ã†åˆ¥ã®æ–¹æ³•ã‚’考ãˆã‚‹å¿…è¦ãŒã‚る。åŒæ§˜ã«ã€`mmap' コールãŒãªã„プラットフォームã§ã¯ã€`CFLAGS' ã« `-DMYNOMMAP' を追加ã™ã‚‹ã¨ã‚ˆã„。`mmap' ã«é–¢ã—ã¦ã¯ `malloc' 等を用ã„ãŸã‚¨ãƒŸãƒ¥ãƒ¬ãƒ¼ã‚·ãƒ§ãƒ³ãŒç”¨æ„ã•ã‚Œã¦ã„る。ãã®ä»–ã®ã‚·ã‚¹ãƒ†ãƒ ã‚³ãƒ¼ãƒ«ãŒå®Ÿè£…ã•ã‚Œã¦ã„ãªã„å ´åˆã¯ã€`myconf.h' 㨠`myconf.c' を修正ã—ã¦è©²å½“ã®ã‚·ã‚¹ãƒ†ãƒ ã‚³ãƒ¼ãƒ«ã®ã‚¨ãƒŸãƒ¥ãƒ¬ãƒ¼ã‚·ãƒ§ãƒ³ã‚’è¡Œãˆã°ã‚ˆã„。

+ +

C++用ã®APIã§ã¯POSIXスレッドを使ã£ã¦ã„ã‚‹ã®ã§ã€ãã®ãƒ‘ッケージãŒå®Ÿè£…ã•ã‚Œã¦ã„ãªã„環境ã«ã¯C++用APIã¯ç§»æ¤ã§ããªã„。Java用ã®APIã§ã¯JNIを使ã£ã¦ã„ã‚‹ã®ã§ã€ãã®ãƒ˜ãƒƒãƒ€ã‚„ライブラリã®å ´æ‰€ã«æ³¨æ„ã™ã¹ãã§ã‚る。ã¾ãŸã€`long long' ã‚„ `int64' ã¨ã„ã£ãŸåž‹å®šç¾©ã«ã‚‚注æ„ã™ã¹ãã§ã‚る。Perlã‚„Ruby用ã®APIã§ã¯å„々ã®è¨€èªžå‡¦ç†ç³»ã§ç”¨æ„ã•ã‚ŒãŸãƒ“ルドコマンドを用ã„ã¦ã„ã‚‹ã®ã§ã€ãã®ä»•æ§˜ã«ç²¾é€šã™ã¹ãã§ã‚る。

+ +
+ +

ãƒã‚°

+ +

QDBMã®å„文書ã¯è‹±èªžã‚’æ¯å›½èªžã¨ã™ã‚‹äººé”ã«ã‚ˆã£ã¦æ ¡æ­£ã•ã‚Œã‚‹ã¹ãã§ã‚る。

+ +

segmentation faultã«ã‚ˆã‚‹ã‚¯ãƒ©ãƒƒã‚·ãƒ¥ã€äºˆæœŸã›ã¬ãƒ‡ãƒ¼ã‚¿ã®æ¶ˆå¤±ç­‰ã®ä¸æ•´åˆã€ãƒ¡ãƒ¢ãƒªãƒªãƒ¼ã‚¯ã€ãã®ä»–諸々ã®ãƒã‚°ã«é–¢ã—ã¦ã€æ—¢çŸ¥ã®ã‚‚ã®ã§æœªä¿®æ­£ã®ã‚‚ã®ã¯ãªã„。

+ +

ãƒã‚°ã‚’発見ã—ãŸã‚‰ã€æ˜¯éžã¨ã‚‚作者ã«ãƒ•ã‚£ãƒ¼ãƒ‰ãƒãƒƒã‚¯ã—ã¦ã»ã—ã„。ãã®éš›ã€QDBMã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã¨ã€åˆ©ç”¨ç’°å¢ƒã®OSã¨ã‚³ãƒ³ãƒ‘イラã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã‚‚æ•™ãˆã¦ã»ã—ã„。

+ +

1.7.13よりå‰ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã®QDBMã§ä½œæˆã—ãŸãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¯ã€ãれ以後ã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã¨äº’æ›æ€§ãŒãªã„。

+ +
+ +

よãèžã‹ã‚Œã‚‹è³ªå•

+ +
+
Q. : QDBMã¯SQLをサãƒãƒ¼ãƒˆã™ã‚‹ã‹ã€‚
+
A. : QDBMã¯SQLをサãƒãƒ¼ãƒˆã—ãªã„。QDBMã¯RDBMS(関係データベース管ç†ã‚·ã‚¹ãƒ†ãƒ ï¼‰ã§ã¯ãªã„。組ã¿è¾¼ã¿ã®RDBMSを求ã‚ã‚‹ãªã‚‰ã€SQLiteãªã©ã‚’利用ã™ã‚‹ã¨ã‚ˆã„。
+
Q. : çµå±€ã®ã¨ã“ã‚ã€GDBM(NDBMã€SDBMã€Berkeley DB)ã¨ã©ã†é•ã†ã®ã‹ã€‚
+
A. : 処ç†ãŒé€Ÿã„。データベースファイルãŒå°ã•ã„。APIãŒç°¡æ½”ã§ã‚る。特筆ã™ã¹ãã¯ã€ãƒ¬ã‚³ãƒ¼ãƒ‰ã®ä¸Šæ›¸ãã‚’ç¹°ã‚Šè¿”ã™å ´åˆã®æ™‚é–“çš„ãŠã‚ˆã³ç©ºé–“的効率ãŒã¨ã¦ã‚‚よãã€å®Ÿç”¨ä¸Šã®ã‚¹ã‚±ãƒ¼ãƒ©ãƒ“リティãŒé«˜ã„ã“ã¨ã§ã‚る。ã¾ãŸã€ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ãŒ100万を越ãˆã‚‹ã‚ˆã†ãªå¤§è¦æ¨¡ãªãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’構築ã™ã‚‹éš›ã«ã‚‚ã€å‡¦ç†ãŒæ¥µç«¯ã«é…ããªã£ãŸã‚Šã€ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºãŒæ¥µç«¯ã«å¤§ãããªã£ãŸã‚Šã—ãªã„。ã¨ã¯ã„ãˆã€ç”¨é€”ã«ã‚ˆã£ã¦ã¯ä»–ã®DBMã‚„DBMSを使ã†æ–¹ãŒé©åˆ‡ã‹ã‚‚ã—ã‚Œãªã„ã®ã§ã€å„自ã§æ€§èƒ½ã‚„機能ã®æ¯”較をã—ã¦ã¿ã¦ã»ã—ã„。
+
Q. : å‚考文献ã¯ä½•ã‹ã€‚
+
A. : QDBMã®å„種アルゴリズムã¯ã€ä¸»ã«Ahoä»–ã® `Data Structures and Algorithms'(邦題ã¯ã€Œãƒ‡ãƒ¼ã‚¿æ§‹é€ ã¨ã‚¢ãƒ«ã‚´ãƒªã‚ºãƒ ã€ï¼‰ãŠã‚ˆã³Sedgewickã® `Algorithms in C'(邦題ã¯ã€Œã‚¢ãƒ«ã‚´ãƒªã‚ºãƒ Cã€ï¼‰ã®è¨˜è¿°ã«åŸºç¤Žã‚’ç½®ã„ã¦ã„る。
+
Q. : ã©ã®APIを使ãˆã°ã‚ˆã„ã®ã‹ã€‚
+
A. : レコードã®æ¤œç´¢ãŒå®Œå…¨ä¸€è‡´ã ã‘ã§æ¸ˆã‚€ã®ãªã‚‰ã€Depotを試ã™ã¨ã‚ˆã„。ãã®è¦æ¨¡ãŒå¤§ãã„ãªã‚‰ã€Curiaを試ã™ã¨ã‚ˆã„。レコードを順åºã«åŸºã¥ã„ã¦å‚ç…§ã—ãŸã„ãªã‚‰ã€Villaを試ã™ã¨ã‚ˆã„。ãã®è¦æ¨¡ãŒå¤§ãã„ãªã‚‰ã€Vistaを試ã™ã¨ã‚ˆã„。最大ã®ãƒ¬ã‚³ãƒ¼ãƒ‰æ•°ã‚’追求ã™ã‚‹ãªã‚‰ã€ZLIBã‹LZOを有効ã«ã—ã¦QDBMをビルドã—ã€ãã®ä¸Šã§Vistaを用ã„ã‚‹ã®ãŒã‚ˆã„。
+
Q. : アプリケーションã®è‰¯ã„サンプルコードã¯ã‚ã‚‹ã‹ã€‚
+
A. : å„APIã®ã‚³ãƒžãƒ³ãƒ‰ã®ã‚½ãƒ¼ã‚¹ã‚³ãƒ¼ãƒ‰ã‚’å‚考ã«ã—ã¦ã»ã—ã„。`dptsv.c' 㨠`crtsv.c' 㨠`vltsv.c' ãŒæœ€ã‚‚ç°¡æ½”ã§ã‚る。
+
Q. : データベースãŒå£Šã‚ŒãŸã®ã ãŒã€ã©ã†ã—ã¦ã‹ã€‚
+
A. : 大抵ã®å ´åˆã€ã‚ãªãŸã®ã‚¢ãƒ—リケーションãŒãã¡ã‚“ã¨ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‰ã˜ã¦ã„ãªã„ã®ãŒåŽŸå› ã§ã‚る。デーモンプロセスã§ã‚ã‚ã†ãŒã€CGIスクリプトã§ã‚ã‚ã†ãŒã€ã‚¢ãƒ—リケーションãŒçµ‚了ã™ã‚‹éš›ã«ã¯å¿…ãšãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’é–‰ã˜ãªã‘ã‚Œã°ãªã‚‰ãªã„。ãªãŠã€CGIã®ãƒ—ロセスã¯SIGPIPEã‚„SIGTERMã«ã‚ˆã£ã¦æ®ºã•ã‚Œã‚‹ã“ã¨ãŒã‚ã‚‹ã“ã¨ã«ã‚‚ç•™æ„ã™ã¹ãã§ã‚る。
+
Q. : QDBMã®ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã¯ã©ã®ãらã„堅牢ãªã®ã‹ã€‚
+
A. : QDBMã¯çµ¶å¯¾çš„ãªå …牢性ã¯ä¿è¨¼ã—ãªã„。オペレーティングシステムãŒæš´èµ°ã—ãŸéš›ã«ã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãŒå£Šã‚Œã‚‹å¯èƒ½æ€§ãŒã‚る。Villaã®ãƒˆãƒ©ãƒ³ã‚¶ã‚¯ã‚·ãƒ§ãƒ³ã¯ã‚¢ãƒ—リケーションã®æš´èµ°ã‹ã‚‰ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã‚’ä¿è­·ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ãŒã€ã‚ªãƒšãƒ¬ãƒ¼ãƒ†ã‚£ãƒ³ã‚°ã‚·ã‚¹ãƒ†ãƒ ã®æš´èµ°ã«ã¯å¯¾å‡¦ã§ããªã„。ã—ãŸãŒã£ã¦ã€ãƒŸãƒƒã‚·ãƒ§ãƒ³ã‚¯ãƒªãƒ†ã‚£ã‚«ãƒ«ãªç”¨é€”ã«QDBMを利用ã™ã‚‹å ´åˆã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã®å¤šé‡åŒ–を考慮ã™ã¹ãã§ã‚る。
+
Q. : Depotã¨Curiaã®ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã®ä½¿ã„æ–¹ãŒã‚ˆãã‚ã‹ã‚‰ãªã„ãŒã€‚
+
A. : 上書ãモードや連çµãƒ¢ãƒ¼ãƒ‰ã§ã®æ›¸ãè¾¼ã¿ã‚’ç¹°ã‚Šè¿”ã™å ´åˆã«ã€ã‚¢ãƒ©ã‚¤ãƒ³ãƒ¡ãƒ³ãƒˆã¯ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ãƒ•ã‚¡ã‚¤ãƒ«ã®ã‚µã‚¤ã‚ºãŒæ€¥æ¿€ã«å¤§ãããªã‚‹ã®ã‚’防ã。アラインメントã®é©åˆ‡ãªã‚µã‚¤ã‚ºã¯ã‚¢ãƒ—リケーションã«ã‚ˆã£ã¦ç•°ãªã‚‹ã®ã§ã€å„自ã§å®Ÿé¨“ã—ã¦ã¿ã¦ã»ã—ã„。ã•ã—ã‚ãŸã‚Šã¯32ãらã„ã«ã—ã¦ãŠãã¨ã‚ˆã„。
+
Q. : Villaã®æ€§èƒ½ãƒ‘ラメータã®èª¿æ•´ãŒã‚ˆãã‚ã‹ã‚‰ãªã„ãŒã€‚
+
A. : レコードを順番ã«å‚ç…§ã™ã‚‹ã“ã¨ãŒå¤šã„ãªã‚‰ã°ã€`lrecmax' 㨠`nidxmax' をより大ããã—ãŸæ–¹ãŒã‚ˆã„。レコードを無作為ã«å‚ç…§ã™ã‚‹ã“ã¨ãŒå¤šã„ãªã‚‰ã°ã€ãれらã¯å°ã•ãã—ãŸæ–¹ãŒã‚ˆã„。RAMã«ä½™è£•ãŒã‚ã‚‹ãªã‚‰ã°ã€`lcnum' 㨠`ncnum' を増やã™ã¨æ€§èƒ½ãŒã‹ãªã‚Šå‘上ã™ã‚‹ã€‚ZLIBã‚„LZOã‚„BZIP2を有効化ã—ãŸå ´åˆã€`lrecmax' を大ããã—ãŸæ–¹ãŒåœ§ç¸®åŠ¹çŽ‡ãŒã‚ˆããªã‚‹ã€‚
+
Q. : Villaã®åœ§ç¸®æ–¹å¼ã¨ã—ã¦ã¯ZLIBã¨LZOã¨BZIP2ã®ã©ã‚ŒãŒã‚ˆã„ã®ã‹ã€‚
+
A. : 圧縮率ãŒæœ€ã‚‚良ã„ã®ã¯BZIP2ã§ã€å‡¦ç†é€Ÿåº¦ãŒæœ€ã‚‚高ã„ã®ã¯LZOã§ã€ZLIBã¯ãã®ä¸­é–“çš„ãªç‰¹æ€§ã‚’æŒã¤ã€‚特ã«ç†ç”±ãŒãªã„é™ã‚Šã¯ZLIBを使ã†ã¨ã‚ˆã„。ãŸã ã—ã€æ›´æ–°ãŒé »ç¹ãªãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹ã«ã¯LZOãŒé©åˆ‡ã§ã€æ›´æ–°ãŒã»ã¨ã‚“ã©ãªã„ãªã‚‰ã°BZIP2ãŒé©åˆ‡ã§ã‚る。圧縮ã—ãªã„ã¨ã„ã†é¸æŠžè‚¢ã‚ˆã‚Šã¯LZOを使ã†æ–¹ãŒã‚ˆã„。LZOã®ãƒ©ã‚¤ã‚»ãƒ³ã‚¹ã¯GNU GPLã§ã‚ã‚‹ã“ã¨ã«æ³¨æ„ã™ã‚‹ã“ã¨ã€‚
+
Q. : スパースファイルã¨ã¯ä½•ã‹ã€‚
+
A. : ホール(一度もデータãŒæ›¸ãè¾¼ã¾ã‚Œã¦ã„ãªã„ブロック)ãŒã‚るファイルã®ã“ã¨ã§ã‚る。ファイルシステムãŒã‚¹ãƒ‘ースファイルをサãƒãƒ¼ãƒˆã—ã¦ã„ã‚‹å ´åˆã€ãƒ›ãƒ¼ãƒ«ã¯ç‰©ç†çš„ãªè¨˜æ†¶è£…ç½®ã«å‰²ã‚Šå½“ã¦ã‚‰ã‚Œãªã„。QDBMã§ã¯ã€DP_OSPARSEãªã©ã®ãƒ•ãƒ©ã‚°ã‚’用ã„ã‚‹ã¨ã€ãƒãƒƒã‚·ãƒ¥ã®ãƒã‚±ãƒƒãƒˆé…列ã¯åˆæœŸåŒ–ã•ã‚Œãšã«ãƒ›ãƒ¼ãƒ«ã¨ãªã‚‹ã€‚ã“ã®ã“ã¨ã‚’利用ã—ã¦ã€éžå¸¸ã«å·¨å¤§ãªãƒãƒƒã‚·ãƒ¥è¡¨ã‚’実ç¾ã™ã‚‹ã“ã¨ãŒã§ãる。ãŸã ã—ã€ãã®æ€§èƒ½ã¯ãƒ•ã‚¡ã‚¤ãƒ«ã‚·ã‚¹ãƒ†ãƒ ã®è¨­å®šã«å¼·ãä¾å­˜ã™ã‚‹ã€‚
+
Q. : ãªãœDepotã¨Curiaã«ã¯ãƒˆãƒ©ãƒ³ã‚¶ã‚¯ã‚·ãƒ§ãƒ³æ©Ÿèƒ½ãŒãªã„ã®ã‹ã€‚
+
A. : アプリケーションãŒç‹¬è‡ªã®ãƒˆãƒ©ãƒ³ã‚¶ã‚¯ã‚·ãƒ§ãƒ³æ©Ÿèƒ½ã‚’実装ã—ã¦ã„ã‚‹å ´åˆã«ã¯ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ãƒ¼ã‚¹å†…部ã®ãƒˆãƒ©ãƒ³ã‚¶ã‚¯ã‚·ãƒ§ãƒ³ã¯é‚ªé­”ã«ãªã‚‹ã‹ã‚‰ã§ã‚る。トランザクションã¯Cabinã®ãƒžãƒƒãƒ—を使ãˆã°ç°¡å˜ã«å®Ÿè£…ã§ãる。
+
Q. : 性能を引ã出ã™ã‚·ã‚¹ãƒ†ãƒ ã®è¨­å®šã¯ã©ã†ã§ã‚ã‚‹ã‹ã€‚
+
A. : データベースã®ã‚µã‚¤ã‚ºã¨åŒç­‰ä»¥ä¸Šã®RAMをマシンã«æ­è¼‰ã™ã‚‹ã“ã¨ãŒæœ›ã¾ã—ã„。ãã—ã¦ã€I/Oãƒãƒƒãƒ•ã‚¡ã®ã‚µã‚¤ã‚ºã‚’大ããã—ã€ãƒ€ãƒ¼ãƒ†ã‚£ãƒãƒƒãƒ•ã‚¡ã‚’フラッシュã™ã‚‹é »åº¦ãŒå°‘ãªãã™ã‚‹ã‚ˆã†ã«è¨­å®šã™ã‚‹ã¨ã‚ˆã„。ファイルシステムã®é¸æŠžã‚‚é‡è¦ã§ã‚る。Linux上ã§ã¯ã€é€šå¸¸ã¯EXT2ãŒæœ€é«˜é€Ÿã§ã‚ã‚‹ãŒã€EXT3ã® `writeback' モードã®æ–¹ãŒé€Ÿã„ã“ã¨ã‚‚ã‚る。ReiserFSã¯ãã‚Œãªã‚Šã§ã‚る。EXT3ã®ãã®ä»–ã®ãƒ¢ãƒ¼ãƒ‰ã¯ã‹ãªã‚Šé…ã„。他ã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚·ã‚¹ãƒ†ãƒ ã«é–¢ã—ã¦ã¯å„自ã§å®Ÿé¨“ã—ã¦ã¿ã¦ã»ã—ã„。
+
Q. : `gcc' ã®ä»£ã‚ã‚Šã« `cc' を使ã£ã¦ãƒ“ルドã§ãã‚‹ã‹ã€‚
+
A. : `LTmakefile' を使ãˆã°ã§ãる。
+
Q. : Visual C++を使ã£ã¦ãƒ“ルドã§ãã‚‹ã‹ã€‚
+
A. : ã§ãる。`Makefile' ã®ä»£ã‚ã‚Šã« `VCmakefile' を使ã†ã“ã¨ã€‚
+
Q. : ä»–ã«QDBMを利用ã§ãる言語ã¯ã‚ã‚‹ã‹ã€‚
+
A. : PHPã€Scheme(Gauche)ã€OCaml用ã®ã‚¤ãƒ³ã‚¿ãƒ•ã‚§ãƒ¼ã‚¹ãŒæ—¢ã«å…¬é–‹ã•ã‚Œã¦ã„るよã†ã§ã‚る。ãれ以外ã®è¨€èªžã«ã¤ã„ã¦ã¯ã€å¿…è¦ãªã‚‰è‡ªåˆ†ã§ä½œã£ã¦ã»ã—ã„。
+
Q. : 「QDBMã€ã¨ã¯ã©ã†ã„ã†æ„味ãªã®ã‹ã€‚
+
A. : 「QDBMã€ã¯ã€ŒQuick Database Managerã€ã®ç•¥ã§ã‚る。高速ã«å‹•ä½œã™ã‚‹ã¨ã„ã†æ„味ã¨ã€ã‚¢ãƒ—リケーションã®é–‹ç™ºãŒè¿…速ã«ã§ãã‚‹ã¨ã„ã†æ„味ãŒè¾¼ã‚られã¦ã„る。
+
Q. : å„APIã®åå‰ã¯ã©ã†ã„ã†æ„味ãªã®ã‹ã€‚ã©ã†ç™ºéŸ³ã™ã‚‹ã®ã‹ã€‚
+
A. : 5文字ã®è‹±å˜èªžã‹ã‚‰é©å½“ã«é¸æŠžã—ãŸã ã‘ã§ã€æ·±ã„æ„味ã¯ãªã„。ãªãŠã€ã€Œdepotã€ã¯ã€ç©ºæ¸¯ã€å€‰åº«ã€è£œçµ¦æ‰€ãªã©ã€ç‰©è³ªãŒé›†ã¾ã‚‹å ´æ‰€ã‚’æ„味ã™ã‚‹ã‚‰ã—ã„。発音を片仮åã§è¡¨ç¾ã™ã‚‹ãªã‚‰ã€Œãƒ‡ã‚£ãƒ¼ãƒã‚¥ã€ãŒå¦¥å½“ã ã‚ã†ã€‚「curiaã€ã¯ã€å®®å»·ã€æ³•å»·ãªã©ã€æ¨©å¨ãŒé›†ã¾ã‚‹å ´æ‰€ã‚’æ„味ã™ã‚‹ã‚‰ã—ã„。発音を片仮åã§è¡¨ç¾ã™ã‚‹ãªã‚‰ã€Œã‚­ãƒ¥ãƒªã‚¢ã€ãŒå¦¥å½“ã ã‚ã†ã€‚「relicã€ã¯ã€éºç‰©ã€éºè·¡ãªã©ã€éŽåŽ»ã®æ®‹éª¸ã‚’æ„味ã™ã‚‹ã‚‰ã—ã„。発音を片仮åã§è¡¨ç¾ã™ã‚‹ãªã‚‰ã€Œãƒ¬ãƒªãƒƒã‚¯ã€ãŒå¦¥å½“ã ã‚ã†ã€‚「hovelã€ã¯ã€å°å±‹ã€ç‰©ç½®ã€é›¢ã‚Œå®¶ãªã©ã€ç²—末ãªå»ºç‰©ã‚’æ„味ã™ã‚‹ã‚‰ã—ã„。発音を片仮åã§è¡¨ç¾ã™ã‚‹ãªã‚‰ã€Œãƒãƒ´ãƒ«ã€ãŒå¦¥å½“ã ã‚ã†ã€‚「cabinã€ã¯ã€æ©Ÿå®¤ã€å®¢å®¤ã€å°å±‹ãªã©ã€ç°¡æ˜“çš„ãªå±…ä½ç©ºé–“ã‚’æ„味ã™ã‚‹ã‚‰ã—ã„。発音を片仮åã§è¡¨ç¾ã™ã‚‹ãªã‚‰ã€Œã‚­ãƒ£ãƒ“ンã€ãŒå¦¥å½“ã ã‚ã†ã€‚「villaã€ã¯ã€åˆ¥è˜ã€éƒŠå¤–ä½å®…ãªã©ã€éƒ½ä¼šé¢¨ã§ãªã„ä½å±…ã‚’æ„味ã™ã‚‹ã‚‰ã—ã„。発音を片仮åã§è¡¨ç¾ã™ã‚‹ãªã‚‰ã€Œãƒ´ã‚£ãƒ©ã€ãŒå¦¥å½“ã ã‚ã†ã€‚「vistaã€ã¯ã€äºˆæƒ³ã€å±•æœ›ãªã©ã€é ãを見渡ã™ã“ã¨ã‚’æ„味ã™ã‚‹ã‚‰ã—ã„。発音を片仮åã§è¡¨ç¾ã™ã‚‹ãªã‚‰ã€Œãƒ´ã‚£ã‚¹ã‚¿ã€ãŒå¦¥å½“ã ã‚ã†ã€‚「odeumã€ã¯ã€éŸ³æ¥½å ‚ã€åŠ‡å ´ãªã©ã€éŸ³æ¥½ã‚„è©©åŸã‚’è¡Œã†å»ºç‰©ã‚’æ„味ã™ã‚‹ã‚‰ã—ã„。発音を片仮åã§è¡¨ç¾ã™ã‚‹ãªã‚‰ã€Œã‚ªãƒ‡ã‚£ã‚¢ãƒ ã€ãŒå¦¥å½“ã ã‚ã†ã€‚
+
+ +
+ +

ライセンス

+ +

QDBMã¯ãƒ•ãƒªãƒ¼ã‚½ãƒ•ãƒˆã‚¦ã‚§ã‚¢ã§ã‚る。ã‚ãªãŸã¯ã€Free Software FoundationãŒå…¬è¡¨ã—ãŸGNU Lesser General Public Licenseã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³2.1ã‚ã‚‹ã„ã¯ãれ以é™ã®å„ãƒãƒ¼ã‚¸ãƒ§ãƒ³ã®ä¸­ã‹ã‚‰ã„ãšã‚Œã‹ã‚’é¸æŠžã—ã€ãã®ãƒãƒ¼ã‚¸ãƒ§ãƒ³ãŒå®šã‚ã‚‹æ¡é …ã«å¾“ã£ã¦QDBMã‚’å†é ’布ã¾ãŸã¯å¤‰æ›´ã™ã‚‹ã“ã¨ãŒã§ãる。

+ +

QDBMã¯æœ‰ç”¨ã§ã‚ã‚‹ã¨æ€ã‚れるãŒã€é ’布ã«ã‚ãŸã£ã¦ã¯ã€å¸‚場性åŠã³ç‰¹å®šç›®çš„é©åˆæ€§ã«ã¤ã„ã¦ã®æš—é»™ã®ä¿è¨¼ã‚’å«ã‚ã¦ã€ã„ã‹ãªã‚‹ä¿è¨¼ã‚‚è¡Œãªã‚ãªã„。詳細ã«ã¤ã„ã¦ã¯GNU Lesser General Public Licenseを読んã§ã»ã—ã„。

+ +

ã‚ãªãŸã¯ã€QDBMã¨ä¸€ç·’ã«GNU Lesser General Public Licenseã®å†™ã—ã‚’å—ã‘å–ã£ã¦ã„ã‚‹ã¯ãšã§ã‚る(`COPYING' ファイルをå‚照)。ãã†ã§ãªã„å ´åˆã¯ã€Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA ã¸é€£çµ¡ã—ã¦ã»ã—ã„。

+ +

QDBMã¯å¹³æž—幹雄ãŒä½œæˆã—ãŸã€‚作者ã¨é€£çµ¡ã‚’ã¨ã‚‹ã«ã¯ã€`mikio@users.sourceforge.net' å®›ã«é›»å­ãƒ¡ãƒ¼ãƒ«ã‚’é€ã£ã¦ã»ã—ã„。ãŸã ã—ã€è³ªå•ã‚„ãƒã‚°ãƒ¬ãƒãƒ¼ãƒˆãªã©ã€ä»–ã®ãƒ¦ãƒ¼ã‚¶ã¨å…±æœ‰ã§ãる話題ã¯ãƒ¡ãƒ¼ãƒªãƒ³ã‚°ãƒªã‚¹ãƒˆã«é€ã£ã¦ã»ã—ã„。メーリングリストã®å‚加方法ã«ã¤ã„ã¦ã¯ã€`http://lists.sourceforge.net/lists/listinfo/qdbm-users' ã‚’å‚ç…§ã™ã‚‹ã“ã¨ã€‚

+ +
+ + + + + + diff --git a/qdbm/spex.html b/qdbm/spex.html new file mode 100644 index 00000000..9c1505f4 --- /dev/null +++ b/qdbm/spex.html @@ -0,0 +1,4343 @@ + + + + + + + + + + + + + + + +Specifications of QDBM Version 1 + + + + + +

Fundamental Specifications of QDBM Version 1

+ +
Copyright (C) 2000-2007 Mikio Hirabayashi
+
Last Update: Thu, 26 Oct 2006 15:00:20 +0900
+ + +
+ +

Table of Contents

+ +
    +
  1. Overview
  2. +
  3. Features
  4. +
  5. Installation
  6. +
  7. Depot: Basic API
  8. +
  9. Commands for Depot
  10. +
  11. Curia: Extended API
  12. +
  13. Commands for Curia
  14. +
  15. Relic: NDBM-compatible API
  16. +
  17. Commands for Relic
  18. +
  19. Hovel: GDBM-compatible API
  20. +
  21. Commands for Hovel
  22. +
  23. Cabin: Utility API
  24. +
  25. Commands for Cabin
  26. +
  27. Villa: Advanced API
  28. +
  29. Commands for Villa
  30. +
  31. Odeum: Inverted API
  32. +
  33. Commands for Odeum
  34. +
  35. File Format
  36. +
  37. Porting
  38. +
  39. Bugs
  40. +
  41. Frequently Asked Questions
  42. +
  43. Copying
  44. +
+ +
+ +

Overview

+ +

QDBM is a library of routines for managing a database. The database is a simple data file containing records, each is a pair of a key and a value. Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. There is neither concept of data tables nor data types. Records are organized in hash table or B+ tree.

+ +

As for database of hash table, each key must be unique within a database, so it is impossible to store two or more records with a key overlaps. The following access methods are provided to the database: storing a record with a key and a value, deleting a record by a key, retrieving a record by a key. Moreover, traversal access to every key are provided, although the order is arbitrary. These access methods are similar to ones of DBM (or its followers: NDBM and GDBM) library defined in the UNIX standard. QDBM is an alternative for DBM because of its higher performance.

+ +

As for database of B+ tree, records whose keys are duplicated can be stored. Access methods of storing, deleting, and retrieving are provided as with the database of hash table. Records are stored in order by a comparing function assigned by a user. It is possible to access each record with the cursor in ascending or descending order. According to this mechanism, forward matching search for strings and range search for integers are realized. Moreover, transaction is available in database of B+ tree.

+ +

QDBM is written in C, and provided as APIs of C, C++, Java, Perl, and Ruby. QDBM is available on platforms which have API conforming to POSIX. QDBM is a free software licensed under the GNU Lesser General Public License.

+ +
+ +

Features

+ +

Effective Implementation of Hash Database

+ +

QDBM is developed referring to GDBM for the purpose of the following three points: higher processing speed, smaller size of a database file, and simpler API. They have been achieved. Moreover, as with GDBM, the following three restrictions of traditional DBM: a process can handle only one database, the size of a key and a value is bounded, a database file is sparse, are cleared.

+ +

QDBM uses hash algorithm to retrieve records. If a bucket array has sufficient number of elements, the time complexity of retrieval is `O(1)'. That is, time required for retrieving a record is constant, regardless of the scale of a database. It is also the same about storing and deleting. Collision of hash values is managed by separate chaining. Data structure of the chains is binary search tree. Even if a bucket array has unusually scarce elements, the time complexity of retrieval is `O(log n)'.

+ +

QDBM attains improvement in retrieval by loading RAM with the whole of a bucket array. If a bucket array is on RAM, it is possible to access a region of a target record by about one path of file operations. A bucket array saved in a file is not read into RAM with the `read' call but directly mapped to RAM with the `mmap' call. Therefore, preparation time on connecting to a database is very short, and two or more processes can share the same memory map.

+ +

If the number of elements of a bucket array is about half of records stored within a database, although it depends on characteristic of the input, the probability of collision of hash values is about 56.7% (36.8% if the same, 21.3% if twice, 11.5% if four times, 6.0% if eight times). In such case, it is possible to retrieve a record by two or less paths of file operations. If it is made into a performance index, in order to handle a database containing one million of records, a bucket array with half a million of elements is needed. The size of each element is 4 bytes. That is, if 2M bytes of RAM is available, a database containing one million records can be handled.

+ +

QDBM provides two modes to connect to a database: `reader' and `writer'. A reader can perform retrieving but neither storing nor deleting. A writer can perform all access methods. Exclusion control between processes is performed when connecting to a database by file locking. While a writer is connected to a database, neither readers nor writers can be connected. While a reader is connected to a database, other readers can be connect, but writers can not. According to this mechanism, data consistency is guaranteed with simultaneous connections in multitasking environment.

+ +

Traditional DBM provides two modes of the storing operations: `insert' and `replace'. In the case a key overlaps an existing record, the insert mode keeps the existing value, while the replace mode transposes it to the specified value. In addition to the two modes, QDBM provides `concatenate' mode. In the mode, the specified value is concatenated at the end of the existing value and stored. This feature is useful when adding a element to a value as an array. Moreover, although DBM has a method to fetch out a value from a database only by reading the whole of a region of a record, QDBM has a method to fetch out a part of a region of a value. When a value is treated as an array, this feature is also useful.

+ +

Generally speaking, while succession of updating, fragmentation of available regions occurs, and the size of a database grows rapidly. QDBM deal with this problem by coalescence of dispensable regions and reuse of them, and featuring of optimization of a database. When overwriting a record with a value whose size is greater than the existing one, it is necessary to remove the region to another position of the file. Because the time complexity of the operation depends on the size of the region of a record, extending values successively is inefficient. However, QDBM deal with this problem by alignment. If increment can be put in padding, it is not necessary to remove the region.

+ +

As for many file systems, it is impossible to handle a file whose size is more than 2GB. To deal with this problem, QDBM provides a directory database containing multiple database files. Due to this feature, it is possible to handle a database whose total size is up to 1TB in theory. Moreover, because database files can be deployed on multiple disks, the speed of updating operations can be improved as with RAID-0 (striping). It is also possible for the database files to deploy on multiple file servers using NFS and so on.

+ +

Useful Implementation of B+ Tree Database

+ +

Although B+ tree database is slower than hash database, it features ordering access to each record. The order can be assigned by users. Records of B+ tree are sorted and arranged in logical pages. Sparse index organized in B tree that is multiway balanced tree are maintained for each page. Thus, the time complexity of retrieval and so on is `O(log n)'. Cursor is provided to access each record in order. The cursor can jump to a position specified by a key and can step forward or backward from the current position. Because each page is arranged as double linked list, the time complexity of stepping cursor is `O(1)'.

+ +

B+ tree database is implemented, based on above hash database. Because each page of B+ tree is stored as each record of hash database, B+ tree database inherits efficiency of storage management of hash database. Because the header of each record is smaller and alignment of each page is adjusted according to the page size, in most cases, the size of database file is cut by half compared to one of hash database. Although operation of many pages are required to update B+ tree, QDBM expedites the process by caching pages and reducing file operations. In most cases, because whole of the sparse index is cached on memory, it is possible to retrieve a record by one or less path of file operations.

+ +

B+ tree database features transaction mechanism. It is possible to commit a series of operations between the beginning and the end of the transaction in a lump, or to abort the transaction and perform rollback to the state before the transaction. Even if the process of an application is crashed while the transaction, the database file is not broken.

+ +

In case that QDBM was built with ZLIB, LZO, or BZIP2 enabled, a lossless data-compression library, the content of each page of B+ tree is compressed and stored in a file. Because each record in a page has similar patterns, high efficiency of compression is expected due to the Lempel-Ziv algorithm and the like. In case handling text data, the size of a database is reduced to about 25%. If the scale of a database is large and disk I/O is the bottleneck, featuring compression makes the processing speed improved to a large extent.

+ +

Simple but Various Interfaces

+ +

QDBM provides very simple APIs. You can perform database I/O as usual file I/O with `FILE' pointer defined in ANSI C. In the basic API of QDBM, entity of a database is recorded as one file. In the extended API, entity of a database is recorded as several files in one directory. Because the two APIs are very similar with each other, porting an application from one to the other is easy.

+ +

APIs which are compatible with NDBM and GDBM are also provided. As there are a lot of applications using NDBM or GDBM, it is easy to port them onto QDBM. In most cases, it is completed only by replacement of header including (#include) and re-compiling. However, QDBM can not handle database files made by the original NDBM or GDBM.

+ +

In order to handle records on memory easily, the utility API is provided. It implements memory allocating functions, sorting functions, extensible datum, array list, hash map, and so on. Using them, you can handle records in C language cheaply as in such script languages as Perl or Ruby.

+ +

B+ tree database is used with the advanced API. The advanced API is implemented using the basic API and the utility API. Because the advanced API is also similar to the basic API and the extended API, it is easy to learn how to use it.

+ +

In order to handle an inverted index which is used by full-text search systems, the inverted API is provided. If it is easy to handle an inverted index of documents, an application can focus on text processing and natural language processing. Because this API does not depend on character codes nor languages, it is possible to implement a full-text search system which can respond to various requests from users.

+ +

Along with APIs for C, QDBM provides APIs for C++, Java, Perl, and Ruby. APIs for C are composed of seven kinds: the basic API, the extended API, the NDBM-compatible API, the GDBM-compatible API, the utility API, the advanced API, and the inverted API. Command line interfaces corresponding to each API are also provided. They are useful for prototyping, testing, debugging, and so on. The C++ API encapsulates database handling functions of the basic API, the extended API, and the advanced API with class mechanism of C++. The Java API has native methods calling the basic API, the extended API, and the advanced API with Java Native Interface. The Perl API has methods calling the basic API, the extended API, and the advanced API with XS language. The Ruby API has method calling the basic API, the extended API, and the advanced API as modules of Ruby. Moreover, CGI scripts for administration of databases, file uploading, and full-text search are provided.

+ +

Wide Portability

+ +

QDBM is implemented being based on syntax of ANSI C (C89) and using only APIs defined in ANSI C or POSIX. Thus, QDBM works on most UNIX and its compatible OSs. As for C API, checking operations have been done at least on the following platforms.

+ +
    +
  • Linux (2.2, 2.4, 2.6) (IA32, IA64, AMD64, PA-RISC, Alpha, PowerPC, M68000, ARM)
  • +
  • FreeBSD (4.9, 5.0, 5.1, 5.2, 5.3) (IA32, IA64, SPARC, Alpha)
  • +
  • NetBSD (1.6) (IA32)
  • +
  • OpenBSD (3.4) (IA32)
  • +
  • SunOS (5.6, 5.7, 5.8, 5.9, 5.10) (IA32, SPARC)
  • +
  • HP-UX (11.11, 11.23) (IA64, PA-RISC)
  • +
  • AIX (5.2) (POWER)
  • +
  • Windows (2000, XP) (IA32, IA64, AMD64) (Cygwin, MinGW, Visual C++)
  • +
  • Mac OS X (10.2, 10.3, 10.4) (IA32, PowerPC)
  • +
  • Tru64 (5.1) (Alpha)
  • +
  • RISC OS (5.03) (ARM)
  • +
+ +

Although a database file created by QDBM depends on byte order of the processor, to do with it, utilities to dump data in format which is independent to byte orders are provided.

+ +
+ +

Installation

+ +

Preparation

+ +

To install QDBM from a source package, GCC of 2.8 or later version and `make' are required.

+ +

When an archive file of QDBM is extracted, change the current working directory to the generated directory and perform installation.

+ +

Usual Steps

+ +

Follow the procedures below on Linux, BSD, or SunOS.

+ +

Run the configuration script.

+ +
./configure
+
+ +

Build programs.

+ +
make
+
+ +

Perform self-diagnostic test.

+ +
make check
+
+ +

Install programs. This operation must be carried out by the root user.

+ +
make install
+
+ +

Using GNU Libtool

+ +

If above steps do not work, try the following steps. This way needs GNU Libtool of 1.5 or later version.

+ +

Run the configuration script.

+ +
./configure
+
+ +

Build programs.

+ +
make -f LTmakefile
+
+ +

Perform self-diagnostic test.

+ +
make -f LTmakefile check
+
+ +

Install programs. This operation must be carried out by the root user.

+ +
make -f LTmakefile install
+
+ +

Result

+ +

When a series of work finishes, the following files will be installed. As for the rest, manuals will be installed under `/usr/local/man/man1' and '/usr/local/man/man3', other documents will be installed under `/usr/local/share/qdbm'. A configuration file for `pkg-config' will be installed under `/usr/local/lib/pkgconfig'.

+ +
/usr/local/include/depot.h
+/usr/local/include/curia.h
+/usr/local/include/relic.h
+/usr/local/include/hovel.h
+/usr/local/include/cabin.h
+/usr/local/include/villa.h
+/usr/local/include/vista.h
+/usr/local/include/odeum.h
+/usr/local/lib/libqdbm.a
+/usr/local/lib/libqdbm.so.14.13.0
+/usr/local/lib/libqdbm.so.14
+/usr/local/lib/libqdbm.so
+/usr/local/bin/dpmgr
+/usr/local/bin/dptest
+/usr/local/bin/dptsv
+/usr/local/bin/crmgr
+/usr/local/bin/crtest
+/usr/local/bin/crtsv
+/usr/local/bin/rlmgr
+/usr/local/bin/rltest
+/usr/local/bin/hvmgr
+/usr/local/bin/hvtest
+/usr/local/bin/cbtest
+/usr/local/bin/cbcodec
+/usr/local/bin/vlmgr
+/usr/local/bin/vltest
+/usr/local/bin/vltsv
+/usr/local/bin/odmgr
+/usr/local/bin/odtest
+/usr/local/bin/odidx
+/usr/local/bin/qmttest
+
+ +

When you run a program linked dynamically to `libqdbm.so', the library search path should include `/usr/local/lib'. You can set the library search path with the environment variable `LD_LIBRARY_PATH'.

+ +

To uninstall QDBM, execute the following command after `./configure'. This operation must be carried out by the root user.

+ +
make uninstall
+
+ +

If an old version of QDBM is installed on your system, uninstall it before installation of a new one.

+ +

The other APIs except for C nor CGI scripts are not installed by default. Refer to `plus/xspex.html' to know how to install the C++ API. Refer to `java/jspex.html' to know how to install the Java API. Refer to `perl/plspex.html' to know how to install the Perl API. Refer to `ruby/rbspex.html' to know how to install the Ruby API. Refer to `cgi/cgispex.html' to know how to install the CGI script.

+ +

To install QDBM from such a binary package as RPM, refer to the manual of the package manager. For example, if you use RPM, execute like the following command by the root user.

+ +
rpm -ivh qdbm-1.x.x-x.i386.rpm
+
+ +

For Windows

+ +

On Windows (Cygwin), you should follow the procedures below for installation.

+ +

Run the configuration script.

+ +
./configure
+
+ +

Build programs.

+ +
make win
+
+ +

Perform self-diagnostic test.

+ +
make check-win
+
+ +

Install programs. As well, perform `make uninstall-win' to uninstall them.

+ +
make install-win
+
+ +

On Windows, the import library `libqdbm.dll.a' is created as well as the static library `libqdbm.a', and the dynamic linking library `qdbm.dll' is created instead of such shared libraries as `libqdbm.so'. `qdbm.dll' is installed into `/usr/local/bin'.

+ +

In order to build QDBM using MinGW on Cygwin, you should perform `make mingw' instead of `make win'. With the UNIX emulation layer of Cygwin, generated programs depend on `cygwin1.dll' (they come under GNU GPL). This problem is solved by linking them to the Win32 native DLL with MinGW.

+ +

In order to build QDBM using Visual C++, you should edit `VCmakefile' and set the search paths for libraries and headers. And perform `nmake /f VCMakefile'. Applications linking to `qdbm.dll' should link to `msvcrt.dll' by `/MD' or `/MDd' option of the compiler. Refer to `VCmakefile' for detail configurations.

+ +

For Mac OS X

+ +

On Mac OS X (Darwin), you should follow the procedures below for installation.

+ +

Run the configuration script.

+ +
./configure
+
+ +

Build programs.

+ +
make mac
+
+ +

Perform self-diagnostic test.

+ +
make check-mac
+
+ +

Install programs. As well, perform `make uninstall-mac' to uninstall them.

+ +
make install-mac
+
+ +

On Mac OS X, `libqdbm.dylib' and so on are created instead of `libqdbm.so' and so on. You can set the library search path with the environment variable `DYLD_LIBRARY_PATH'.

+ +

For HP-UX

+ +

On HP-UX, you should follow the procedures below for installation.

+ +

Run the configuration script.

+ +
./configure
+
+ +

Build programs.

+ +
make hpux
+
+ +

Perform self-diagnostic test.

+ +
make check-hpux
+
+ +

Install programs. As well, perform `make uninstall-hpux' to uninstall them.

+ +
make install-hpux
+
+ +

On HP-UX, `libqdbm.sl' is created instead of `libqdbm.so' and so on. You can set the library search path with the environment variable `SHLIB_PATH'.

+ +

For RISC OS

+ +

On RISC OS, you should follow the procedures below for installation.

+ +

Build programs. As `cc' is used for compilation by default, if you want to use `gcc', add the argument `CC=gcc'.

+ +
make -f RISCmakefile
+
+ +

When a series of work finishes, the library file `libqdbm' and such commands as `dpmgr' are generated. Because how to install them is not defined, copy them manually for installation. As with it, such header files as `depot.h' should be installed manually.

+ +

Detail Configurations

+ +

You can configure building processes by the following optional arguments of `./configure'.

+ +
    +
  • --enable-debug : build for debugging. Enable debugging symbols, do not perform optimization, and perform static linking.
  • +
  • --enable-devel : build for development. Enable debugging symbols, perform optimization, and perform dynamic linking.
  • +
  • --enable-stable : build for stable release. Perform conservative optimization, and perform dynamic linking.
  • +
  • --enable-pthread : feature POSIX thread and treat global variables as thread specific data.
  • +
  • --disable-lock : build for environments without file locking.
  • +
  • --disable-mmap : build for environments without memory mapping.
  • +
  • --enable-zlib : feature ZLIB compression for B+ tree and inverted index.
  • +
  • --enable-lzo : feature LZO compression for B+ tree and inverted index.
  • +
  • --enable-bzip : feature BZIP2 compression for B+ tree and inverted index.
  • +
  • --enable-iconv : feature ICONV utilities for conversion of character encodings.
  • +
+ +

Usually, QDBM and its applications can be built without any dependency on non-standard libraries except for `libqdbm.*'. However, they depend on `libpthread.*' if POSIX thread is enabled, and they depend on `libz.*' if ZLIB is enabled, and they depend on `liblzo2.*' if LZO is enabled, and they depend on `libbz2.*' if BZIP2 is enabled, and they depend on `libiconv.*' if ICONV is enabled.

+ +

Because the license of LZO is GNU GPL, note that applications linking to `liblzo2.*' should meet commitments of GNU GPL.

+ +
+ +

Depot: Basic API

+ +

Overview

+ +

Depot is the basic API of QDBM. Almost all features for managing a database provided by QDBM are implemented by Depot. Other APIs are no more than wrappers of Depot. Depot is the fastest in all APIs of QDBM.

+ +

In order to use Depot, you should include `depot.h' and `stdlib.h' in the source files. Usually, the following description will be near the beginning of a source file.

+ +
+
#include <depot.h>
+
#include <stdlib.h>
+
+ +

A pointer to `DEPOT' is used as a database handle. It is like that some file I/O routines of `stdio.h' use a pointer to `FILE'. A database handle is opened with the function `dpopen' and closed with `dpclose'. You should not refer directly to any member of the handle. If a fatal error occurs in a database, any access method via the handle except `dpclose' will not work and return error status. Although a process is allowed to use multiple database handles at the same time, handles of the same database file should not be used.

+ +

API

+ +

The external variable `dpversion' is the string containing the version information.

+ +
+
extern const char *dpversion;
+
+ +

The external variable `dpecode' is assigned with the last happened error code. Refer to `depot.h' for details of the error codes.

+ +
+
extern int dpecode;
+
The initial value of this variable is `DP_ENOERR'. The other values are `DP_EFATAL', `DP_EMODE', `DP_EBROKEN', `DP_EKEEP', `DP_ENOITEM', `DP_EALLOC', `DP_EMAP', `DP_EOPEN', `DP_ECLOSE', `DP_ETRUNC', `DP_ESYNC', `DP_ESTAT', `DP_ESEEK', `DP_EREAD', `DP_EWRITE', `DP_ELOCK', `DP_EUNLINK', `DP_EMKDIR', `DP_ERMDIR', and `DP_EMISC'.
+
+ +

The function `dperrmsg' is used in order to get a message string corresponding to an error code.

+ +
+
const char *dperrmsg(int ecode);
+
`ecode' specifies an error code. The return value is the message string of the error code. The region of the return value is not writable.
+
+ +

The function `dpopen' is used in order to get a database handle.

+ +
+
DEPOT *dpopen(const char *name, int omode, int bnum);
+
`name' specifies the name of a database file. `omode' specifies the connection mode: `DP_OWRITER' as a writer, `DP_OREADER' as a reader. If the mode is `DP_OWRITER', the following may be added by bitwise or: `DP_OCREAT', which means it creates a new database if not exist, `DP_OTRUNC', which means it creates a new database regardless if one exists. Both of `DP_OREADER' and `DP_OWRITER' can be added to by bitwise or: `DP_ONOLCK', which means it opens a database file without file locking, or `DP_OLCKNB', which means locking is performed without blocking. `DP_OCREAT' can be added to by bitwise or: `DP_OSPARSE', which means it creates a database file as a sparse file. `bnum' specifies the number of elements of the bucket array. If it is not more than 0, the default value is specified. The size of a bucket array is determined on creating, and can not be changed except for by optimization of the database. Suggested size of a bucket array is about from 0.5 to 4 times of the number of all records to store. The return value is the database handle or `NULL' if it is not successful. While connecting as a writer, an exclusive lock is invoked to the database file. While connecting as a reader, a shared lock is invoked to the database file. The thread blocks until the lock is achieved. If `DP_ONOLCK' is used, the application is responsible for exclusion control.
+
+ +

The function `dpclose' is used in order to close a database handle.

+ +
+
int dpclose(DEPOT *depot);
+
`depot' specifies a database handle. If successful, the return value is true, else, it is false. Because the region of a closed handle is released, it becomes impossible to use the handle. Updating a database is assured to be written when the handle is closed. If a writer opens a database but does not close it appropriately, the database will be broken.
+
+ +

The function `dpput' is used in order to store a record.

+ +
+
int dpput(DEPOT *depot, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
+
`depot' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `dmode' specifies behavior when the key overlaps, by the following values: `DP_DOVER', which means the specified value overwrites the existing one, `DP_DKEEP', which means the existing value is kept, `DP_DCAT', which means the specified value is concatenated at the end of the existing value. If successful, the return value is true, else, it is false.
+
+ +

The function `dpout' is used in order to delete a record.

+ +
+
int dpout(DEPOT *depot, const char *kbuf, int ksiz);
+
`depot' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the specified key.
+
+ +

The function `dpget' is used in order to retrieve a record.

+ +
+
char *dpget(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, int *sp);
+
`depot' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `start' specifies the offset address of the beginning of the region of the value to be read. `max' specifies the max size to be read. If it is negative, the size to read is unlimited. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key or the size of the value of the corresponding record is less than `start'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `dpgetwb' is used in order to retrieve a record and write the value into a buffer.

+ +
+
int dpgetwb(DEPOT *depot, const char *kbuf, int ksiz, int start, int max, char *vbuf);
+
`depot' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `start' specifies the offset address of the beginning of the region of the value to be read. `max' specifies the max size to be read. It shuld be equal to or less than the size of the writing buffer. `vbuf' specifies the pointer to a buffer into which the value of the corresponding record is written. If successful, the return value is the size of the written data, else, it is -1. -1 is returned when no record corresponds to the specified key or the size of the value of the corresponding record is less than `start'. Note that no additional zero code is appended at the end of the region of the writing buffer.
+
+ +

The function `dpvsiz' is used in order to get the size of the value of a record.

+ +
+
int dpvsiz(DEPOT *depot, const char *kbuf, int ksiz);
+
`depot' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is the size of the value of the corresponding record, else, it is -1. Because this function does not read the entity of a record, it is faster than `dpget'.
+
+ +

The function `dpiterinit' is used in order to initialize the iterator of a database handle.

+ +
+
int dpiterinit(DEPOT *depot);
+
`depot' specifies a database handle. If successful, the return value is true, else, it is false. The iterator is used in order to access the key of every record stored in a database.
+
+ +

The function `dpiternext' is used in order to get the next key of the iterator.

+ +
+
char *dpiternext(DEPOT *depot, int *sp);
+
`depot' specifies a database handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record is to be get out of the iterator. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. It is possible to access every record by iteration of calling this function. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.
+
+ +

The function `dpsetalign' is used in order to set alignment of a database handle.

+ +
+
int dpsetalign(DEPOT *depot, int align);
+
`depot' specifies a database handle connected as a writer. `align' specifies the size of alignment. If successful, the return value is true, else, it is false. If alignment is set to a database, the efficiency of overwriting values is improved. The size of alignment is suggested to be average size of the values of the records to be stored. If alignment is positive, padding whose size is multiple number of the alignment is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not saved in a database, you should specify alignment every opening a database.
+
+ +

The function `dpsetfbpsiz' is used in order to set the size of the free block pool of a database handle.

+ +
+
int dpsetfbpsiz(DEPOT *depot, int size);
+
`depot' specifies a database handle connected as a writer. `size' specifies the size of the free block pool of a database. If successful, the return value is true, else, it is false. The default size of the free block pool is 16. If the size is greater, the space efficiency of overwriting values is improved with the time efficiency sacrificed.
+
+ +

The function `dpsync' is used in order to synchronize updating contents with the file and the device.

+ +
+
int dpsync(DEPOT *depot);
+
`depot' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. This function is useful when another process uses the connected database file.
+
+ +

The function `dpoptimize' is used in order to optimize a database.

+ +
+
int dpoptimize(DEPOT *depot, int bnum);
+
`depot' specifies a database handle connected as a writer. `bnum' specifies the number of the elements of the bucket array. If it is not more than 0, the default value is specified. If successful, the return value is true, else, it is false. In an alternating succession of deleting and storing with overwrite or concatenate, dispensable regions accumulate. This function is useful to do away with them.
+
+ +

The function `dpname' is used in order to get the name of a database.

+ +
+
char *dpname(DEPOT *depot);
+
`depot' specifies a database handle. If successful, the return value is the pointer to the region of the name of the database, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `dpfsiz' is used in order to get the size of a database file.

+ +
+
int dpfsiz(DEPOT *depot);
+
`depot' specifies a database handle. If successful, the return value is the size of the database file, else, it is -1.
+
+ +

The function `dpbnum' is used in order to get the number of the elements of the bucket array.

+ +
+
int dpbnum(DEPOT *depot);
+
`depot' specifies a database handle. If successful, the return value is the number of the elements of the bucket array, else, it is -1.
+
+ +

The function `dpbusenum' is used in order to get the number of the used elements of the bucket array.

+ +
+
int dpbusenum(DEPOT *depot);
+
`depot' specifies a database handle. If successful, the return value is the number of the used elements of the bucket array, else, it is -1. This function is inefficient because it accesses all elements of the bucket array.
+
+ +

The function `dprnum' is used in order to get the number of the records stored in a database.

+ +
+
int dprnum(DEPOT *depot);
+
`depot' specifies a database handle. If successful, the return value is the number of the records stored in the database, else, it is -1.
+
+ +

The function `dpwritable' is used in order to check whether a database handle is a writer or not.

+ +
+
int dpwritable(DEPOT *depot);
+
`depot' specifies a database handle. The return value is true if the handle is a writer, false if not.
+
+ +

The function `dpfatalerror' is used in order to check whether a database has a fatal error or not.

+ +
+
int dpfatalerror(DEPOT *depot);
+
`depot' specifies a database handle. The return value is true if the database has a fatal error, false if not.
+
+ +

The function `dpinode' is used in order to get the inode number of a database file.

+ +
+
int dpinode(DEPOT *depot);
+
`depot' specifies a database handle. The return value is the inode number of the database file.
+
+ +

The function `dpmtime' is used in order to get the last modified time of a database.

+ +
+
time_t dpmtime(DEPOT *depot);
+
`depot' specifies a database handle. The return value is the last modified time of the database.
+
+ +

The function `dpfdesc' is used in order to get the file descriptor of a database file.

+ +
+
int dpfdesc(DEPOT *depot);
+
`depot' specifies a database handle. The return value is the file descriptor of the database file. Handling the file descriptor of a database file directly is not suggested.
+
+ +

The function `dpremove' is used in order to remove a database file.

+ +
+
int dpremove(const char *name);
+
`name' specifies the name of a database file. If successful, the return value is true, else, it is false.
+
+ +

The function `dprepair' is used in order to repair a broken database file.

+ +
+
int dprepair(const char *name);
+
`name' specifies the name of a database file. If successful, the return value is true, else, it is false. There is no guarantee that all records in a repaired database file correspond to the original or expected state.
+
+ +

The function `dpexportdb' is used in order to dump all records as endian independent data.

+ +
+
int dpexportdb(DEPOT *depot, const char *name);
+
`depot' specifies a database handle. `name' specifies the name of an output file. If successful, the return value is true, else, it is false.
+
+ +

The function `dpimportdb' is used in order to load all records from endian independent data.

+ +
+
int dpimportdb(DEPOT *depot, const char *name);
+
`depot' specifies a database handle connected as a writer. The database of the handle must be empty. `name' specifies the name of an input file. If successful, the return value is true, else, it is false.
+
+ +

The function `dpsnaffle' is used in order to retrieve a record directly from a database file.

+ +
+
char *dpsnaffle(const char *name, const char *kbuf, int ksiz, int *sp);
+
`name' specifies the name of a database file. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Although this function can be used even while the database file is locked by another process, it is not assured that recent updated is reflected.
+
+ +

The function `dpinnerhash' is a hash function used inside Depot.

+ +
+
int dpinnerhash(const char *kbuf, int ksiz);
+
`kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. The return value is the hash value of 31 bits length computed from the key. This function is useful when an application calculates the state of the inside bucket array.
+
+ +

The function `dpouterhash' is a hash function which is independent from the hash functions used inside Depot.

+ +
+
int dpouterhash(const char *kbuf, int ksiz);
+
`kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. The return value is the hash value of 31 bits length computed from the key. This function is useful when an application uses its own hash algorithm outside Depot.
+
+ +

The function `dpprimenum' is used in order to get a natural prime number not less than a number.

+ +
+
int dpprimenum(int num);
+
`num' specified a natural number. The return value is a natural prime number not less than the specified number. This function is useful when an application determines the size of a bucket array of its own hash algorithm.
+
+ +

Examples

+ +

The following example stores and retrieves a phone number, using the name as the key.

+ +
#include <depot.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define NAME     "mikio"
+#define NUMBER   "000-1234-5678"
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  DEPOT *depot;
+  char *val;
+
+  /* open the database */
+  if(!(depot = dpopen(DBNAME, DP_OWRITER | DP_OCREAT, -1))){
+    fprintf(stderr, "dpopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* store the record */
+  if(!dpput(depot, NAME, -1, NUMBER, -1, DP_DOVER)){
+    fprintf(stderr, "dpput: %s\n", dperrmsg(dpecode));
+  }
+
+  /* retrieve the record */
+  if(!(val = dpget(depot, NAME, -1, 0, -1, NULL))){
+    fprintf(stderr, "dpget: %s\n", dperrmsg(dpecode));
+  } else {
+    printf("Name: %s\n", NAME);
+    printf("Number: %s\n", val);
+    free(val);
+  }
+
+  /* close the database */
+  if(!dpclose(depot)){
+    fprintf(stderr, "dpclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

The following example shows all records of the database.

+ +
#include <depot.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  DEPOT *depot;
+  char *key, *val;
+
+  /* open the database */
+  if(!(depot = dpopen(DBNAME, DP_OREADER, -1))){
+    fprintf(stderr, "dpopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* initialize the iterator */
+  if(!dpiterinit(depot)){
+    fprintf(stderr, "dpiterinit: %s\n", dperrmsg(dpecode));
+  }
+
+  /* scan with the iterator */
+  while((key = dpiternext(depot, NULL)) != NULL){
+    if(!(val = dpget(depot, key, -1, 0, -1, NULL))){
+      fprintf(stderr, "dpget: %s\n", dperrmsg(dpecode));
+      free(key);
+      break;
+    }
+    printf("%s: %s\n", key, val);
+    free(val);
+    free(key);
+  }
+
+  /* close the database */
+  if(!dpclose(depot)){
+    fprintf(stderr, "dpclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

Notes

+ +

For building a program using Depot, the program should be linked with a library file `libqdbm.a' or `libqdbm.so'. For example, the following command is executed to build `sample' from `sample.c'.

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

If QDBM was built with POSIX thread enabled, the global variable `dpecode' is treated as thread specific data, and functions of Depot are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.

+ +
+ +

Commands for Depot

+ +

Depot has the following command line interfaces.

+ +

The command `dpmgr' is a utility for debugging Depot and its applications. It features editing and checking of a database. It can be used for database applications with shell scripts. This command is used in the following format. `name' specifies a database name. `key' specifies the key of a record. `val' specifies the value of a record.

+ +
+
dpmgr create [-s] [-bnum num] name
+
Create a database file.
+
dpmgr put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat] [-na] name key val
+
Store a record with a key and a value.
+
dpmgr out [-kx|-ki] name key
+
Delete a record with a key.
+
dpmgr get [-nl] [-kx|-ki] [-start num] [-max num] [-ox] [-n] name key
+
Retrieve a record with a key and output it to the standard output.
+
dpmgr list [-nl] [-k|-v] [-ox] name
+
List all keys and values delimited with tab and line-feed to the standard output.
+
dpmgr optimize [-bnum num] [-na] name
+
Optimize a database.
+
dpmgr inform [-nl] name
+
Output miscellaneous information to the standard output.
+
dpmgr remove name
+
Remove a database file.
+
dpmgr repair name
+
Repair a broken database file.
+
dpmgr exportdb name file
+
Dump all records as endian independent data.
+
dpmgr importdb [-bnum num] name file
+
Load all records from endian independent data.
+
dpmgr snaffle [-kx|-ki] [-ox] [-n] name key
+
Retrieve a record from a locked database with a key and output it to the standard output.
+
dpmgr version
+
Output version information of QDBM to the standard output.
+
+ +

Options feature the following.

+ +
    +
  • -s : make the file sparse.
  • +
  • -bnum num : specify the number of the elements of the bucket array.
  • +
  • -kx : treat `key' as a binary expression of hexadecimal notation.
  • +
  • -ki : treat `key' as an integer expression of decimal notation.
  • +
  • -vx : treat `val' as a binary expression of hexadecimal notation.
  • +
  • -vi : treat `val' as an integer expression of decimal notation.
  • +
  • -vf : read the value from a file specified with `val'.
  • +
  • -keep : specify the storing mode for `DP_DKEEP'.
  • +
  • -cat : specify the storing mode for `DP_DCAT'.
  • +
  • -na : do not set alignment.
  • +
  • -nl : open the database without file locking.
  • +
  • -start : specify the beginning offset of a value to fetch.
  • +
  • -max : specify the max size of a value to fetch.
  • +
  • -ox : treat the output as a binary expression of hexadecimal notation.
  • +
  • -n : do not output the tailing newline.
  • +
  • -k : output keys only.
  • +
  • -v : output values only.
  • +
+ +

This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.

+ +

The command `dptest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `rnum' specifies the number of the records. `bnum' specifies the number of the elements of the bucket array. `pnum' specifies the number of patterns of the keys. `align' specifies the basic size of alignment. `fbpsiz' specifies the size of the free block pool.

+ +
+
dptest write [-s] name rnum bnum
+
Store records with keys of 8 bytes. They change as `00000001', `00000002'...
+
dptest read [-wb] name
+
Retrieve all records of the database above.
+
dptest rcat [-c] name rnum bnum pnum align fbpsiz
+
Store records with partway duplicated keys using concatenate mode.
+
dptest combo name
+
Perform combination test of various operations.
+
dptest wicked [-c] name rnum
+
Perform updating operations selected at random.
+
+ +

Options feature the following.

+ +
    +
  • -s : make the file sparse.
  • +
  • -wb : use the function `dpgetwb' instead of the function `dpget'.
  • +
  • -c : perform comparison test with map of Cabin.
  • +
+ +

This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.

+ +

The command `dptsv' features mutual conversion between a database of Depot and a TSV text. This command is useful when data exchange with another version of QDBM or another DBM, or when data exchange between systems which have different byte orders. This command is used in the following format. `name' specifies a database name. The subcommand `export' reads TSV data from the standard input. If a key overlaps, the latter is adopted. `-bnum' specifies the number of the elements of the bucket array. The subcommand `import' writes TSV data to the standard output.

+ +
+
dptsv import [-bnum num] [-bin] name
+
Create a database from TSV.
+
dptsv export [-bin] name
+
Write TSV data of a database.
+
+ +

Options feature the following.

+ +
    +
  • -bnum num : specify the number of the elements of the bucket array.
  • +
  • -bin : treat records as Base64 format.
  • +
+ +

This command returns 0 on success, another on failure.

+ +

Commands of Depot realize a simple database system. For example, to make a database to search `/etc/password' by a user name, perform the following command.

+ +
cat /etc/passwd | tr ':' '\t' | dptsv import casket
+
+ +

Thus, to retrieve the information of a user `mikio', perform the following command.

+ +
dpmgr get casket mikio
+
+ +

It is easy to implement functions upsides with these commands, using the API of Depot.

+ +
+ +

Curia: Extended API

+ +

Overview

+ +

Curia is the extended API of QDBM. It provides routines for managing multiple database files in a directory. Restrictions of some file systems that the size of each file is limited are escaped by dividing a database file into two or more. If the database files deploy on multiple devices, the scalability is improved.

+ +

Although Depot creates a database with a file name, Curia creates a database with a directory name. A database file named as `depot' is placed in the specified directory. Although it keeps the attribute of the database, it does not keep the entities of the records. Besides, sub directories are created by the number of division of the database, named with 4 digits. The database files are placed in the subdirectories. The entities of the records are stored in the database file. For example, in the case that a database directory named as `casket' and the number of division is 3, `casket/depot', `casket/0001/depot', `casket/0002/depot' and `casket/0003/depot' are created. No error occurs even if the namesake directory exists when creating a database. So, if sub directories exists and some devices are mounted on the sub directories, the database files deploy on the multiple devices.

+ +

Curia features managing large objects. Although usual records are stored in some database files, records of large objects are stored in individual files. Because the files of large objects are deployed in different directories named with the hash values, the access speed is part-way robust although it is slower than the speed of usual records. Large and not often accessed data should be secluded as large objects. By doing this, the access speed of usual records is improved. The directory hierarchies of large objects are placed in the directory named as `lob' in the sub directories of the database. Because the key spaces of the usual records and the large objects are different, the operations keep out of each other.

+ +

In order to use Curia, you should include `depot.h', `curia.h' and `stdlib.h' in the source files. Usually, the following description will be near the beginning of a source file.

+ +
+
#include <depot.h>
+
#include <curia.h>
+
#include <stdlib.h>
+
+ +

A pointer to `CURIA' is used as a database handle. It is like that some file I/O routines of `stdio.h' use a pointer to `FILE'. A database handle is opened with the function `cropen' and closed with `crclose'. You should not refer directly to any member of the handle. If a fatal error occurs in a database, any access method via the handle except `crclose' will not work and return error status. Although a process is allowed to use multiple database handles at the same time, handles of the same database directory should not be used.

+ +

Curia also assign the external variable `dpecode' with the error code. The function `dperrmsg' is used in order to get the message of the error code.

+ +

API

+ +

The function `cropen' is used in order to get a database handle.

+ +
+
CURIA *cropen(const char *name, int omode, int bnum, int dnum);
+
`name' specifies the name of a database directory. `omode' specifies the connection mode: `CR_OWRITER' as a writer, `CR_OREADER' as a reader. If the mode is `CR_OWRITER', the following may be added by bitwise or: `CR_OCREAT', which means it creates a new database if not exist, `CR_OTRUNC', which means it creates a new database regardless if one exists. Both of `CR_OREADER' and `CR_OWRITER' can be added to by bitwise or: `CR_ONOLCK', which means it opens a database directory without file locking, or `CR_OLCKNB', which means locking is performed without blocking. `CR_OCREAT' can be added to by bitwise or: `CR_OSPARSE', which means it creates database files as sparse files. `bnum' specifies the number of elements of each bucket array. If it is not more than 0, the default value is specified. The size of each bucket array is determined on creating, and can not be changed except for by optimization of the database. Suggested size of each bucket array is about from 0.5 to 4 times of the number of all records to store. `dnum' specifies the number of division of the database. If it is not more than 0, the default value is specified. The number of division can not be changed from the initial value. The max number of division is 512. The return value is the database handle or `NULL' if it is not successful. While connecting as a writer, an exclusive lock is invoked to the database directory. While connecting as a reader, a shared lock is invoked to the database directory. The thread blocks until the lock is achieved. If `CR_ONOLCK' is used, the application is responsible for exclusion control.
+
+ +

The function `crclose' is used in order to close a database handle.

+ +
+
int crclose(CURIA *curia);
+
`curia' specifies a database handle. If successful, the return value is true, else, it is false. Because the region of a closed handle is released, it becomes impossible to use the handle. Updating a database is assured to be written when the handle is closed. If a writer opens a database but does not close it appropriately, the database will be broken.
+
+ +

The function `crput' is used in order to store a record.

+ +
+
int crput(CURIA *curia, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
+
`curia' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `dmode' specifies behavior when the key overlaps, by the following values: `CR_DOVER', which means the specified value overwrites the existing one, `CR_DKEEP', which means the existing value is kept, `CR_DCAT', which means the specified value is concatenated at the end of the existing value. If successful, the return value is true, else, it is false.
+
+ +

The function `crout' is used in order to delete a record.

+ +
+
int crout(CURIA *curia, const char *kbuf, int ksiz);
+
`curia' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the specified key.
+
+ +

The function `crget' is used in order to retrieve a record.

+ +
+
char *crget(CURIA *curia, const char *kbuf, int ksiz, int start, int max, int *sp);
+
`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `start' specifies the offset address of the beginning of the region of the value to be read. `max' specifies the max size to be read. If it is negative, the size to read is unlimited. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key or the size of the value of the corresponding record is less than `start'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `crgetwb' is used in order to retrieve a record and write the value into a buffer.

+ +
+
int crgetwb(CURIA *curia, const char *kbuf, int ksiz, int start, int max, char *vbuf);
+
`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `start' specifies the offset address of the beginning of the region of the value to be read. `max' specifies the max size to be read. It shuld be equal to or less than the size of the writing buffer. `vbuf' specifies the pointer to a buffer into which the value of the corresponding record is written. If successful, the return value is the size of the written data, else, it is -1. -1 is returned when no record corresponds to the specified key or the size of the value of the corresponding record is less than `start'. Note that no additional zero code is appended at the end of the region of the writing buffer.
+
+ +

The function `crvsiz' is used in order to get the size of the value of a record.

+ +
+
int crvsiz(CURIA *curia, const char *kbuf, int ksiz);
+
`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is the size of the value of the corresponding record, else, it is -1. Because this function does not read the entity of a record, it is faster than `crget'.
+
+ +

The function `criterinit' is used in order to initialize the iterator of a database handle.

+ +
+
int criterinit(CURIA *curia);
+
`curia' specifies a database handle. If successful, the return value is true, else, it is false. The iterator is used in order to access the key of every record stored in a database.
+
+ +

The function `criternext' is used in order to get the next key of the iterator.

+ +
+
char *criternext(CURIA *curia, int *sp);
+
`curia' specifies a database handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record is to be get out of the iterator. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. It is possible to access every record by iteration of calling this function. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.
+
+ +

The function `crsetalign' is used in order to set alignment of a database handle.

+ +
+
int crsetalign(CURIA *curia, int align);
+
`curia' specifies a database handle connected as a writer. `align' specifies the size of alignment. If successful, the return value is true, else, it is false. If alignment is set to a database, the efficiency of overwriting values is improved. The size of alignment is suggested to be average size of the values of the records to be stored. If alignment is positive, padding whose size is multiple number of the alignment is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not saved in a database, you should specify alignment every opening a database.
+
+ +

The function `crsetfbpsiz' is used in order to set the size of the free block pool of a database handle.

+ +
+
int crsetfbpsiz(CURIA *curia, int size);
+
`curia' specifies a database handle connected as a writer. `size' specifies the size of the free block pool of a database. If successful, the return value is true, else, it is false. The default size of the free block pool is 16. If the size is greater, the space efficiency of overwriting values is improved with the time efficiency sacrificed.
+
+ +

The function `crsync' is used in order to synchronize updating contents with the files and the devices.

+ +
+
int crsync(CURIA *curia);
+
`curia' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. This function is useful when another process uses the connected database directory.
+
+ +

The function `croptimize' is used in order to optimize a database.

+ +
+
int croptimize(CURIA *curia, int bnum);
+
`curia' specifies a database handle connected as a writer. `bnum' specifies the number of the elements of each bucket array. If it is not more than 0, the default value is specified. In an alternating succession of deleting and storing with overwrite or concatenate, dispensable regions accumulate. This function is useful to do away with them.
+
+ +

The function `crname' is used in order to get the name of a database.

+ +
+
char *crname(CURIA *curia);
+
`curia' specifies a database handle. If successful, the return value is the pointer to the region of the name of the database, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `crfsiz' is used in order to get the total size of database files.

+ +
+
int crfsiz(CURIA *curia);
+
`curia' specifies a database handle. If successful, the return value is the total size of the database files, else, it is -1. If the total size is more than 2GB, the return value overflows.
+
+ +

The function `crfsizd' is used in order to get the total size of database files as double-precision floating-point number.

+ +
+
double crfsizd(CURIA *curia);
+
`curia' specifies a database handle. If successful, the return value is the total size of the database files, else, it is -1.0.
+
+ +

The function `crbnum' is used in order to get the total number of the elements of each bucket array.

+ +
+
int crbnum(CURIA *curia);
+
`curia' specifies a database handle. If successful, the return value is the total number of the elements of each bucket array, else, it is -1.
+
+ +

The function `crbusenum' is used in order to get the total number of the used elements of each bucket array.

+ +
+
int crbusenum(CURIA *curia);
+
`curia' specifies a database handle. If successful, the return value is the total number of the used elements of each bucket array, else, it is -1. This function is inefficient because it accesses all elements of each bucket array.
+
+ +

The function `crrnum' is used in order to get the number of the records stored in a database.

+ +
+
int crrnum(CURIA *curia);
+
`curia' specifies a database handle. If successful, the return value is the number of the records stored in the database, else, it is -1.
+
+ +

The function `crwritable' is used in order to check whether a database handle is a writer or not.

+ +
+
int crwritable(CURIA *curia);
+
`curia' specifies a database handle. The return value is true if the handle is a writer, false if not.
+
+ +

The function `crfatalerror' is used in order to check whether a database has a fatal error or not.

+ +
+
int crfatalerror(CURIA *curia);
+
`curia' specifies a database handle. The return value is true if the database has a fatal error, false if not.
+
+ +

The function `crinode' is used in order to get the inode number of a database directory.

+ +
+
int crinode(CURIA *curia);
+
`curia' specifies a database handle. The return value is the inode number of the database directory.
+
+ +

The function `crmtime' is used in order to get the last modified time of a database.

+ +
+
time_t crmtime(CURIA *curia);
+
`curia' specifies a database handle. The return value is the last modified time of the database.
+
+ +

The function `crremove' is used in order to remove a database directory.

+ +
+
int crremove(const char *name);
+
`name' specifies the name of a database directory. If successful, the return value is true, else, it is false.
+
+ +

The function `crrepair' is used in order to repair a broken database directory.

+ +
+
int crrepair(const char *name);
+
`name' specifies the name of a database directory. If successful, the return value is true, else, it is false. There is no guarantee that all records in a repaired database directory correspond to the original or expected state.
+
+ +

The function `crexportdb' is used in order to dump all records as endian independent data.

+ +
+
int crexportdb(CURIA *curia, const char *name);
+
`curia' specifies a database handle. `name' specifies the name of an output directory. If successful, the return value is true, else, it is false. Note that large objects are ignored.
+
+ +

The function `crimportdb' is used in order to load all records from endian independent data.

+ +
+
int crimportdb(CURIA *curia, const char *name);
+
`curia' specifies a database handle connected as a writer. The database of the handle must be empty. `name' specifies the name of an input directory. If successful, the return value is true, else, it is false. Note that large objects are ignored.
+
+ +

The function `crsnaffle' is used in order to retrieve a record directly from a database directory.

+ +
+
char *crsnaffle(const char *name, const char *kbuf, int ksiz, int *sp);
+
`name' specifies the name of a database directory. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Although this function can be used even while the database directory is locked by another process, it is not assured that recent updated is reflected.
+
+ +

The function `crputlob' is used in order to store a large object.

+ +
+
int crputlob(CURIA *curia, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
+
`curia' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `dmode' specifies behavior when the key overlaps, by the following values: `CR_DOVER', which means the specified value overwrites the existing one, `CR_DKEEP', which means the existing value is kept, `CR_DCAT', which means the specified value is concatenated at the end of the existing value. If successful, the return value is true, else, it is false.
+
+ +

The function `croutlob' is used in order to delete a large object.

+ +
+
int croutlob(CURIA *curia, const char *kbuf, int ksiz);
+
`curia' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true, else, it is false. false is returned when no large object corresponds to the specified key.
+
+ +

The function `crgetlob' is used in order to retrieve a large object.

+ +
+
char *crgetlob(CURIA *curia, const char *kbuf, int ksiz, int start, int max, int *sp);
+
`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `start' specifies the offset address of the beginning of the region of the value to be read. `max' specifies the max size to be read. If it is negative, the size to read is unlimited. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding large object, else, it is `NULL'. `NULL' is returned when no large object corresponds to the specified key or the size of the value of the corresponding large object is less than `start'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `crgetlobfd' is used in order to get the file descriptor of a large object.

+ +
+
int crgetlobfd(CURIA *curia, const char *kbuf, int ksiz);
+
`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is the file descriptor of the corresponding large object, else, it is -1. -1 is returned when no large object corresponds to the specified key. The returned file descriptor is opened with the `open' call. If the database handle was opened as a writer, the descriptor is writable (O_RDWR), else, it is not writable (O_RDONLY). The descriptor should be closed with the `close' call if it is no longer in use.
+
+ +

The function `crvsizlob' is used in order to get the size of the value of a large object.

+ +
+
int crvsizlob(CURIA *curia, const char *kbuf, int ksiz);
+
`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is the size of the value of the corresponding large object, else, it is -1. Because this function does not read the entity of a large object, it is faster than `crgetlob'.
+
+ +

The function `crrnumlob' is used in order to get the number of the large objects stored in a database.

+ +
+
int crrnumlob(CURIA *curia);
+
`curia' specifies a database handle. If successful, the return value is the number of the large objects stored in the database, else, it is -1.
+
+ +

Examples

+ +

The following example stores and retrieves a phone number, using the name as the key.

+ +
#include <depot.h>
+#include <curia.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define NAME     "mikio"
+#define NUMBER   "000-1234-5678"
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  CURIA *curia;
+  char *val;
+
+  /* open the database */
+  if(!(curia = cropen(DBNAME, CR_OWRITER | CR_OCREAT, -1, -1))){
+    fprintf(stderr, "cropen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* store the record */
+  if(!crput(curia, NAME, -1, NUMBER, -1, CR_DOVER)){
+    fprintf(stderr, "crput: %s\n", dperrmsg(dpecode));
+  }
+
+  /* retrieve the record */
+  if(!(val = crget(curia, NAME, -1, 0, -1, NULL))){
+    fprintf(stderr, "crget: %s\n", dperrmsg(dpecode));
+  } else {
+    printf("Name: %s\n", NAME);
+    printf("Number: %s\n", val);
+    free(val);
+  }
+
+  /* close the database */
+  if(!crclose(curia)){
+    fprintf(stderr, "crclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

The following example shows all records of the database.

+ +
#include <depot.h>
+#include <curia.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  CURIA *curia;
+  char *key, *val;
+
+  /* open the database */
+  if(!(curia = cropen(DBNAME, CR_OREADER, -1, -1))){
+    fprintf(stderr, "cropen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* initialize the iterator */
+  if(!criterinit(curia)){
+    fprintf(stderr, "criterinit: %s\n", dperrmsg(dpecode));
+  }
+
+  /* scan with the iterator */
+  while((key = criternext(curia, NULL)) != NULL){
+    if(!(val = crget(curia, key, -1, 0, -1, NULL))){
+      fprintf(stderr, "crget: %s\n", dperrmsg(dpecode));
+      free(key);
+      break;
+    }
+    printf("%s: %s\n", key, val);
+    free(val);
+    free(key);
+  }
+
+  /* close the iterator */
+  if(!crclose(curia)){
+    fprintf(stderr, "crclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

Notes

+ +

How to build programs using Curia is the same as the case of Depot.

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

If QDBM was built with POSIX thread enabled, the global variable `dpecode' is treated as thread specific data, and functions of Curia are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.

+ +
+ +

Commands for Curia

+ +

Curia has the following command line interfaces.

+ +

The command `crmgr' is a utility for debugging Curia and its applications. It features editing and checking of a database. It can be used for the database applications with shell scripts. This command is used in the following format. `name' specifies a database name. `key' specifies the key of a record. `val' specifies the value of a record.

+ +
+
crmgr create [-s] [-bnum num] [-dnum num] name
+
Create a database file.
+
crmgr put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat] [-lob] [-na] name key val
+
Store a record with a key and a value.
+
crmgr out [-kx|-ki] [-lob] name key
+
Delete a record with a key.
+
crmgr get [-nl] [-kx|-ki] [-start num] [-max num] [-ox] [-lob] [-n] name key
+
Retrieve a record with a key and output it to the standard output.
+
crmgr list [-nl] [-k|-v] [-ox] name
+
List all keys and values delimited with tab and line-feed to the standard output.
+
crmgr optimize [-bnum num] [-na] name
+
Optimize a database.
+
crmgr inform [-nl] name
+
Output miscellaneous information to the standard output.
+
crmgr remove name
+
Remove a database directory.
+
crmgr repair name
+
Repair a broken database directory.
+
crmgr exportdb name dir
+
Dump all records as endian independent data.
+
crmgr importdb [-bnum num] [-dnum num] name dir
+
Load all records from endian independent data.
+
crmgr snaffle [-kx|-ki] [-ox] [-n] name key
+
Retrieve a record from a locked database with a key and output it to the standard output.
+
crmgr version
+
Output version information of QDBM to the standard output.
+
+ +

Options feature the following.

+ +
    +
  • -s : make the files sparse.
  • +
  • -bnum num : specify the number of elements of each bucket array.
  • +
  • -dnum num : specify the number of division of the database.
  • +
  • -kx : treat `key' as a binary expression of hexadecimal notation.
  • +
  • -ki : treat `key' as an integer expression of decimal notation.
  • +
  • -vx : treat `val' as a binary expression of hexadecimal notation.
  • +
  • -vi : treat `val' as an integer expression of decimal notation.
  • +
  • -vf : read the value from a file specified with `val'.
  • +
  • -keep : specify the storing mode for `CR_DKEEP'.
  • +
  • -cat : specify the storing mode for `CR_DCAT'.
  • +
  • -na : do not set alignment.
  • +
  • -nl : open the database without file locking.
  • +
  • -start : specify the beginning offset of a value to fetch.
  • +
  • -max : specify the max size of a value to fetch.
  • +
  • -ox : treat the output as a binary expression of hexadecimal notation.
  • +
  • -lob : handle large objects.
  • +
  • -n : do not output the tailing newline.
  • +
  • -k : output keys only.
  • +
  • -v : output values only.
  • +
+ +

This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.

+ +

The command `crtest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `rnum' specifies the number of records. `bnum' specifies the number of elements of a bucket array. `dnum' specifies the number of division of a database. `pnum' specifies the number of patterns of the keys. `align' specifies the basic size of alignment. `fbpsiz' specifies the size of the free block pool.

+ +
+
crtest write [-s] [-lob] name rnum bnum dnum
+
Store records with keys of 8 bytes. They change as `00000001', `00000002'...
+
crtest read [-wb] [-lob] name
+
Retrieve all records of the database above.
+
crtest rcat [-c] name rnum bnum dnum pnum align fbpsiz
+
Store records with partway duplicated keys using concatenate mode.
+
crtest combo name
+
Perform combination test of various operations.
+
crtest wicked [-c] name rnum
+
Perform updating operations selected at random.
+
+ +

Options feature the following.

+ +
    +
  • -s : make the files sparse.
  • +
  • -lob : handle large objects.
  • +
  • -wb : use the function `crgetwb' instead of the function `crget'.
  • +
  • -c : perform comparison test with map of Cabin.
  • +
+ +

This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.

+ +

The command `crtsv' features mutual conversion between a database of Curia and a TSV text. This command is useful when data exchange with another version of QDBM or another DBM, or when data exchange between systems which have different byte orders. This command is used in the following format. `name' specifies a database name. The subcommand `export' reads TSV data from the standard input. If a key overlaps, the latter is adopted. `-bnum' specifies the number of the elements of the bucket array. `-dnum' specifies the number of division of the database. The subcommand `import' writes TSV data to the standard output.

+ +
+
crtsv import [-bnum num] [-dnum num] [-bin] name
+
Create a database from TSV.
+
crtsv export [-bin] name
+
Write TSV data of a database.
+
+ +

Options feature the following.

+ +
    +
  • -bnum num : specify the number of the elements of the bucket array.
  • +
  • -dnum num : specify the number of division of the database.
  • +
  • -bin : treat records as Base64 format.
  • +
+ +

This command returns 0 on success, another on failure.

+ +

Commands of Curia realize a simple database system. For example, to make a database to search `/etc/password' by a user name, perform the following command.

+ +
cat /etc/passwd | tr ':' '\t' | crtsv import casket
+
+ +

Thus, to retrieve the information of a user `mikio', perform the following command.

+ +
crmgr get casket mikio
+
+ +

It is easy to implement functions upsides with these commands, using the API of Curia.

+ +
+ +

Relic: NDBM-compatible API

+ +

Overview

+ +

Relic is the API which is compatible with NDBM. So, Relic wraps functions of Depot as API of NDBM. It is easy to port an application from NDBM to QDBM. In most cases, you should only replace the includings of `ndbm.h' with `relic.h' and replace the linking option `-lndbm' with `-lqdbm'.

+ +

The original NDBM treats a database as a pair of files. One, `a directory file', has a name with suffix `.dir' and stores a bit map of keys. The other, `a data file', has a name with suffix `.pag' and stores entities of each records. Relic creates the directory file as a mere dummy file and creates the data file as a database. Relic has no restriction about the size of each record. Relic can not handle database files made by the original NDBM.

+ +

In order to use Relic, you should include `relic.h', `stdlib.h', `sys/types.h', `sys/stat.h' and `fcntl.h' in the source files. Usually, the following description will be near the beginning of a source file.

+ +
+
#include <relic.h>
+
#include <stdlib.h>
+
#include <sys/types.h>
+
#include <sys/stat.h>
+
#include <fcntl.h>
+
+ +

A pointer to `DBM' is used as a database handle. A database handle is opened with the function `dbm_open' and closed with `dbm_close'. You should not refer directly to any member of a handle.

+ +

API

+ +

Structures of `datum' type is used in order to give and receive data of keys and values with functions of Relic.

+ +
+
typedef struct { void *dptr; size_t dsize; } datum;
+
`dptr' specifies the pointer to the region of a key or a value. `dsize' specifies the size of the region.
+
+ +

The function `dbm_open' is used in order to get a database handle.

+ +
+
DBM *dbm_open(char *name, int flags, int mode);
+
`name' specifies the name of a database. The file names are concatenated with suffixes. `flags' is the same as the one of `open' call, although `O_WRONLY' is treated as `O_RDWR' and additional flags except for `O_CREAT' and `O_TRUNC' have no effect. `mode' specifies the mode of the database file as the one of `open' call does. The return value is the database handle or `NULL' if it is not successful.
+
+ +

The function `dbm_close' is used in order to close a database handle.

+ +
+
void dbm_close(DBM *db);
+
`db' specifies a database handle. Because the region of the closed handle is released, it becomes impossible to use the handle.
+
+ +

The function `dbm_store' is used in order to store a record.

+ +
+
int dbm_store(DBM *db, datum key, datum content, int flags);
+
`db' specifies a database handle. `key' specifies a structure of a key. `content' specifies a structure of a value. `flags' specifies behavior when the key overlaps, by the following values: `DBM_REPLACE', which means the specified value overwrites the existing one, `DBM_INSERT', which means the existing value is kept. The return value is 0 if it is successful, 1 if it gives up because of overlaps of the key, -1 if other error occurs.
+
+ +

The function `dbm_delete' is used in order to delete a record.

+ +
+
int dbm_delete(DBM *db, datum key);
+
`db' specifies a database handle. `key' specifies a structure of a key. The return value is 0 if it is successful, -1 if some errors occur.
+
+ +

The function `dbm_fetch' is used in order to retrieve a record.

+ +
+
datum dbm_fetch(DBM *db, datum key);
+
`db' specifies a database handle. `key' specifies a structure of a key. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the value. If no record corresponds or some errors occur, `dptr' is `NULL'. `dptr' points to the region related with the handle. The region is available until the next time of calling this function with the same handle.
+
+ +

The function `dbm_firstkey' is used in order to get the first key of a database.

+ +
+
datum dbm_firstkey(DBM *db);
+
`db' specifies a database handle. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the first key. If no record corresponds or some errors occur, `dptr' is `NULL'. `dptr' points to the region related with the handle. The region is available until the next time of calling this function or the function `dbm_nextkey' with the same handle.
+
+ +

The function `dbm_nextkey' is used in order to get the next key of a database.

+ +
+
datum dbm_nextkey(DBM *db);
+
`db' specifies a database handle. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the next key. If no record corresponds or some errors occur, `dptr' is `NULL'. `dptr' points to the region related with the handle. The region is available until the next time of calling this function or the function `dbm_firstkey' with the same handle.
+
+ +

The function `dbm_error' is used in order to check whether a database has a fatal error or not.

+ +
+
int dbm_error(DBM *db);
+
`db' specifies a database handle. The return value is true if the database has a fatal error, false if not.
+
+ +

The function `dbm_clearerr' has no effect.

+ +
+
int dbm_clearerr(DBM *db);
+
`db' specifies a database handle. The return value is 0. The function is only for compatibility.
+
+ +

The function `dbm_rdonly' is used in order to check whether a handle is read-only or not.

+ +
+
int dbm_rdonly(DBM *db);
+
`db' specifies a database handle. The return value is true if the handle is read-only, or false if not read-only.
+
+ +

The function `dbm_dirfno' is used in order to get the file descriptor of a directory file.

+ +
+
int dbm_dirfno(DBM *db);
+
`db' specifies a database handle. The return value is the file descriptor of the directory file.
+
+ +

The function `dbm_pagfno' is used in order to get the file descriptor of a data file.

+ +
+
int dbm_pagfno(DBM *db);
+
`db' specifies a database handle. The return value is the file descriptor of the data file.
+
+ +

Examples

+ +

The following example stores and retrieves a phone number, using the name as the key.

+ +
#include <relic.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <string.h>
+
+#define NAME     "mikio"
+#define NUMBER   "000-1234-5678"
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  DBM *db;
+  datum key, val;
+  int i;
+
+  /* open the database */
+  if(!(db = dbm_open(DBNAME, O_RDWR | O_CREAT, 00644))){
+    perror("dbm_open");
+    return 1;
+  }
+
+  /* prepare the record */
+  key.dptr = NAME;
+  key.dsize = strlen(NAME);
+  val.dptr = NUMBER;
+  val.dsize = strlen(NUMBER);
+
+  /* store the record */
+  if(dbm_store(db, key, val, DBM_REPLACE) != 0){
+    perror("dbm_store");
+  }
+
+  /* retrieve the record */
+  val = dbm_fetch(db, key);
+  if(val.dptr){
+    printf("Name: %s\n", NAME);
+    printf("Number: ");
+    for(i = 0; i < val.dsize; i++){
+      putchar(((char *)val.dptr)[i]);
+    }
+    putchar('\n');
+  } else {
+    perror("dbm_fetch");
+  }
+
+  /* close the database */
+  dbm_close(db);
+
+  return 0;
+}
+
+ +

Notes

+ +

How to build programs using Relic is the same as the case of Depot. Note that an option to be given to a linker is not `-lndbm', but `-lqdbm'.

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

Functions of Relic are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.

+ +
+ +

Commands for Relic

+ +

Relic has the following command line interfaces.

+ +

The command `rlmgr' is a utility for debugging Relic and its applications. It features editing and checking of a database. It can be used for database applications with shell scripts. This command is used in the following format. `name' specifies a database name. `key' specifies the key of a record. `val' specifies the value of a record.

+ +
+
rlmgr create name
+
Create a database file.
+
rlmgr store [-kx] [-vx|-vf] [-insert] name key val
+
Store a record with a key and a value.
+
rlmgr delete [-kx] name key
+
Delete a record with a key.
+
rlmgr fetch [-kx] [-ox] [-n] name key
+
Retrieve a record with a key and output to the standard output.
+
rlmgr list [-ox] name
+
List all keys and values delimited with tab and line-feed to the standard output.
+
+ +

Options feature the following.

+ +
    +
  • -kx : treat `key' as a binary expression of hexadecimal notation.
  • +
  • -vx : treat `val' as a binary expression of hexadecimal notation.
  • +
  • -vf : read the value from a file specified with `val'.
  • +
  • -insert : specify the storing mode for `DBM_INSERT'.
  • +
  • -ox : treat the output as a binary expression of hexadecimal notation.
  • +
  • -n : do not output the tailing newline.
  • +
+ +

This command returns 0 on success, another on failure.

+ +

The command `rltest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `rnum' specifies the number of records.

+ +
+
rltest write name rnum
+
Store records with keys of 8 bytes. They change as `00000001', `00000002'...
+
rltest read name rnum
+
Retrieve records of the database above.
+
+ +

This command returns 0 on success, another on failure.

+ +
+ +

Hovel: GDBM-compatible API

+ +

Overview

+ +

Hovel is the API which is compatible with GDBM. So, Hovel wraps functions of Depot and Curia as API of GDBM. It is easy to port an application from GDBM to QDBM. In most cases, you should only replace the includings of `gdbm.h' with `hovel.h' and replace the linking option `-lgdbm' with `-lqdbm'. Hovel can not handle database files made by the original GDBM.

+ +

In order to use Hovel, you should include `hovel.h', `stdlib.h', `sys/types.h' and `sys/stat.h' in the source files. Usually, the following description will be near the beginning of a source file.

+ +
+
#include <hovel.h>
+
#include <stdlib.h>
+
#include <sys/types.h>
+
#include <sys/stat.h>
+
+ +

An object of `GDBM_FILE' is used as a database handle. A database handle is opened with the function `gdbm_open' and closed with `gdbm_close'. You should not refer directly to any member of a handle. Although Hovel works as a wrapper of Depot and handles a database file usually, if you use the function `gdbm_open2' to open the handle, it is possible to make behavior of a handle as a wrapper of Curia and treat a database directory.

+ +

API

+ +

Structures of `datum' type is used in order to give and receive data of keys and values with functions of Hovel.

+ +
+
typedef struct { char *dptr; size_t dsize; } datum;
+
`dptr' specifies the pointer to the region of a key or a value. `dsize' specifies the size of the region.
+
+ +

The external variable `gdbm_version' is the string containing the version information.

+ +
+
extern char *gdbm_version;
+
+ +

The external variable `gdbm_errno' is assigned with the last happened error code. Refer to `hovel.h' for details of the error codes.

+ +
+
extern gdbm_error gdbm_errno;
+
The initial value of this variable is `GDBM_NO_ERROR'. The other values are `GDBM_MALLOC_ERROR', `GDBM_BLOCK_SIZE_ERROR', `GDBM_FILE_OPEN_ERROR', `GDBM_FILE_WRITE_ERROR', `GDBM_FILE_SEEK_ERROR', `GDBM_FILE_READ_ERROR', `GDBM_BAD_MAGIC_NUMBER', `GDBM_EMPTY_DATABASE', `GDBM_CANT_BE_READER', `GDBM_CANT_BE_WRITER', `GDBM_READER_CANT_DELETE', `GDBM_READER_CANT_STORE', `GDBM_READER_CANT_REORGANIZE', `GDBM_UNKNOWN_UPDATE', `GDBM_ITEM_NOT_FOUND', `GDBM_REORGANIZE_FAILED', `GDBM_CANNOT_REPLACE', `GDBM_ILLEGAL_DATA', `GDBM_OPT_ALREADY_SET', and `GDBM_OPT_ILLEGAL'.
+
+ +

The function `gdbm_strerror' is used in order to get a message string corresponding to an error code.

+ +
+
char *gdbm_strerror(gdbm_error gdbmerrno);
+
`gdbmerrno' specifies an error code. The return value is the message string of the error code. The region of the return value is not writable.
+
+ +

The function `gdbm_open' is used in order to get a database handle after the fashion of GDBM.

+ +
+
GDBM_FILE gdbm_open(char *name, int block_size, int read_write, int mode, void (*fatal_func)(void));
+
`name' specifies the name of a database. `block_size' is ignored. `read_write' specifies the connection mode: `GDBM_READER' as a reader, `GDBM_WRITER', `GDBM_WRCREAT' and `GDBM_NEWDB' as a writer. `GDBM_WRCREAT' makes a database file or directory if it does not exist. `GDBM_NEWDB' makes a new database even if it exists. You can add the following to writer modes by bitwise or: `GDBM_SYNC', `GDBM_NOLOCK', `GDBM_LOCKNB', `GDBM_FAST', and `GDBM_SPARSE'. `GDBM_SYNC' means a database is synchronized after every updating method. `GDBM_NOLOCK' means a database is opened without file locking. `GDBM_LOCKNB' means file locking is performed without blocking. `GDBM_FAST' is ignored. `GDBM_SPARSE' is an original mode of QDBM and makes database a sparse file. `mode' specifies mode of a database file as the one of `open' call does. `fatal_func' is ignored. The return value is the database handle or `NULL' if it is not successful.
+
+ +

The function `gdbm_open2' is used in order to get a database handle after the fashion of QDBM.

+ +
+
GDBM_FILE gdbm_open2(char *name, int read_write, int mode, int bnum, int dnum, int align);
+
`name' specifies the name of a database. `read_write' specifies the connection mode: `GDBM_READER' as a reader, `GDBM_WRITER', `GDBM_WRCREAT' and `GDBM_NEWDB' as a writer. `GDBM_WRCREAT' makes a database file or directory if it does not exist. `GDBM_NEWDB' makes a new database even if it exists. You can add the following to writer modes by bitwise or: `GDBM_SYNC', `GDBM_NOLOCK', 'GDBM_LOCKNB', `GDBM_FAST', and `GDBM_SPARSE'. `GDBM_SYNC' means a database is synchronized after every updating method. `GDBM_NOLOCK' means a database is opened without file locking. `GDBM_LOCKNB' means file locking is performed without blocking. `GDBM_FAST' is ignored. `GDBM_SPARSE' is an original mode of QDBM and makes database sparse files. `mode' specifies a mode of a database file or a database directory as the one of `open' or `mkdir' call does. `bnum' specifies the number of elements of each bucket array. If it is not more than 0, the default value is specified. `dnum' specifies the number of division of the database. If it is not more than 0, the returning handle is created as a wrapper of Depot, else, it is as a wrapper of Curia. `align' specifies the basic size of alignment. The return value is the database handle or `NULL' if it is not successful. If the database already exists, whether it is one of Depot or Curia is measured automatically.
+
+ +

The function `gdbm_close' is used in order to close a database handle.

+ +
+
void gdbm_close(GDBM_FILE dbf);
+
`dbf' specifies a database handle. Because the region of the closed handle is released, it becomes impossible to use the handle.
+
+ +

The function `gdbm_store' is used in order to store a record.

+ +
+
int gdbm_store(GDBM_FILE dbf, datum key, datum content, int flag);
+
`dbf' specifies a database handle connected as a writer. `key' specifies a structure of a key. `content' specifies a structure of a value. `flag' specifies behavior when the key overlaps, by the following values: `GDBM_REPLACE', which means the specified value overwrites the existing one, `GDBM_INSERT', which means the existing value is kept. The return value is 0 if it is successful, 1 if it gives up because of overlaps of the key, -1 if other error occurs.
+
+ +

The function `gdbm_delete' is used in order to delete a record.

+ +
+
int gdbm_delete(GDBM_FILE dbf, datum key);
+
`dbf' specifies a database handle connected as a writer. `key' specifies a structure of a key. The return value is 0 if it is successful, -1 if some errors occur.
+
+ +

The function `gdbm_fetch' is used in order to retrieve a record.

+ +
+
datum gdbm_fetch(GDBM_FILE dbf, datum key);
+
`dbf' specifies a database handle. `key' specifies a structure of a key. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the value. If no record corresponds or some errors occur, `dptr' is `NULL'. Because the region pointed to by `dptr' is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `gdbm_exists' is used in order to check whether a record exists or not.

+ +
+
int gdbm_exists(GDBM_FILE dbf, datum key);
+
`dbf' specifies a database handle. `key' specifies a structure of a key. The return value is true if a record corresponds and no error occurs, or false, else, it is false.
+
+ +

The function `gdbm_firstkey' is used in order to get the first key of a database.

+ +
+
datum gdbm_firstkey(GDBM_FILE dbf);
+
`dbf' specifies a database handle. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the first key. If no record corresponds or some errors occur, `dptr' is `NULL'. Because the region pointed to by `dptr' is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `gdbm_nextkey' is used in order to get the next key of a database.

+ +
+
datum gdbm_nextkey(GDBM_FILE dbf, datum key);
+
`dbf' specifies a database handle. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the next key. If no record corresponds or some errors occur, `dptr' is `NULL'. Because the region pointed to by `dptr' is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `gdbm_sync' is used in order to synchronize updating contents with the file and the device.

+ +
+
void gdbm_sync(GDBM_FILE dbf);
+
`dbf' specifies a database handle connected as a writer.
+
+ +

The function `gdbm_reorganize' is used in order to reorganize a database.

+ +
+
int gdbm_reorganize(GDBM_FILE dbf);
+
`dbf' specifies a database handle connected as a writer. If successful, the return value is 0, else -1.
+
+ +

The function `gdbm_fdesc' is used in order to get the file descriptor of a database file.

+ +
+
int gdbm_fdesc(GDBM_FILE dbf);
+
`dbf' specifies a database handle connected as a writer. The return value is the file descriptor of the database file. If the database is a directory the return value is -1.
+
+ +

The function `gdbm_setopt' has no effect.

+ +
+
int gdbm_setopt(GDBM_FILE dbf, int option, int *value, int size);
+
`dbf' specifies a database handle. `option' is ignored. `size' is ignored. The return value is 0. The function is only for compatibility.
+
+ +

Examples

+ +

The following example stores and retrieves a phone number, using the name as the key.

+ +
#include <hovel.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <string.h>
+
+#define NAME     "mikio"
+#define NUMBER   "000-1234-5678"
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  GDBM_FILE dbf;
+  datum key, val;
+  int i;
+
+  /* open the database */
+  if(!(dbf = gdbm_open(DBNAME, 0, GDBM_WRCREAT, 00644, NULL))){
+    fprintf(stderr, "gdbm_open: %s\n", gdbm_strerror(gdbm_errno));
+    return 1;
+  }
+
+  /* prepare the record */
+  key.dptr = NAME;
+  key.dsize = strlen(NAME);
+  val.dptr = NUMBER;
+  val.dsize = strlen(NUMBER);
+
+  /* store the record */
+  if(gdbm_store(dbf, key, val, GDBM_REPLACE) != 0){
+    fprintf(stderr, "gdbm_store: %s\n", gdbm_strerror(gdbm_errno));
+  }
+
+  /* retrieve the record */
+  val = gdbm_fetch(dbf, key);
+  if(val.dptr){
+    printf("Name: %s\n", NAME);
+    printf("Number: ");
+    for(i = 0; i < val.dsize; i++){
+      putchar(val.dptr[i]);
+    }
+    putchar('\n');
+    free(val.dptr);
+  } else {
+    fprintf(stderr, "gdbm_fetch: %s\n", gdbm_strerror(gdbm_errno));
+  }
+
+  /* close the database */
+  gdbm_close(dbf);
+
+  return 0;
+}
+
+ +

Notes

+ +

How to build programs using Hovel is the same as the case of Depot. Note that an option to be given to a linker is not `-lgdbm', but `-lqdbm'.

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

If QDBM was built with POSIX thread enabled, the global variable `gdbm_errno' is treated as thread specific data, and functions of Hovel are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.

+ +
+ +

Commands for Hovel

+ +

Hovel has the following command line interfaces.

+ +

The command `hvmgr' is a utility for debugging Hovel and its applications. It features editing and checking of a database. It can be used for database applications with shell scripts. This command is used in the following format. `name' specifies a database name. `key' specifies the key of a record. `val' specifies the value of a record.

+ +
+
hvmgr create [-qdbm bnum dnum] [-s] name
+
Create a database file.
+
hvmgr store [-qdbm] [-kx] [-vx|-vf] [-insert] name key val
+
Store a record with a key and a value.
+
hvmgr delete [-qdbm] [-kx] name key
+
Delete a record with a key.
+
hvmgr fetch [-qdbm] [-kx] [-ox] [-n] name key
+
Retrieve a record with a key and output to the standard output.
+
hvmgr list [-qdbm] [-ox] name
+
List all keys and values delimited with tab and line-feed to the standard output.
+
hvmgr optimize [-qdbm] name
+
Optimize a database.
+
+ +

Options feature the following.

+ +
    +
  • -qdbm [bnum dnum] : use `gdbm_open2' to open the database. `bnum' specifies the number of the elements of the bucket array. `dnum' specifies the number of division of the database.
  • +
  • -s : make the file sparse.
  • +
  • -kx : treat `key' as a binary expression of hexadecimal notation.
  • +
  • -vx : treat `val' as a binary expression of hexadecimal notation.
  • +
  • -vf : read the value from a file specified with `val'.
  • +
  • -insert : specify the storing mode for `GDBM_INSERT'.
  • +
  • -ox : treat the output as a binary expression of hexadecimal notation.
  • +
  • -n : do not output the trailing newline.
  • +
+ +

This command returns 0 on success, another on failure.

+ +

The command `hvtest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `rnum' specifies the number of records.

+ +
+
hvtest write [-qdbm] [-s] name rnum
+
Store records with keys of 8 bytes. They changes as `00000001', `00000002'...
+
hvtest read [-qdbm] name rnum
+
Retrieve records of the database above.
+
+ +

Options feature the following.

+ +
    +
  • -qdbm : use `gdbm_open2' and open the handle as Curia.
  • +
  • -s : make the file sparse.
  • +
+ +

This command returns 0 on success, another on failure.

+ +
+ +

Cabin: Utility API

+ +

Overview

+ +

Cabin is the utility API which provides memory allocating functions, sorting functions, extensible datum, array list, hash map, heap array, and so on for handling records easily on memory. This API features also parsing MIME, CSV, and XML, and features various types of encoding and decoding.

+ +

In order to use Cabin, you should include `cabin.h' and `stdlib.h' in the source files. Usually, the following description will be near the beginning of a source file.

+ +
+
#include <cabin.h>
+
#include <stdlib.h>
+
+ +

A pointer to `CBDATUM' is used as a handle of an extensible datum. A datum handle is opened with the function `cbdatumopen' and closed with `cbdatumclose'. A pointer to `CBLIST' is used as a handle of an array list. A list handle is opened with the function `cblistopen' and closed with `cblistclose'. A pointer to `CBMAP' is used as a handle of a hash map. A map handle is opened with the function `cbmapopen' and closed with `cbmapclose'. A pointer to `CBHEAP' is used as a handle of a heap array. A heap handle is opened with the function `cbheapopen' and closed with `cbheapclose'. You should not refer directly to any member of each handles.

+ +

API

+ +

The external variable `cbfatalfunc' is the pointer to call back function for handling a fatal error.

+ +
+
extern void (*cbfatalfunc)(const char *);
+
The argument specifies the error message. The initial value of this variable is `NULL'. If the value is `NULL', the default function is called when a fatal error occurs. A fatal error occurs when memory allocation is failed.
+
+ +

The function `cbmalloc' is used in order to allocate a region on memory.

+ +
+
void *cbmalloc(size_t size);
+
`size' specifies the size of the region. The return value is the pointer to the allocated region. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbrealloc' is used in order to re-allocate a region on memory.

+ +
+
void *cbrealloc(void *ptr, size_t size);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. The return value is the pointer to the re-allocated region. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbmemdup' is used in order to duplicate a region on memory.

+ +
+
char *cbmemdup(const char *ptr, int size);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the pointer to the allocated region of the duplicate. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbfree' is used in order to free a region on memory.

+ +
+
void cbfree(void *ptr);
+
`ptr' specifies the pointer to a region. If it is `NULL', this function has no effect. Although this function is just a wrapper of `free' call, this is useful in applications using another package of the `malloc' series.
+
+ +

The function `cbglobalgc' is used in order to register the pointer or handle of an object to the global garbage collector.

+ +
+
void cbglobalgc(void *ptr, void (*func)(void *));
+
`ptr' specifies the pointer or handle of an object. `func' specifies the pointer to a function to release resources of the object. Its argument is the pointer or handle of the object to release. This function assures that resources of an object are released when the process exits normally by returning from the `main' function or calling the `exit' function.
+
+ +

The function `cbggcsweep' is used in order to exercise the global garbage collector explicitly.

+ +
+
void cbggcsweep(void);
+
Note that you should not use objects registered to the global garbage collector any longer after calling this function. Because the global garbage collector is initialized and you can register new objects into it.
+
+ +

The function `cbvmemavail' is used in order to check availability of allocation of the virtual memory.

+ +
+
int cbvmemavail(size_t size);
+
`size' specifies the size of region to be allocated newly. The return value is true if allocation should be success, or false if not.
+
+ +

The function `cbisort' is used in order to sort an array using insert sort.

+ +
+
void cbisort(void *base, int nmemb, int size, int(*compar)(const void *, const void *));
+
`base' specifies the pointer to an array. `nmemb' specifies the number of elements of the array. `size' specifies the size of each element. `compar' specifies the pointer to comparing function. The two arguments specify the pointers of elements. The comparing function should returns positive if the former is big, negative if the latter is big, 0 if both are equal. Insert sort is useful only if most elements have been sorted already.
+
+ +

The function `cbssort' is used in order to sort an array using shell sort.

+ +
+
void cbssort(void *base, int nmemb, int size, int(*compar)(const void *, const void *));
+
`base' specifies the pointer to an array. `nmemb' specifies the number of elements of the array. `size' specifies the size of each element. `compar' specifies the pointer to comparing function. The two arguments specify the pointers of elements. The comparing function should returns positive if the former is big, negative if the latter is big, 0 if both are equal. If most elements have been sorted, shell sort may be faster than heap sort or quick sort.
+
+ +

The function `cbhsort' is used in order to sort an array using heap sort.

+ +
+
void cbhsort(void *base, int nmemb, int size, int(*compar)(const void *, const void *));
+
`base' specifies the pointer to an array. `nmemb' specifies the number of elements of the array. `size' specifies the size of each element. `compar' specifies the pointer to comparing function. The two arguments specify the pointers of elements. The comparing function should returns positive if the former is big, negative if the latter is big, 0 if both are equal. Although heap sort is robust against bias of input, quick sort is faster in most cases.
+
+ +

The function `cbqsort' is used in order to sort an array using quick sort.

+ +
+
void cbqsort(void *base, int nmemb, int size, int(*compar)(const void *, const void *));
+
`base' specifies the pointer to an array. `nmemb' specifies the number of elements of the array. `size' specifies the size of each element. `compar' specifies the pointer to comparing function. The two arguments specify the pointers of elements. The comparing function should returns positive if the former is big, negative if the latter is big, 0 if both are equal. Being sensitive to bias of input, quick sort is the fastest sorting algorithm.
+
+ +

The function `cbstricmp' is used in order to compare two strings with case insensitive evaluation.

+ +
+
int cbstricmp(const char *astr, const char *bstr);
+
`astr' specifies the pointer of one string. `astr' specifies the pointer of the other string. The return value is positive if the former is big, negative if the latter is big, 0 if both are equivalent. Upper cases and lower cases of alphabets in ASCII code are not distinguished.
+
+ +

The function `cbstrfwmatch' is used in order to check whether a string begins with a key.

+ +
+
int cbstrfwmatch(const char *str, const char *key);
+
`str' specifies the pointer of a target string. `key' specifies the pointer of a forward matching key string. The return value is true if the target string begins with the key, else, it is false.
+
+ +

The function `cbstrfwimatch' is used in order to check whether a string begins with a key, with case insensitive evaluation.

+ +
+
int cbstrfwimatch(const char *str, const char *key);
+
`str' specifies the pointer of a target string. `key' specifies the pointer of a forward matching key string. The return value is true if the target string begins with the key, else, it is false. Upper cases and lower cases of alphabets in ASCII code are not distinguished.
+
+ +

The function `cbstrbwmatch' is used in order to check whether a string ends with a key.

+ +
+
int cbstrbwmatch(const char *str, const char *key);
+
`str' specifies the pointer of a target string. `key' specifies the pointer of a backward matching key string. The return value is true if the target string ends with the key, else, it is false.
+
+ +

The function `cbstrbwimatch' is used in order to check whether a string ends with a key, with case insensitive evaluation.

+ +
+
int cbstrbwimatch(const char *str, const char *key);
+
`str' specifies the pointer of a target string. `key' specifies the pointer of a backward matching key string. The return value is true if the target string ends with the key, else, it is false. Upper cases and lower cases of alphabets in ASCII code are not distinguished.
+
+ +

The function `cbstrstrkmp' is used in order to locate a substring in a string using KMP method.

+ +
+
char *cbstrstrkmp(const char *haystack, const char *needle);
+
`haystack' specifies the pointer of a target string. `needle' specifies the pointer of a substring to be found. The return value is the pointer to the beginning of the substring or `NULL' if the substring is not found. In most cases, `strstr' as a built-in function of the compiler is faster than this function.
+
+ +

The function `cbstrstrkmp' is used in order to locate a substring in a string using BM method.

+ +
+
char *cbstrstrbm(const char *haystack, const char *needle);
+
`haystack' specifies the pointer of a target string. `needle' specifies the pointer of a substring to be found. The return value is the pointer to the beginning of the substring or `NULL' if the substring is not found. In most cases, `strstr' as a built-in function of the compiler is faster than this function.
+
+ +

The function `cbstrtoupper' is used in order to convert the letters of a string to upper case.

+ +
+
char *cbstrtoupper(char *str);
+
`str' specifies the pointer of a string to convert. The return value is the pointer to the string.
+
+ +

The function `cbstrtolower' is used in order to convert the letters of a string to lower case.

+ +
+
char *cbstrtolower(char *str);
+
`str' specifies the pointer of a string to convert. The return value is the pointer to the string.
+
+ +

The function `cbstrtrim' is used in order to cut space characters at head or tail of a string.

+ +
+
char *cbstrtrim(char *str);
+
`str' specifies the pointer of a string to convert. The return value is the pointer to the string.
+
+ +

The function `cbstrsqzspc' is used in order to squeeze space characters in a string and trim it.

+ +
+
char *cbstrsqzspc(char *str);
+
`str' specifies the pointer of a string to convert. The return value is the pointer to the string.
+
+ +

The function `cbstrcountutf' is used in order to count the number of characters in a string of UTF-8.

+ +
+
int cbstrcountutf(const char *str);
+
`str' specifies the pointer of a string of UTF-8. The return value is the number of characters in the string.
+
+ +

The function `cbstrcututf' is used in order to cut a string of UTF-8 at the specified number of characters.

+ +
+
char *cbstrcututf(char *str, int num);
+
`str' specifies the pointer of a string of UTF-8. `num' specifies the number of characters to be kept. The return value is the pointer to the string.
+
+ +

The function `cbdatumopen' is used in order to get a datum handle.

+ +
+
CBDATUM *cbdatumopen(const char *ptr, int size);
+
`ptr' specifies the pointer to the region of the initial content. If it is `NULL', an empty datum is created. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is a datum handle.
+
+ +

The function `cbdatumdup' is used in order to copy a datum.

+ +
+
CBDATUM *cbdatumdup(const CBDATUM *datum);
+
`datum' specifies a datum handle. The return value is a new datum handle.
+
+ +

The function `cbdatumclose' is used in order to free a datum handle.

+ +
+
void cbdatumclose(CBDATUM *datum);
+
`datum' specifies a datum handle. Because the region of a closed handle is released, it becomes impossible to use the handle.
+
+ +

The function `cbdatumcat' is used in order to concatenate a datum and a region.

+ +
+
void cbdatumcat(CBDATUM *datum, const char *ptr, int size);
+
`datum' specifies a datum handle. `ptr' specifies the pointer to the region to be appended. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'.
+
+ +

The function `cbdatumptr' is used in order to get the pointer of the region of a datum.

+ +
+
const char *cbdatumptr(const CBDATUM *datum);
+
`datum' specifies a datum handle. The return value is the pointer of the region of a datum. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.
+
+ +

The function `cbdatumsize' is used in order to get the size of the region of a datum.

+ +
+
int cbdatumsize(const CBDATUM *datum);
+
`datum' specifies a datum handle. The return value is the size of the region of a datum.
+
+ +

The function `cbdatumsetsize' is used in order to change the size of the region of a datum.

+ +
+
void cbdatumsetsize(CBDATUM *datum, int size);
+
`datum' specifies a datum handle. `size' specifies the new size of the region. If the new size is bigger than the one of old, the surplus region is filled with zero codes.
+
+ +

The function `cbdatumprintf' is used in order to perform formatted output into a datum.

+ +
+
void cbdatumprintf(CBDATUM *datum, const char *format, ...);
+
`format' specifies a printf-like format string. The conversion character `%' can be used with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@', `?', `:', `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as with `s' but escapes meta characters of URL. `:' works as with `s' but performs MIME encoding as UTF-8. The other conversion character work as with each original.
+
+ +

The function `cbdatumtomalloc' is used in order to convert a datum to an allocated region.

+ +
+
char *cbdatumtomalloc(CBDATUM *datum, int *sp);
+
`datum' specifies a datum handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the datum. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Because the region of the original datum is released, it should not be released again.
+
+ +

The function `cblistopen' is used in order to get a list handle.

+ +
+
CBLIST *cblistopen(void);
+
The return value is a list handle.
+
+ +

The function `cblistdup' is used in order to copy a list.

+ +
+
CBLIST *cblistdup(const CBLIST *list);
+
`list' specifies a list handle. The return value is a new list handle.
+
+ +

The function `cblistclose' is used in order to close a list handle.

+ +
+
void cblistclose(CBLIST *list);
+
`list' specifies a list handle. Because the region of a closed handle is released, it becomes impossible to use the handle.
+
+ +

The function `cblistnum' is used in order to get the number of elements of a list.

+ +
+
int cblistnum(const CBLIST *list);
+
`list' specifies a list handle. The return value is the number of elements of the list.
+
+ +

The function `cblistval' is used in order to get the pointer to the region of an element of a list.

+ +
+
const char *cblistval(const CBLIST *list, int index, int *sp);
+
`list' specifies a list handle. `index' specifies the index of an element. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the element. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. If `index' is equal to or more than the number of elements, the return value is `NULL'.
+
+ +

The function `cblistpush' is used in order to add an element at the end of a list.

+ +
+
void cblistpush(CBLIST *list, const char *ptr, int size);
+
`list' specifies a list handle. `ptr' specifies the pointer to the region of an element. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'.
+
+ +

The function `cblistpop' is used in order to remove an element of the end of a list.

+ +
+
char *cblistpop(CBLIST *list, int *sp);
+
`list' specifies a list handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the value. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. If the list is empty, the return value is `NULL'.
+
+ +

The function `cblistunshift' is used in order to add an element at the top of a list.

+ +
+
void cblistunshift(CBLIST *list, const char *ptr, int size);
+
`list' specifies a list handle. `ptr' specifies the pointer to the region of an element. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'.
+
+ +

The function `cblistshift' is used in order to remove an element of the top of a list.

+ +
+
char *cblistshift(CBLIST *list, int *sp);
+
`list' specifies a list handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the value. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. If the list is empty, the return value is `NULL'.
+
+ +

The function `cblistinsert' is used in order to add an element at the specified location of a list.

+ +
+
void cblistinsert(CBLIST *list, int index, const char *ptr, int size);
+
`list' specifies a list handle. `index' specifies the index of an element. `ptr' specifies the pointer to the region of the element. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'.
+
+ +

The function `cblistremove' is used in order to remove an element at the specified location of a list.

+ +
+
char *cblistremove(CBLIST *list, int index, int *sp);
+
`list' specifies a list handle. `index' specifies the index of an element. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the value. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. If `index' is equal to or more than the number of elements, no element is removed and the return value is `NULL'.
+
+ +

The function `cblistover' is used in order to overwrite an element at the specified location of a list.

+ +
+
void cblistover(CBLIST *list, int index, const char *ptr, int size);
+
`list' specifies a list handle. `index' specifies the index of an element. `ptr' specifies the pointer to the region of the new content. `size' specifies the size of the new content. If it is negative, the size is assigned with `strlen(ptr)'. If `index' is equal to or more than the number of elements, this function has no effect.
+
+ +

The function `cblistsort' is used in order to sort elements of a list in lexical order.

+ +
+
void cblistsort(CBLIST *list);
+
`list' specifies a list handle. Quick sort is used for sorting.
+
+ +

The function `cblistlsearch' is used in order to search a list for an element using liner search.

+ +
+
int cblistlsearch(const CBLIST *list, const char *ptr, int size);
+
`list' specifies a list handle. `ptr' specifies the pointer to the region of a key. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the index of a corresponding element or -1 if there is no corresponding element. If two or more elements corresponds, the former returns.
+
+ +

The function `cblistbsearch' is used in order to search a list for an element using binary search.

+ +
+
int cblistbsearch(const CBLIST *list, const char *ptr, int size);
+
`list' specifies a list handle. It should be sorted in lexical order. `ptr' specifies the pointer to the region of a key. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the index of a corresponding element or -1 if there is no corresponding element. If two or more elements corresponds, which returns is not defined.
+
+ +

The function `cblistdump' is used in order to serialize a list into a byte array.

+ +
+
char *cblistdump(const CBLIST *list, int *sp);
+
`list' specifies a list handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. The return value is the pointer to the region of the result serial region. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cblistload' is used in order to redintegrate a serialized list.

+ +
+
CBLIST *cblistload(const char *ptr, int size);
+
`ptr' specifies the pointer to a byte array. `size' specifies the size of the region. The return value is a new list handle.
+
+ +

The function `cbmapopen' is used in order to get a map handle.

+ +
+
CBMAP *cbmapopen(void);
+
The return value is a map handle.
+
+ +

The function `cbmapdup' is used in order to copy a map.

+ +
+
CBMAP *cbmapdup(CBMAP *map);
+
`map' specifies a map handle. The return value is a new map handle. The iterator of the source map is initialized.
+
+ +

The function `cbmapclose' is used in order to close a map handle.

+ +
+
void cbmapclose(CBMAP *map);
+
`map' specifies a map handle. Because the region of a closed handle is released, it becomes impossible to use the handle.
+
+ +

The function `cbmapput' is used in order to store a record into a map.

+ +
+
int cbmapput(CBMAP *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int over);
+
`map' specifies a map handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `over' specifies whether the value of the duplicated record is overwritten or not. If `over' is false and the key duplicated, the return value is false, else, it is true.
+
+ +

The function `cbmapputcat' is used in order to concatenate a value at the end of the value of the existing record.

+ +
+
void cbmapputcat(CBMAP *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz);
+
`map' specifies a map handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. If there is no corresponding record, a new record is created.
+
+ +

The function `cbmapout' is used in order to delete a record of a map.

+ +
+
int cbmapout(CBMAP *map, const char *kbuf, int ksiz);
+
`map' specifies a map handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true. False is returned when no record corresponds to the specified key.
+
+ +

The function `cbmapget' is used in order to retrieve a record of a map.

+ +
+
const char *cbmapget(const CBMAP *map, const char *kbuf, int ksiz, int *sp);
+
`map' specifies a map handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when no record corresponds. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.
+
+ +

The function `cbmapmove' is used in order to move a record to the edge of a map.

+ +
+
int cbmapmove(CBMAP *map, const char *kbuf, int ksiz, int head);
+
`map' specifies a map handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `head' specifies the destination which is head if it is true or tail if else. If successful, the return value is true. False is returned when no record corresponds to the specified key.
+
+ +

The function `cbmapiterinit' is used in order to initialize the iterator of a map.

+ +
+
void cbmapiterinit(CBMAP *map);
+
`map' specifies a map handle. The iterator is used in order to access the key of every record stored in a map.
+
+ +

The function `cbmapiternext' is used in order to get the next key of the iterator of a map.

+ +
+
const char *cbmapiternext(CBMAP *map, int *sp);
+
`map' specifies a map handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record is to be get out of the iterator. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. The order of iteration is assured to be the same of the one of storing.
+
+ +

The function `cbmapiterval' is used in order to get the value binded to the key fetched from the iterator of a map.

+ +
+
const char *cbmapiterval(const char *kbuf, int *sp);
+
`kbuf' specifies the pointer to the region of a iteration key. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the value of the corresponding record. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.
+
+ +

The function `cbmaprnum' is used in order to get the number of the records stored in a map.

+ +
+
int cbmaprnum(const CBMAP *map);
+
`map' specifies a map handle. The return value is the number of the records stored in the map.
+
+ +

The function `cbmapkeys' is used in order to get the list handle contains all keys in a map.

+ +
+
CBLIST *cbmapkeys(CBMAP *map);
+
`map' specifies a map handle. The return value is the list handle contains all keys in the map. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.
+
+ +

The function `cbmapvals' is used in order to get the list handle contains all values in a map.

+ +
+
CBLIST *cbmapvals(CBMAP *map);
+
`map' specifies a map handle. The return value is the list handle contains all values in the map. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.
+
+ +

The function `cbmapdump' is used in order to serialize a map into a byte array.

+ +
+
char *cbmapdump(const CBMAP *map, int *sp);
+
`map' specifies a map handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. The return value is the pointer to the region of the result serial region. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbmapload' is used in order to redintegrate a serialized map.

+ +
+
CBMAP *cbmapload(const char *ptr, int size);
+
`ptr' specifies the pointer to a byte array. `size' specifies the size of the region. The return value is a new map handle.
+
+ +

The function `cbmaploadone' is used in order to extract a record from a serialized map.

+ +
+
char *cbmaploadone(const char *ptr, int size, const char *kbuf, int ksiz, int *sp);
+
`ptr' specifies the pointer to a byte array. `size' specifies the size of the region. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when no record corresponds. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.
+
+ + +

The function `cbheapopen' is used in order to get a heap handle.

+ +
+
CBHEAP *cbheapopen(int size, int max, int(*compar)(const void *, const void *));
+
`size' specifies the size of each record. `max' specifies the maximum number of records in the heap. `compar' specifies the pointer to comparing function. The two arguments specify the pointers of records. The comparing function should returns positive if the former is big, negative if the latter is big, 0 if both are equal. The return value is a heap handle.
+
+ +

The function `cbheapdup' is used in order to copy a heap.

+ +
+
CBHEAP *cbheapdup(CBHEAP *heap);
+
`heap' specifies a heap handle. The return value is a new heap handle.
+
+ +

The function `cbheapclose' is used in order to close a heap handle.

+ +
+
void cbheapclose(CBHEAP *heap);
+
`heap' specifies a heap handle. Because the region of a closed handle is released, it becomes impossible to use the handle.
+
+ +

The function `cbheapnum' is used in order to get the number of the records stored in a heap.

+ +
+
int cbheapnum(CBHEAP *heap);
+
`heap' specifies a heap handle. The return value is the number of the records stored in the heap.
+
+ +

The function `cbheapinsert' is used in order to insert a record into a heap.

+ +
+
int cbheapinsert(CBHEAP *heap, const void *ptr);
+
`heap' specifies a heap handle. `ptr' specifies the pointer to the region of a record. The return value is true if the record is added, else false. If the new record is bigger than the biggest existing regord, the new record is not added. If the new record is added and the number of records exceeds the maximum number, the biggest existing record is removed.
+
+ +

The function `cbheapval' is used in order to get the pointer to the region of a record in a heap.

+ +
+
void *cbheapval(CBHEAP *heap, int index);
+
`heap' specifies a heap handle. `index' specifies the index of a record. The return value is the pointer to the region of the record. If `index' is equal to or more than the number of records, the return value is `NULL'. Note that records are organized by the nagative order the comparing function.
+
+ +

The function `cbheaptomalloc' is used in order to convert a heap to an allocated region.

+ +
+
void *cbheaptomalloc(CBHEAP *heap, int *np);
+
`heap' specifies a heap handle. `np' specifies the pointer to a variable to which the number of records of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the heap. Records are sorted. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Because the region of the original heap is released, it should not be released again.
+
+ +

The function `cbsprintf' is used in order to allocate a formatted string on memory.

+ +
+
char *cbsprintf(const char *format, ...);
+
`format' specifies a printf-like format string. The conversion character `%' can be used with such flag characters as `d', `o', `u', `x', `X', `e', `E', `f', `g', `G', `c', `s', and `%'. Specifiers of the field length and the precision can be put between the conversion characters and the flag characters. The specifiers consist of decimal characters, `.', `+', `-', and the space character. The other arguments are used according to the format string. The return value is the pointer to the allocated region of the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbreplace' is used in order to replace some patterns in a string.

+ +
+
char *cbreplace(const char *str, CBMAP *pairs);
+
`str' specifies the pointer to a source string. `pairs' specifies the handle of a map composed of pairs of replacement. The key of each pair specifies a pattern before replacement and its value specifies the pattern after replacement. The return value is the pointer to the allocated region of the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbsplit' is used in order to make a list by splitting a serial datum.

+ +
+
CBLIST *cbsplit(const char *ptr, int size, const char *delim);
+
`ptr' specifies the pointer to the region of the source content. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `delim' specifies a string containing delimiting characters. If it is `NULL', zero code is used as a delimiter. The return value is a list handle. If two delimiters are successive, it is assumed that an empty element is between the two. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose'.
+
+ +

The function `cbreadfile' is used in order to read whole data of a file.

+ +
+
char *cbreadfile(const char *name, int *sp);
+
`name' specifies the name of a file. If it is `NULL', the standard input is specified. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the allocated region of the read data. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbwritefile' is used in order to write a serial datum into a file.

+ +
+
int cbwritefile(const char *name, const char *ptr, int size);
+
`name specifies the name of a file. If it is `NULL', the standard output is specified. `ptr' specifies the pointer to the region of the source content. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. If successful, the return value is true, else, it is false. If the file exists, it is overwritten. Else, a new file is created.
+
+ +

The function `cbreadlines' is used in order to read every line of a file.

+ +
+
CBLIST *cbreadlines(const char *name);
+
`name' specifies the name of a file. If it is `NULL', the standard input is specified. The return value is a list handle of the lines if successful, else it is NULL. Line separators are cut out. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.
+
+ +

The function `cbdirlist' is used in order to read names of files in a directory.

+ +
+
CBLIST *cbdirlist(const char *name);
+
`name' specifies the name of a directory. The return value is a list handle of names if successful, else it is NULL. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.
+
+ +

The function `cbfilestat' is used in order to get the status of a file or a directory.

+ +
+
int cbfilestat(const char *name, int *isdirp, int *sizep, int *mtimep);
+
`name' specifies the name of a file or a directory. `dirp' specifies the pointer to a variable to which whether the file is a directory is assigned. If it is `NULL', it is not used. `sizep' specifies the pointer to a variable to which the size of the file is assigned. If it is `NULL', it is not used. `mtimep' specifies the pointer to a variable to which the last modified time of the file is assigned. If it is `NULL', it is not used. If successful, the return value is true, else, false. False is returned when the file does not exist or the permission is denied.
+
+ +

The function `cbremove' is used in order to remove a file or a directory and its sub ones recursively.

+ +
+
int cbremove(const char *name);
+
`name' specifies the name of a file or a directory. If successful, the return value is true, else, false. False is returned when the file does not exist or the permission is denied.
+
+ +

The function `cburlbreak' is used in order to break up a URL into elements.

+ +
+
CBMAP *cburlbreak(const char *str);
+
`str' specifies the pointer to a string of URL. The return value is a map handle. Each key of the map is the name of an element. The key "self" specifies the URL itself. The key "scheme" specifies the scheme. The key "host" specifies the host of the server. The key "port" specifies the port number of the server. The key "authority" specifies the authority information. The key "path" specifies the path of the resource. The key "file" specifies the file name without the directory section. The key "query" specifies the query string. The key "fragment" specifies the fragment string. Supported schema are HTTP, HTTPS, FTP, and FILE. Absolute URL and relative URL are supported. Because the handle of the return value is opened with the function `cbmapopen', it should be closed with the function `cbmapclose' if it is no longer in use.
+
+ +

The runction `cburlresolve' is used in order to resolve a relative URL with another absolute URL.

+ +
+
char *cburlresolve(const char *base, const char *target);
+
`base' specifies an absolute URL of a base location. `target' specifies a URL to be resolved. The return value is a resolved URL. If the target URL is relative, a new URL of relative location from the base location is returned. Else, a copy of the target URL is returned. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cburlencode' is used in order to encode a serial object with URL encoding.

+ +
+
char *cburlencode(const char *ptr, int size);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the pointer to the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cburldecode' is used in order to decode a string encoded with URL encoding.

+ +
+
char *cburldecode(const char *str, int *sp);
+
`str' specifies the pointer to a source string. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the result. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbbaseencode' is used in order to encode a serial object with Base64 encoding.

+ +
+
char *cbbaseencode(const char *ptr, int size);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the pointer to the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbbasedecode' is used in order to decode a string encoded with Base64 encoding.

+ +
+
char *cbbasedecode(const char *str, int *sp);
+
`str' specifies the pointer to a source string. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the result. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbquoteencode' is used in order to encode a serial object with quoted-printable encoding.

+ +
+
char *cbquoteencode(const char *ptr, int size);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the pointer to the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbquotedecode' is used in order to decode a string encoded with quoted-printable encoding.

+ +
+
char *cbquotedecode(const char *str, int *sp);
+
`str' specifies the pointer to a source string. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the result. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ + +

The function `cbmimebreak' is used in order to split a string of MIME into headers and the body.

+ +
+
char *cbmimebreak(const char *ptr, int size, CBMAP *attrs, int *sp);
+
`ptr' specifies the pointer to the region of MIME data. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `attrs' specifies a map handle to store attributes. If it is `NULL', it is not used. Each key of the map is an attribute name uncapitalized. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer of the body data. If the content type is defined, the attribute map has the key "TYPE" specifying the type. If the character encoding is defined, the key "CHARSET" specifies the encoding name. If the boundary string of multipart is defined, the key "BOUNDARY" specifies the string. If the content disposition is defined, the key "DISPOSITION" specifies the direction. If the file name is defined, the key "FILENAME" specifies the name. If the attribute name is defined, the key "NAME" specifies the name. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbmimeparts' is used in order to split multipart data of MIME into its parts.

+ +
+
CBLIST *cbmimeparts(const char *ptr, int size, const char *boundary);
+
`ptr' specifies the pointer to the region of multipart data of MIME. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `boundary' specifies the pointer to the region of the boundary string. The return value is a list handle. Each element of the list is the string of a part. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.
+
+ +

The function `cbmimeencode' is used in order to encode a string with MIME encoding.

+ +
+
char *cbmimeencode(const char *str, const char *encname, int base);
+
`str' specifies the pointer to a string. `encname' specifies a string of the name of the character encoding. The return value is the pointer to the result string. `base' specifies whether to use Base64 encoding. If it is false, quoted-printable is used. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbmimedecode' is used in order to decode a string encoded with MIME encoding.

+ +
+
char *cbmimedecode(const char *str, char *enp);
+
`str' specifies the pointer to an encoded string. `enp' specifies the pointer to a region into which the name of encoding is written. If it is `NULL', it is not used. The size of the buffer should be equal to or more than 32 bytes. The return value is the pointer to the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbcsvrows' is used in order to split a string of CSV into rows.

+ +
+
CBLIST *cbcsvrows(const char *str);
+
`str' specifies the pointer to the region of an CSV string. The return value is a list handle. Each element of the list is a string of a row. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use. The character encoding of the input string should be US-ASCII, UTF-8, ISO-8859-*, EUC-*, or Shift_JIS. Being compatible with MS-Excel, these functions for CSV can handle cells including such meta characters as comma, between double quotation marks.
+
+ +

The function `cbcsvcells' is used in order to split the string of a row of CSV into cells.

+ +
+
CBLIST *cbcsvcells(const char *str);
+
`str' specifies the pointer to the region of a row of CSV. The return value is a list handle. Each element of the list is the unescaped string of a cell of the row. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.
+
+ +

The function `cbcsvescape' is used in order to escape a string with the meta characters of CSV.

+ +
+
char *cbcsvescape(const char *str);
+
`str' specifies the pointer to the region of a string. The return value is the pointer to the escaped string sanitized of meta characters. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbcsvunescape' is used in order to unescape a string with the escaped meta characters of CSV.

+ +
+
char *cbcsvunescape(const char *str);
+
`str' specifies the pointer to the region of a string with meta characters. The return value is the pointer to the unescaped string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbxmlbreak' is used in order to split a string of XML into tags and text sections.

+ +
+
CBLIST *cbxmlbreak(const char *str, int cr);
+
`str' specifies the pointer to the region of an XML string. `cr' specifies whether to remove comments. The return value is a list handle. Each element of the list is the string of a tag or a text section. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use. The character encoding of the input string should be US-ASCII, UTF-8, ISO-8859-*, EUC-*, or Shift_JIS. Because these functions for XML are not XML parser with validation check, it can handle also HTML and SGML.
+
+ +

The function `cbxmlattrs' is used in order to get the map of attributes of an XML tag.

+ +
+
CBMAP *cbxmlattrs(const char *str);
+
`str' specifies the pointer to the region of a tag string. The return value is a map handle. Each key of the map is the name of an attribute. Each value is unescaped. You can get the name of the tag with the key of an empty string. Because the handle of the return value is opened with the function `cbmapopen', it should be closed with the function `cbmapclose' if it is no longer in use.
+
+ +

The function `cbxmlescape' is used in order to escape a string with the meta characters of XML.

+ +
+
char *cbxmlescape(const char *str);
+
`str' specifies the pointer to the region of a string. The return value is the pointer to the escaped string sanitized of meta characters. This function converts only `&', `<', `>', and `"'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbxmlunescape' is used in order to unescape a string with the entity references of XML.

+ +
+
char *cbxmlunescape(const char *str);
+
`str' specifies the pointer to the region of a string. The return value is the pointer to the unescaped string. This function restores only `&amp;', `&lt;', `&gt;', and `&quot;'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbdeflate' is used in order to compress a serial object with ZLIB.

+ +
+
char *cbdeflate(const char *ptr, int size, int *sp);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with ZLIB enabled.
+
+ +

The function `cbinflate' is used in order to decompress a serial object compressed with ZLIB.

+ +
+
char *cbinflate(const char *ptr, int size, int *sp);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with ZLIB enabled.
+
+ +

The function `cbgzencode' is used in order to compress a serial object with GZIP.

+ +
+
char *cbgzencode(const char *ptr, int size, int *sp);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with ZLIB enabled.
+
+ +

The function `cbgzdecode' is used in order to decompress a serial object compressed with GZIP.

+ +
+
char *cbgzdecode(const char *ptr, int size, int *sp);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with ZLIB enabled.
+
+ +

The function `cbgetcrc' is used in order to get the CRC32 checksum of a serial object.

+ +
+
unsigned int cbgetcrc(const char *ptr, int size);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the CRC32 checksum of the object. This function is available only if QDBM was built with ZLIB enabled.
+
+ +

The function `cblzoencode' is used in order to compress a serial object with LZO.

+ +
+
char *cblzoencode(const char *ptr, int size, int *sp);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with LZO enabled.
+
+ +

The function `cblzodecode' is used in order to decompress a serial object compressed with LZO.

+ +
+
char *cblzodecode(const char *ptr, int size, int *sp);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with LZO enabled.
+
+ +

The function `cbbzencode' is used in order to compress a serial object with BZIP2.

+ +
+
char *cbbzencode(const char *ptr, int size, int *sp);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with BZIP2 enabled.
+
+ +

The function `cbbzdecode' is used in order to decompress a serial object compressed with BZIP2.

+ +
+
char *cbbzdecode(const char *ptr, int size, int *sp);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with BZIP2 enabled.
+
+ +

The function `cbiconv' is used in order to convert the character encoding of a string.

+ +
+
char *cbiconv(const char *ptr, int size, const char *icode, const char *ocode, int *sp, int *mp);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `icode' specifies the name of encoding of the input string. `ocode' specifies the name of encoding of the output string. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. `mp' specifies the pointer to a variable to which the number of missing characters by failure of conversion is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with ICONV enabled.
+
+ +

The function `cbencname' is used in order to detect the encoding of a string automatically.

+ +
+
const char *cbencname(const char *ptr, int size);
+
`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the string of the encoding name of the string. As it stands, US-ASCII, ISO-2022-JP, Shift_JIS, CP932, EUC-JP, UTF-8, UTF-16, UTF-16BE, and UTF-16LE are supported. If none of them matches, ISO-8859-1 is selected. This function is available only if QDBM was built with ICONV enabled.
+
+ +

The function `cbjetlag' is used in order to get the jet lag of the local time in seconds.

+ +
+
int cbjetlag(void);
+
The return value is the jet lag of the local time in seconds.
+
+ +

The function `cbcalendar' is used in order to get the Gregorian calendar of a time.

+ +
+
void cbcalendar(time_t t, int jl, int *yearp, int *monp, int *dayp, int *hourp, int *minp, int *secp);
+
`t' specifies a source time. If it is negative, the current time is specified. `jl' specifies the jet lag of a location in seconds. `yearp' specifies the pointer to a variable to which the year is assigned. If it is `NULL', it is not used. `monp' specifies the pointer to a variable to which the month is assigned. If it is `NULL', it is not used. 1 means January and 12 means December. `dayp' specifies the pointer to a variable to which the day of the month is assigned. If it is `NULL', it is not used. `hourp' specifies the pointer to a variable to which the hours is assigned. If it is `NULL', it is not used. `minp' specifies the pointer to a variable to which the minutes is assigned. If it is `NULL', it is not used. `secp' specifies the pointer to a variable to which the seconds is assigned. If it is `NULL', it is not used.
+
+ +

The function `cbdayofweek' is used in order to get the day of week of a date.

+ +
+
int cbdayofweek(int year, int mon, int day);
+
`year' specifies the year of a date. `mon' specifies the month of the date. `day' specifies the day of the date. The return value is the day of week of the date. 0 means Sunday and 6 means Saturday.
+
+ +

The function `cbdatestrwww' is used in order to get the string for a date in W3CDTF.

+ +
+
char *cbdatestrwww(time_t t, int jl);
+
`t' specifies a source time. If it is negative, the current time is specified. `jl' specifies the jet lag of a location in seconds. The return value is the string of the date in W3CDTF (YYYY-MM-DDThh:mm:ddTZD). Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbdatestrhttp' is used in order to get the string for a date in RFC 1123 format.

+ +
+
char *cbdatestrhttp(time_t t, int jl);
+
`t' specifies a source time. If it is negative, the current time is specified. `jl' specifies the jet lag of a location in seconds. The return value is the string of the date in RFC 1123 format (Wdy, DD-Mon-YYYY hh:mm:dd TZD). Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `cbstrmktime' is used in order to get the time value of a date string in decimal, hexadecimal, W3CDTF, or RFC 822 (1123).

+ +
+
time_t cbstrmktime(const char *str);
+
`str' specifies a date string in decimal, hexadecimal, W3CDTF, or RFC 822 (1123). The return value is the time value of the date or -1 if the format is invalid. Decimal can be trailed by "s" for in seconds, "m" for in minutes, "h" for in hours, and "d" for in days.
+
+ +

The function `cbproctime' is used in order to get user and system processing times.

+ +
+
void cbproctime(double *usrp, double *sysp);
+
`usrp' specifies the pointer to a variable to which the user processing time is assigned. If it is `NULL', it is not used. The unit of time is seconds. `sysp' specifies the pointer to a variable to which the system processing time is assigned. If it is `NULL', it is not used. The unit of time is seconds.
+
+ +

The function `cbstdiobin' is used in order to ensure that the standard I/O is binary mode.

+ +
+
void cbstdiobin(void);
+
This function is useful for applications on dosish file systems.
+
+ +

Examples

+ +

The following example is typical use.

+ +
#include <cabin.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(int argc, char **argv){
+  CBDATUM *datum;
+  CBLIST *list;
+  CBMAP *map;
+  char *buf1, *buf2;
+  int i;
+
+  /* open the datum handle */
+  datum = cbdatumopen("123", -1);
+  /* concatenate the data */
+  cbdatumcat(datum, "abc", -1);
+  /* print the datum */
+  printf("%s\n", cbdatumptr(datum));
+  /* close the datum handle */
+  cbdatumclose(datum);
+
+  /* open the list handle */
+  list = cblistopen();
+  /* add elements into the list */
+  cblistpush(list, "apple", -1);
+  cblistpush(list, "orange", -1);
+  /* print all elements */
+  for(i = 0; i < cblistnum(list); i++){
+    printf("%s\n", cblistval(list, i, NULL));
+  }
+  /* close the list handle */
+  cblistclose(list);
+
+  /* open the map handle */
+  map = cbmapopen();
+  /* add records into the map */
+  cbmapput(map, "dog", -1, "bowwow", -1, 1);
+  cbmapput(map, "cat", -1, "meow", -1, 1);
+  /* search for values and print them */
+  printf("%s\n", cbmapget(map, "dog", -1, NULL));
+  printf("%s\n", cbmapget(map, "cat", -1, NULL));
+  /* close the map */
+  cbmapclose(map);
+
+  /* Base64 encoding */
+  buf1 = cbbaseencode("I miss you.", -1);
+  printf("%s\n", buf1);
+  /* Base64 decoding */
+  buf2 = cbbasedecode(buf1, NULL);
+  printf("%s\n", buf2);
+  /* release the resources */
+  free(buf2);
+  free(buf1);
+
+  /* register a plain pointer to the global garbage collector */
+  buf1 = cbmemdup("Take it easy.", -1);
+  cbglobalgc(buf1, free);
+  /* the pointer is available but you don't have to release it */
+  printf("%s\n", buf1);
+  
+  /* register a list to the global garbage collector */
+  list = cblistopen();
+  cbglobalgc(list, (void (*)(void *))cblistclose);
+  /* the handle is available but you don't have to close it */
+  cblistpush(list, "Don't hesitate.", -1);
+  for(i = 0; i < cblistnum(list); i++){
+    printf("%s\n", cblistval(list, i, NULL));    
+  }
+
+  return 0;
+}
+
+ +

Notes

+ +

How to build programs using Cabin is the same as the case of Depot.

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

Functions of Cabin except for `cbglobalgc' are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.

+ +
+ +

Commands for Cabin

+ +

Cabin has the following command line interfaces.

+ +

The command `cbtest' is a utility for facility test and performance test. Measure the execution time of the command. This command is used in the following format. `rnum' specifies the number of records.

+ +
+
cbtest sort [-d] rnum
+
Perform test of sorting algorithms.
+
cbtest strstr [-d] rnum
+
Perform test of string locating algorithms.
+
cbtest list [-d] rnum
+
Perform writing test of list.
+
cbtest map [-d] rnum
+
Perform writing test of map.
+
cbtest wicked rnum
+
Perform updating operations of list and map selected at random.
+
cbtest misc
+
Perform test of miscellaneous routines.
+
+ +

Options feature the following.

+ +
    +
  • -d : read and show data of the result.
  • +
+ +

This command returns 0 on success, another on failure.

+ +

The command `cbcodec' is a tool to use encoding and decoding features provided by Cabin. This command is used in the following format. `file' specifies a input file. If it is omitted, the standard input is read.

+ +
+
cbcodec url [-d] [-br] [-rs base target] [-l] [-e expr] [file]
+
Perform URL encoding and its decoding.
+
cbcodec base [-d] [-l] [-c num] [-e expr] [file]
+
Perform Base64 encoding and its decoding.
+
cbcodec quote [-d] [-l] [-c num] [-e expr] [file]
+
Perform quoted-printable encoding and its decoding.
+
cbcodec mime [-d] [-hd] [-bd] [-part num] [-l] [-ec code] [-qp] [-dc] [-e expr] [file]
+
Perform MIME encoding and its decoding.
+
cbcodec csv [-d] [-t] [-l] [-e expr] [-html] [file]
+
Process CSV. By default, escape meta characters.
+
cbcodec xml [-d] [-p] [-l] [-e expr] [-tsv] [file]
+
Process XML. By default, escape meta characters.
+
cbcodec zlib [-d] [-gz] [-crc] [file]
+
Perform deflation and inflation with ZLIB. It is available only if QDBM was built with ZLIB enabled.
+
cbcodec lzo [-d] [file]
+
Perform compression and decompression with LZO. It is available only if QDBM was built with LZO enabled.
+
cbcodec bzip [-d] [file]
+
Perform compression and decompression with BZIP2. It is available only if QDBM was built with BZIP2 enabled.
+
cbcodec iconv [-ic code] [-oc code] [-ol ltype] [-cn] [-um] [-wc] [file]
+
Convert character encoding with ICONV. It is available only if QDBM was built with ICONV enabled.
+
cbcodec date [-wf] [-rf] [-utc] [str]
+
Convert a date string specified `str'. By default, UNIX time is output. If `str' is omitted, the current date is dealt.
+
+ +

Options feature the following.

+ +
    +
  • -d : perform decoding (unescaping), not encoding (escaping).
  • +
  • -br : break up URL into elements.
  • +
  • -rs : resolve relative URL.
  • +
  • -l : output the tailing newline.
  • +
  • -e expr : specify input data directly.
  • +
  • -c num : limit the number of columns of the encoded data.
  • +
  • -hd : parse MIME and extract headers in TSV format.
  • +
  • -bd : parse MIME and extract the body.
  • +
  • -part num : parse MIME and extract a part.
  • +
  • -ec code : specify the input encoding, which is UTF-8 by default.
  • +
  • -qp : use quoted-printable encoding, which is Base64 by default.
  • +
  • -dc : output the encoding name instead of the result string when decoding.
  • +
  • -t : parse CSV. Convert the data into TSV. Tab and new-line in a cell are deleted.
  • +
  • -html : parse CSV. Convert the data into HTML.
  • +
  • -p : parse XML. Show tags and text sections with dividing headers.
  • +
  • -tsv : parse XML. Show the result in TSV format. Characters of tabs and new-lines are URL-encoded.
  • +
  • -gz : use GZIP format.
  • +
  • -crc : output the CRC32 checksum as hexadecimal and big endian.
  • +
  • -ic code : specify the input encoding, which is detected automatically by default.
  • +
  • -oc code : specify the output encoding, which is UTF-8 by default.
  • +
  • -ol ltype : convert line feed characters, with `unix'(LF), `dos'(CRLF), and `mac'(CR).
  • +
  • -cn : detect the input encoding and show its name.
  • +
  • -wc : count the number of characters of the input string of UTF-8.
  • +
  • -um : output mappings of UCS-2 characters and C strings of UTF-16BE and UTF-8.
  • +
  • -wf : output in W3CDTF format.
  • +
  • -rf : output in RFC 1123 format.
  • +
  • -utc : output the coordinate universal time.
  • +
+ +

This command returns 0 on success, another on failure.

+ +
+ +

Villa: Advanced API

+ +

Overview

+ +

Villa is the advanced API of QDBM. It provides routines for managing a database file of B+ tree. Each record is stored being sorted in order defined by a user. As for hash databases, retrieving method is provided only as complete accord. However, with Villa, it is possible to retrieve records specified by range. Cursor is used in order to access each record in order. It is possible to store records duplicating keys in a database. Moreover, according to the transaction mechanism, you can commit or abort operations of a database in a lump.

+ +

Villa is implemented, based on Depot and Cabin. A database file of Villa is actual one of Depot. Although processing speed of retrieving and storing is slower than Depot, the size of a database is smaller.

+ +

In order to use Villa, you should include `depot.h', `cabin.h', `villa.h' and `stdlib.h' in the source files. Usually, the following description will be near the beginning of a source file.

+ +
+
#include <depot.h>
+
#include <cabin.h>
+
#include <villa.h>
+
#include <stdlib.h>
+
+ +

A pointer to `VILLA' is used as a database handle. It is like that some file I/O routines of `stdio.h' use a pointer to `FILE'. A database handle is opened with the function `vlopen' and closed with `vlclose'. You should not refer directly to any member of the handle. If a fatal error occurs in a database, any access method via the handle except `vlclose' will not work and return error status. Although a process is allowed to use multiple database handles at the same time, handles of the same database file should not be used. Before the cursor is used, it should be initialized by one of `vlcurfirst', `vlcurlast' or `vlcurjump'. Also after storing or deleting a record with functions except for `vlcurput' and `vlcurout', the cursor should be initialized.

+ +

Villa also assign the external variable `dpecode' with the error code. The function `dperrmsg' is used in order to get the message of the error code.

+ +

API

+ +

You can define a comparing function to specify the order of records. The function should be the following type.

+ +
+
typedef int(*VLCFUNC)(const char *aptr, int asiz, const char *bptr, int bsiz);
+
`aptr' specifies the pointer to the region of one key. `asiz' specifies the size of the region of one key. `bptr' specifies the pointer to the region of the other key. `bsiz' specifies the size of the region of the other key. The return value is positive if the former is big, negative if the latter is big, 0 if both are equivalent.
+
+ +

The function `vlopen' is used in order to get a database handle.

+ +
+
VILLA *vlopen(const char *name, int omode, VLCFUNC cmp);
+
`name' specifies the name of a database file. `omode' specifies the connection mode: `VL_OWRITER' as a writer, `VL_OREADER' as a reader. If the mode is `VL_OWRITER', the following may be added by bitwise or: `VL_OCREAT', which means it creates a new database if not exist, `VL_OTRUNC', which means it creates a new database regardless if one exists, `VL_OZCOMP', which means leaves in the database are compressed with ZLIB, `VL_OYCOMP', which means leaves in the database are compressed with LZO, `VL_OXCOMP', which means leaves in the database are compressed with BZIP2. Both of `VL_OREADER' and `VL_OWRITER' can be added to by bitwise or: `VL_ONOLCK', which means it opens a database file without file locking, or `VL_OLCKNB', which means locking is performed without blocking. `cmp' specifies the comparing function: `VL_CMPLEX' comparing keys in lexical order, `VL_CMPINT' comparing keys as objects of `int' in native byte order, `VL_CMPNUM' comparing keys as numbers of big endian, `VL_CMPDEC' comparing keys as decimal strings. Any function based on the declaration of the type `VLCFUNC' can be assigned to the comparing function. The comparing function should be kept same in the life of a database. The return value is the database handle or `NULL' if it is not successful. While connecting as a writer, an exclusive lock is invoked to the database file. While connecting as a reader, a shared lock is invoked to the database file. The thread blocks until the lock is achieved. `VL_OZCOMP', `VL_OYCOMP', and `VL_OXCOMP' are available only if QDBM was built each with ZLIB, LZO, and BZIP2 enabled. If `VL_ONOLCK' is used, the application is responsible for exclusion control.
+
+ +

The function `vlclose' is used in order to close a database handle.

+ +
+
int vlclose(VILLA *villa);
+
`villa' specifies a database handle. If successful, the return value is true, else, it is false. Because the region of a closed handle is released, it becomes impossible to use the handle. Updating a database is assured to be written when the handle is closed. If a writer opens a database but does not close it appropriately, the database will be broken. If the transaction is activated and not committed, it is aborted.
+
+ +

The function `vlput' is used in order to store a record.

+ +
+
int vlput(VILLA *villa, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode);
+
`villa' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `dmode' specifies behavior when the key overlaps, by the following values: `VL_DOVER', which means the specified value overwrites the existing one, `VL_DKEEP', which means the existing value is kept, `VL_DCAT', which means the specified value is concatenated at the end of the existing value, `VL_DDUP', which means duplication of keys is allowed and the specified value is added as the last one, `VL_DDUPR', which means duplication of keys is allowed and the specified value is added as the first one. If successful, the return value is true, else, it is false. The cursor becomes unavailable due to updating database.
+
+ +

The function `vlout' is used in order to delete a record.

+ +
+
int vlout(VILLA *villa, const char *kbuf, int ksiz);
+
`villa' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the specified key. When the key of duplicated records is specified, the first record of the same key is deleted. The cursor becomes unavailable due to updating database.
+
+ +

The function `vlget' is used in order to retrieve a record.

+ +
+
char *vlget(VILLA *villa, const char *kbuf, int ksiz, int *sp);
+
`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. When the key of duplicated records is specified, the value of the first record of the same key is selected. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `vlvsiz' is used in order to get the size of the value of a record.

+ +
+
int vlvsiz(VILLA *villa, const char *kbuf, int ksiz);
+
`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is the size of the value of the corresponding record, else, it is -1. If multiple records correspond, the size of the first is returned.
+
+ +

The function `vlvnum' is used in order to get the number of records corresponding a key.

+ +
+
int vlvnum(VILLA *villa, const char *kbuf, int ksiz);
+
`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. The return value is the number of corresponding records. If no record corresponds, 0 is returned.
+
+ +

The function `vlputlist' is used in order to store plural records corresponding a key.

+ +
+
int vlputlist(VILLA *villa, const char *kbuf, int ksiz, const CBLIST *vals);
+
`villa' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vals' specifies a list handle of values. The list should not be empty. If successful, the return value is true, else, it is false. The cursor becomes unavailable due to updating database.
+
+ +

The function `vloutlist' is used in order to delete all records corresponding a key.

+ +
+
int vloutlist(VILLA *villa, const char *kbuf, int ksiz);
+
`villa' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the specified key. The cursor becomes unavailable due to updating database.
+
+ +

The function `vlgetlist' is used in order to retrieve values of all records corresponding a key.

+ +
+
CBLIST *vlgetlist(VILLA *villa, const char *kbuf, int ksiz);
+
`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is a list handle of the values of the corresponding records, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.
+
+ +

The function `vlgetcat' is used in order to retrieve concatenated values of all records corresponding a key.

+ +
+
char *vlgetcat(VILLA *villa, const char *kbuf, int ksiz, int *sp);
+
`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the concatenated values of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `vlcurfirst' is used in order to move the cursor to the first record.

+ +
+
int vlcurfirst(VILLA *villa);
+
`villa' specifies a database handle. If successful, the return value is true, else, it is false. False is returned if there is no record in the database.
+
+ +

The function `vlcurlast' is used in order to move the cursor to the last record.

+ +
+
int vlcurlast(VILLA *villa);
+
`villa' specifies a database handle. If successful, the return value is true, else, it is false. False is returned if there is no record in the database.
+
+ +

The function `vlcurprev' is used in order to move the cursor to the previous record.

+ +
+
int vlcurprev(VILLA *villa);
+
`villa' specifies a database handle. If successful, the return value is true, else, it is false. False is returned if there is no previous record.
+
+ +

The function `vlcurnext' is used in order to move the cursor to the next record.

+ +
+
int vlcurnext(VILLA *villa);
+
`villa' specifies a database handle. If successful, the return value is true, else, it is false. False is returned if there is no next record.
+
+ +

The function `vlcurjump' is used in order to move the cursor to a position around a record.

+ +
+
int vlcurjump(VILLA *villa, const char *kbuf, int ksiz, int jmode);
+
`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `jmode' specifies detail adjustment: `VL_JFORWARD', which means that the cursor is set to the first record of the same key and that the cursor is set to the next substitute if completely matching record does not exist, `VL_JBACKWARD', which means that the cursor is set to the last record of the same key and that the cursor is set to the previous substitute if completely matching record does not exist. If successful, the return value is true, else, it is false. False is returned if there is no record corresponding the condition.
+
+ +

The function `vlcurkey' is used in order to get the key of the record where the cursor is.

+ +
+
char *vlcurkey(VILLA *villa, int *sp);
+
`villa' specifies a database handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the key of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the cursor. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `vlcurval' is used in order to get the value of the record where the cursor is.

+ +
+
char *vlcurval(VILLA *villa, int *sp);
+
`villa' specifies a database handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the cursor. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `vlcurput' is used in order to insert a record around the cursor.

+ +
+
int vlcurput(VILLA *villa, const char *vbuf, int vsiz, int cpmode);
+
`villa' specifies a database handle connected as a writer. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `cpmode' specifies detail adjustment: `VL_CPCURRENT', which means that the value of the current record is overwritten, `VL_CPBEFORE', which means that a new record is inserted before the current record, `VL_CPAFTER', which means that a new record is inserted after the current record. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the cursor. After insertion, the cursor is moved to the inserted record.
+
+ +

The function `vlcurout' is used in order to delete the record where the cursor is.

+ +
+
int vlcurout(VILLA *villa);
+
`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the cursor. After deletion, the cursor is moved to the next record if possible.
+
+ +

The function `vlsettuning' is used in order to set the tuning parameters for performance.

+ +
+
void vlsettuning(VILLA *villa, int lrecmax, int nidxmax, int lcnum, int ncnum);
+
`villa' specifies a database handle. `lrecmax' specifies the max number of records in a leaf node of B+ tree. If it is not more than 0, the default value is specified. `nidxmax' specifies the max number of indexes in a non-leaf node of B+ tree. If it is not more than 0, the default value is specified. `lcnum' specifies the max number of caching leaf nodes. If it is not more than 0, the default value is specified. `ncnum' specifies the max number of caching non-leaf nodes. If it is not more than 0, the default value is specified. The default setting is equivalent to `vlsettuning(49, 192, 1024, 512)'. Because tuning parameters are not saved in a database, you should specify them every opening a database.
+
+ +

The function `vlsetfbpsiz' is used in order to set the size of the free block pool of a database handle.

+ +
+
int vlsetfbpsiz(VILLA *villa, int size);
+
`villa' specifies a database handle connected as a writer. `size' specifies the size of the free block pool of a database. If successful, the return value is true, else, it is false. The default size of the free block pool is 256. If the size is greater, the space efficiency of overwriting values is improved with the time efficiency sacrificed.
+
+ +

The function `vlsync' is used in order to synchronize updating contents with the file and the device.

+ +
+
int vlsync(VILLA *villa);
+
`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. This function is useful when another process uses the connected database file. This function should not be used while the transaction is activated.
+
+ +

The function `vloptimize' is used in order to optimize a database.

+ +
+
int vloptimize(VILLA *villa);
+
`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. In an alternating succession of deleting and storing with overwrite or concatenate, dispensable regions accumulate. This function is useful to do away with them. This function should not be used while the transaction is activated.
+
+ +

The function `vlname' is used in order to get the name of a database.

+ +
+
char *vlname(VILLA *villa);
+
`villa' specifies a database handle. If successful, the return value is the pointer to the region of the name of the database, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `vlfsiz' is used in order to get the size of a database file.

+ +
+
int vlfsiz(VILLA *villa);
+
`villa' specifies a database handle. If successful, the return value is the size of the database file, else, it is -1. Because of the I/O buffer, the return value may be less than the hard size.
+
+ +

The function `vllnum' is used in order to get the number of the leaf nodes of B+ tree.

+ +
+
int vllnum(VILLA *villa);
+
`villa' specifies a database handle. If successful, the return value is the number of the leaf nodes, else, it is -1.
+
+ +

The function `vlnnum' is used in order to get the number of the non-leaf nodes of B+ tree.

+ +
+
int vlnnum(VILLA *villa);
+
`villa' specifies a database handle. If successful, the return value is the number of the non-leaf nodes, else, it is -1.
+
+ +

The function `vlrnum' is used in order to get the number of the records stored in a database.

+ +
+
int vlrnum(VILLA *villa);
+
`villa' specifies a database handle. If successful, the return value is the number of the records stored in the database, else, it is -1.
+
+ +

The function `vlwritable' is used in order to check whether a database handle is a writer or not.

+ +
+
int vlwritable(VILLA *villa);
+
`villa' specifies a database handle. The return value is true if the handle is a writer, false if not.
+
+ +

The function `vlfatalerror' is used in order to check whether a database has a fatal error or not.

+ +
+
int vlfatalerror(VILLA *villa);
+
`villa' specifies a database handle. The return value is true if the database has a fatal error, false if not.
+
+ +

The function `vlinode' is used in order to get the inode number of a database file.

+ +
+
int vlinode(VILLA *villa);
+
`villa' specifies a database handle. The return value is the inode number of the database file.
+
+ +

The function `vlmtime' is used in order to get the last modified time of a database.

+ +
+
time_t vlmtime(VILLA *villa);
+
`villa' specifies a database handle. The return value is the last modified time of the database.
+
+ +

The function `vltranbegin' is used in order to begin the transaction.

+ +
+
int vltranbegin(VILLA *villa);
+
`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. Because this function does not perform mutual exclusion control in multi-thread, the application is responsible for it. Only one transaction can be activated with a database handle at the same time.
+
+ +

The function `vltrancommit' is used in order to commit the transaction.

+ +
+
int vltrancommit(VILLA *villa);
+
`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. Updating a database in the transaction is fixed when it is committed successfully.
+
+ +

The function `vltranabort' is used in order to abort the transaction.

+ +
+
int vltranabort(VILLA *villa);
+
`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. Updating a database in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.
+
+ +

The function `vlremove' is used in order to remove a database file.

+ +
+
int vlremove(const char *name);
+
`name' specifies the name of a database file. If successful, the return value is true, else, it is false.
+
+ +

The function `vlrepair' is used in order to repair a broken database file.

+ +
+
int vlrepair(const char *name, VLCFUNC cmp);
+
`name' specifies the name of a database file. `cmp' specifies the comparing function of the database file. If successful, the return value is true, else, it is false. There is no guarantee that all records in a repaired database file correspond to the original or expected state.
+
+ +

The function `vlexportdb' is used in order to dump all records as endian independent data.

+ +
+
int vlexportdb(VILLA *villa, const char *name);
+
`villa' specifies a database handle. `name' specifies the name of an output file. If successful, the return value is true, else, it is false.
+
+ +

The function `vlimportdb' is used in order to load all records from endian independent data.

+ +
+
int vlimportdb(VILLA *villa, const char *name);
+
`villa' specifies a database handle connected as a writer. The database of the handle must be empty. `name' specifies the name of an input file. If successful, the return value is true, else, it is false.
+
+ +

Examples

+ +

The following example stores and retrieves a phone number, using the name as the key.

+ +
#include <depot.h>
+#include <cabin.h>
+#include <villa.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define NAME     "mikio"
+#define NUMBER   "000-1234-5678"
+#define DBNAME   "book"
+
+int main(int argc, char **argv){
+  VILLA *villa;
+  char *val;
+
+  /* open the database */
+  if(!(villa = vlopen(DBNAME, VL_OWRITER | VL_OCREAT, VL_CMPLEX))){
+    fprintf(stderr, "vlopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* store the record */
+  if(!vlput(villa, NAME, -1, NUMBER, -1, VL_DOVER)){
+    fprintf(stderr, "vlput: %s\n", dperrmsg(dpecode));
+  }
+
+  /* retrieve the record */
+  if(!(val = vlget(villa, NAME, -1, NULL))){
+    fprintf(stderr, "vlget: %s\n", dperrmsg(dpecode));
+  } else {
+    printf("Name: %s\n", NAME);
+    printf("Number: %s\n", val);
+    free(val);
+  }
+
+  /* close the database */
+  if(!vlclose(villa)){
+    fprintf(stderr, "vlclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

The following example performs forward matching search for strings.

+ +
#include <depot.h>
+#include <cabin.h>
+#include <villa.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define DBNAME   "words"
+#define PREFIX   "apple"
+
+int main(int argc, char **argv){
+  VILLA *villa;
+  char *key, *val;
+
+  /* open the database */
+  if(!(villa = vlopen(DBNAME, VL_OWRITER | VL_OCREAT, VL_CMPLEX))){
+    fprintf(stderr, "vlopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* store records */
+  if(!vlput(villa, "applet", -1, "little application", -1, VL_DDUP) ||
+     !vlput(villa, "aurora", -1, "polar wonderwork", -1, VL_DDUP) ||
+     !vlput(villa, "apple", -1, "delicious fruit", -1, VL_DDUP) ||
+     !vlput(villa, "amigo", -1, "good friend", -1, VL_DDUP) ||
+     !vlput(villa, "apple", -1, "big city", -1, VL_DDUP)){
+    fprintf(stderr, "vlput: %s\n", dperrmsg(dpecode));
+  }
+
+  /* set the cursor at the top of candidates */
+  vlcurjump(villa, PREFIX, -1, VL_JFORWARD);
+
+  /* scan with the cursor */
+  while((key = vlcurkey(villa, NULL)) != NULL){
+    if(strstr(key, PREFIX) != key){
+      free(key);
+      break;
+    }
+    if(!(val = vlcurval(villa, NULL))){
+      fprintf(stderr, "vlcurval: %s\n", dperrmsg(dpecode));
+      free(key);
+      break;
+    }
+    printf("%s: %s\n", key, val);
+    free(val);
+    free(key);
+    vlcurnext(villa);
+  }
+
+  /* close the database */
+  if(!vlclose(villa)){
+    fprintf(stderr, "vlclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

Notes

+ +

How to build programs using Villa is the same as the case of Depot.

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

If QDBM was built with POSIX thread enabled, the global variable `dpecode' is treated as thread specific data, and functions of Villa are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.

+ +

Vista: Extended Advanced API

+ +

Vista is the extended API of Villa. To compensate for the defect that Villa can not handle a file whose size is more than 2GB, Vista does not use Depot but Curia for handling its internal database. While Vista provides data structure and operations of B+ tree as with Villa, its database is realized as a directory.

+ +

In order to use Vista, you should include `vista.h' instead of `villa.h'. Because Vista is implemented by overriding symbols of Villa, it can be used as with Villa. That is, Signatures of Villa and Vista is all the same. However, as its adverse effect, modules (compilation unit) using Vista can not use Villa (do not include `villa.h').

+ +
+ +

Commands for Villa

+ +

Villa has the following command line interfaces.

+ +

The command `vlmgr' is a utility for debugging Villa and its applications. It features editing and checking of a database. It can be used for database applications with shell scripts. This command is used in the following format. `name' specifies a database name. `key' specifies the key of a record. `val' specifies the value of a record.

+ +
+
vlmgr create [-cz|-cy|-cx] name
+
Create a database file.
+
vlmgr put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat|-dup] name key val
+
Store a record with a key and a value.
+
vlmgr out [-l] [-kx|-ki] name key
+
Delete a record with a key.
+
vlmgr get [-nl] [-l] [-kx|-ki] [-ox] [-n] name key
+
Retrieve a record with a key and output it to the standard output.
+
vlmgr list [-nl] [-k|-v] [-kx|-ki] [-ox] [-top key] [-bot key] [-gt] [-lt] [-max num] [-desc] name
+
List all keys and values delimited with tab and line-feed to the standard output.
+
vlmgr optimize name
+
Optimize a database.
+
vlmgr inform [-nl] name
+
Output miscellaneous information to the standard output.
+
vlmgr remove name
+
Remove a database file.
+
vlmgr repair [-ki] name
+
Repair a broken database file.
+
vlmgr exportdb [-ki] name file
+
Dump all records as endian independent data.
+
vlmgr importdb [-ki] name file
+
Load all records from endian independent data.
+
vlmgr version
+
Output version information of QDBM to the standard output.
+
+ +

Options feature the following.

+ +
    +
  • -cz : compress leaves in the database with ZLIB.
  • +
  • -cy : compress leaves in the database with LZO.
  • +
  • -cx : compress leaves in the database with BZIP2.
  • +
  • -l : all records corresponding the key are dealt.
  • +
  • -kx : treat `key' as a binary expression of hexadecimal notation.
  • +
  • -ki : treat `key' as an integer expression of decimal notation.
  • +
  • -vx : treat `val' as a binary expression of hexadecimal notation.
  • +
  • -vi : treat `val' as an integer expression of decimal notation.
  • +
  • -vf : read the value from a file specified with `val'.
  • +
  • -keep : specify the storing mode for `VL_DKEEP'.
  • +
  • -cat : specify the storing mode for `VL_DCAT'.
  • +
  • -dup : specify the storing mode for `VL_DDUP'.
  • +
  • -nl : open the database without file locking.
  • +
  • -top key : specify the top key of listing.
  • +
  • -bot key : specify the bottom key of listing.
  • +
  • -gt : do not include the top key of listing.
  • +
  • -lt : do not include the bottom key of listing.
  • +
  • -max num : specify the max number of listing.
  • +
  • -desc : list in descending order.
  • +
  • -ox : treat the output as a binary expression of hexadecimal notation.
  • +
  • -n : do not output the tailing newline.
  • +
  • -k : output keys only.
  • +
  • -v : output values only.
  • +
+ +

This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.

+ +

The command `vltest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `rnum' specifies the number of the records.

+ +
+
vltest write [-int] [-cz|-cy|-cx] [-tune lrecmax nidxmax lcnum ncnum] [-fbp num] name rnum
+
Store records with keys of 8 bytes. They change as `00000001', `00000002'...
+
vltest read [-int] [-vc] name
+
Retrieve all records of the database above.
+
vltest rdup [-int] [-cz|-cy|-cx] [-cc] [-tune lrecmax nidxmax lcnum ncnum] [-fbp num] name rnum pnum
+
Store records with partway duplicated keys using duplicate mode.
+
vltest combo [-cz|-cy|-cx] name
+
Perform combination test of various operations.
+
vltest wicked [-cz|-cy|-cx] name rnum
+
Perform updating operations selected at random.
+
+ +

Options feature the following.

+ +
    +
  • -int : treat keys and values as objects of `int', and use comparing function `VL_CMPINT'.
  • +
  • -cz : compress leaves in the database with ZLIB.
  • +
  • -cy : compress leaves in the database with LZO.
  • +
  • -cx : compress leaves in the database with BZIP2.
  • +
  • -vc : refer to volatile cache.
  • +
  • -cc : select `VL_DCAT' or `VL_DDUP' at random.
  • +
  • -tune lrecmax nidxmax lcnum ncnum : set tuning parameters.
  • +
  • -fbp num : set the size of the free block pool.
  • +
  • -c : perform comparison test with map of Cabin.
  • +
+ +

This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.

+ +

The command `vltsv' features mutual conversion between a database of Villa and a TSV text. This command is useful when data exchange with another version of QDBM or another DBM, or when data exchange between systems which have different byte orders. This command is used in the following format. `name' specifies a database name. The subcommand `export' reads TSV data from the standard input. The subcommand `import' writes TSV data to the standard output.

+ +
+
vltsv import [-bin] name
+
Create a database from TSV.
+
vltsv export [-bin] name
+
Write TSV data of a database.
+
+ +

Options feature the following.

+ +
    +
  • -bin : treat records as Base64 format.
  • +
+ +

This command returns 0 on success, another on failure.

+ +

Commands of Villa realize a simple database system. For example, to make a database to search `/etc/password' by a user name, perform the following command.

+ +
cat /etc/passwd | tr ':' '\t' | vltsv import casket
+
+ +

Thus, to retrieve the information of a user `mikio', perform the following command.

+ +
vlmgr get casket mikio
+
+ +

It is easy to implement functions upsides with these commands, using the API of Villa.

+ +

The command `qmttest' checks multi-thread safety of Depot, Curia, and Villa. This command works with multi threads only if QDBM was built with POSIX thread. This command is used in the following format. `name' specifies the prefix of each database. `rnum' specifies the number of records to be stored in each database. `tnum' specifies the number of threads.

+ +
+
qmttest name rnum tnum
+
Check multi-thread safety.
+
+ +

This command returns 0 on success, another on failure.

+ +
+ +

Odeum: Inverted API

+ +

Overview

+ +

Odeum is the API which handles an inverted index. An inverted index is a data structure to retrieve a list of some documents that include one of words which were extracted from a population of documents. It is easy to realize a full-text search system with an inverted index. Odeum provides an abstract data structure which consists of words and attributes of a document. It is used when an application stores a document into a database and when an application retrieves some documents from a database.

+ +

Odeum does not provide methods to extract the text from the original data of a document. It should be implemented by applications. Although Odeum provides utilities to extract words from a text, it is oriented to such languages whose words are separated with space characters as English. If an application handles such languages which need morphological analysis or N-gram analysis as Japanese, or if an application perform more such rarefied analysis of natural languages as stemming, its own analyzing method can be adopted. Result of search is expressed as an array contains elements which are structures composed of the ID number of documents and its score. In order to search with two or more words, Odeum provides utilities of set operations.

+ +

Odeum is implemented, based on Curia, Cabin, and Villa. Odeum creates a database with a directory name. Some databases of Curia and Villa are placed in the specified directory. For example, `casket/docs', `casket/index', and `casket/rdocs' are created in the case that a database directory named as `casket'. `docs' is a database directory of Curia. The key of each record is the ID number of a document, and the value is such attributes as URI. `index' is a database directory of Curia. The key of each record is the normalized form of a word, and the value is an array whose element is a pair of the ID number of a document including the word and its score. `rdocs' is a database file of Villa. The key of each record is the URI of a document, and the value is its ID number.

+ +

In order to use Odeum, you should include `depot.h', `cabin.h', `odeum.h' and `stdlib.h' in the source files. Usually, the following description will be near the beginning of a source file.

+ +
+
#include <depot.h>
+
#include <cabin.h>
+
#include <odeum.h>
+
#include <stdlib.h>
+
+ +

A pointer to `ODEUM' is used as a database handle. A database handle is opened with the function `odopen' and closed with `odclose'. You should not refer directly to any member of the handle. If a fatal error occurs in a database, any access method via the handle except `odclose' will not work and return error status. Although a process is allowed to use multiple database handles at the same time, handles of the same database file should not be used.

+ +

A pointer to `ODDOC' is used as a document handle. A document handle is opened with the function `oddocopen' and closed with `oddocclose'. You should not refer directly to any member of the handle. A document consists of attributes and words. Each word is expressed as a pair of a normalized form and a appearance form.

+ +

Odeum also assign the external variable `dpecode' with the error code. The function `dperrmsg' is used in order to get the message of the error code.

+ +

API

+ +

Structures of `ODPAIR' type is used in order to handle results of search.

+ +
+
typedef struct { int id; int score; } ODPAIR;
+
`id' specifies the ID number of a document. `score' specifies the score calculated from the number of searching words in the document.
+
+ +

The function `odopen' is used in order to get a database handle.

+ +
+
ODEUM *odopen(const char *name, int omode);
+
`name' specifies the name of a database directory. `omode' specifies the connection mode: `OD_OWRITER' as a writer, `OD_OREADER' as a reader. If the mode is `OD_OWRITER', the following may be added by bitwise or: `OD_OCREAT', which means it creates a new database if not exist, `OD_OTRUNC', which means it creates a new database regardless if one exists. Both of `OD_OREADER' and `OD_OWRITER' can be added to by bitwise or: `OD_ONOLCK', which means it opens a database directory without file locking, or `OD_OLCKNB', which means locking is performed without blocking. The return value is the database handle or `NULL' if it is not successful. While connecting as a writer, an exclusive lock is invoked to the database directory. While connecting as a reader, a shared lock is invoked to the database directory. The thread blocks until the lock is achieved. If `OD_ONOLCK' is used, the application is responsible for exclusion control.
+
+ +

The function `odclose' is used in order to close a database handle.

+ +
+
int odclose(ODEUM *odeum);
+
`odeum' specifies a database handle. If successful, the return value is true, else, it is false. Because the region of a closed handle is released, it becomes impossible to use the handle. Updating a database is assured to be written when the handle is closed. If a writer opens a database but does not close it appropriately, the database will be broken.
+
+ +

The function `odput' is used in order to store a document.

+ +
+
int odput(ODEUM *odeum, const ODDOC *doc, int wmax, int over);
+
`odeum' specifies a database handle connected as a writer. `doc' specifies a document handle. `wmax' specifies the max number of words to be stored in the document database. If it is negative, the number is unlimited. `over' specifies whether the data of the duplicated document is overwritten or not. If it is false and the URI of the document is duplicated, the function returns as an error. If successful, the return value is true, else, it is false.
+
+ +

The function `odout' is used in order to delete a document specified by a URI.

+ +
+
int odout(ODEUM *odeum, const char *uri);
+
`odeum' specifies a database handle connected as a writer. `uri' specifies the string of the URI of a document. If successful, the return value is true, else, it is false. False is returned when no document corresponds to the specified URI.
+
+ +

The function `odoutbyid' is used in order to delete a document specified by an ID number.

+ +
+
int odoutbyid(ODEUM *odeum, int id);
+
`odeum' specifies a database handle connected as a writer. `id' specifies the ID number of a document. If successful, the return value is true, else, it is false. False is returned when no document corresponds to the specified ID number.
+
+ +

The function `odget' is used in order to retrieve a document specified by a URI.

+ +
+
ODDOC *odget(ODEUM *odeum, const char *uri);
+
`odeum' specifies a database handle. `uri' specifies the string of the URI of a document. If successful, the return value is the handle of the corresponding document, else, it is `NULL'. `NULL' is returned when no document corresponds to the specified URI. Because the handle of the return value is opened with the function `oddocopen', it should be closed with the function `oddocclose'.
+
+ +

The function `odgetbyid' is used in order to retrieve a document by an ID number.

+ +
+
ODDOC *odgetbyid(ODEUM *odeum, int id);
+
`odeum' specifies a database handle. `id' specifies the ID number of a document. If successful, the return value is the handle of the corresponding document, else, it is `NULL'. `NULL' is returned when no document corresponds to the specified ID number. Because the handle of the return value is opened with the function `oddocopen', it should be closed with the function `oddocclose'.
+
+ +

The function `odgetidbyuri' is used in order to retrieve the ID of the document specified by a URI.

+ +
+
int odgetidbyuri(ODEUM *odeum, const char *uri);
+
`odeum' specifies a database handle. `uri' specifies the string the URI of a document. If successful, the return value is the ID number of the document, else, it is -1. -1 is returned when no document corresponds to the specified URI.
+
+ +

The function `odcheck' is used in order to check whether the document specified by an ID number exists.

+ +
+
int odcheck(ODEUM *odeum, int id);
+
`odeum' specifies a database handle. `id' specifies the ID number of a document. The return value is true if the document exists, else, it is false.
+
+ +

The function `odsearch' is used in order to search the inverted index for documents including a particular word.

+ +
+
ODPAIR *odsearch(ODEUM *odeum, const char *word, int max, int *np);
+
`odeum' specifies a database handle. `word' specifies a searching word. `max' specifies the max number of documents to be retrieve. `np' specifies the pointer to a variable to which the number of the elements of the return value is assigned. If successful, the return value is the pointer to an array, else, it is `NULL'. Each element of the array is a pair of the ID number and the score of a document, and sorted in descending order of their scores. Even if no document corresponds to the specified word, it is not error but returns an dummy array. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Note that each element of the array of the return value can be data of a deleted document.
+
+ +

The function `odsearchnum' is used in order to get the number of documents including a word.

+ +
+
int odsearchdnum(ODEUM *odeum, const char *word);
+
`odeum' specifies a database handle. `word' specifies a searching word. If successful, the return value is the number of documents including the word, else, it is -1. Because this function does not read the entity of the inverted index, it is faster than `odsearch'.
+
+ +

The function `oditerinit' is used in order to initialize the iterator of a database handle.

+ +
+
int oditerinit(ODEUM *odeum);
+
`odeum' specifies a database handle. If successful, the return value is true, else, it is false. The iterator is used in order to access every document stored in a database.
+
+ +

The function `oditernext' is used in order to get the next key of the iterator.

+ +
+
ODDOC *oditernext(ODEUM *odeum);
+
`odeum' specifies a database handle. If successful, the return value is the handle of the next document, else, it is `NULL'. `NULL' is returned when no document is to be get out of the iterator. It is possible to access every document by iteration of calling this function. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of string matches the one of the traversal access. Because the handle of the return value is opened with the function `oddocopen', it should be closed with the function `oddocclose'.
+
+ +

The function `odsync' is used in order to synchronize updating contents with the files and the devices.

+ +
+
int odsync(ODEUM *odeum);
+
`odeum' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. This function is useful when another process uses the connected database directory.
+
+ +

The function `odoptimize' is used in order to optimize a database.

+ +
+
int odoptimize(ODEUM *odeum);
+
`odeum' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. Elements of the deleted documents in the inverted index are purged.
+
+ +

The function `odname' is used in order to get the name of a database.

+ +
+
char *odname(ODEUM *odeum);
+
`odeum' specifies a database handle. If successful, the return value is the pointer to the region of the name of the database, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `odfsiz' is used in order to get the total size of database files.

+ +
+
double odfsiz(ODEUM *odeum);
+
`odeum' specifies a database handle. If successful, the return value is the total size of the database files, else, it is -1.0.
+
+ +

The function `odbnum' is used in order to get the total number of the elements of the bucket arrays in the inverted index.

+ +
+
int odbnum(ODEUM *odeum);
+
`odeum' specifies a database handle. If successful, the return value is the total number of the elements of the bucket arrays, else, it is -1.
+
+ +

The function `odbusenum' is used in order to get the total number of the used elements of the bucket arrays in the inverted index.

+ +
+
int odbusenum(ODEUM *odeum);
+
`odeum' specifies a database handle. If successful, the return value is the total number of the used elements of the bucket arrays, else, it is -1.
+
+ +

The function `oddnum' is used in order to get the number of the documents stored in a database.

+ +
+
int oddnum(ODEUM *odeum);
+
`odeum' specifies a database handle. If successful, the return value is the number of the documents stored in the database, else, it is -1.
+
+ +

The function `odwnum' is used in order to get the number of the words stored in a database.

+ +
+
int odwnum(ODEUM *odeum);
+
`odeum' specifies a database handle. If successful, the return value is the number of the words stored in the database, else, it is -1. Because of the I/O buffer, the return value may be less than the hard number.
+
+ +

The function `odwritable' is used in order to check whether a database handle is a writer or not.

+ +
+
int odwritable(ODEUM *odeum);
+
`odeum' specifies a database handle. The return value is true if the handle is a writer, false if not.
+
+ +

The function `odfatalerror' is used in order to check whether a database has a fatal error or not.

+ +
+
int odfatalerror(ODEUM *odeum);
+
`odeum' specifies a database handle. The return value is true if the database has a fatal error, false if not.
+
+ +

The function `odinode' is used in order to get the inode number of a database directory.

+ +
+
int odinode(ODEUM *odeum);
+
`odeum' specifies a database handle. The return value is the inode number of the database directory.
+
+ +

The function `odmtime' is used in order to get the last modified time of a database.

+ +
+
time_t odmtime(ODEUM *odeum);
+
`odeum' specifies a database handle. The return value is the last modified time of the database.
+
+ +

The function `odmerge' is used in order to merge plural database directories.

+ +
+
int odmerge(const char *name, const CBLIST *elemnames);
+
`name' specifies the name of a database directory to create. `elemnames' specifies a list of names of element databases. If successful, the return value is true, else, it is false. If two or more documents which have the same URL come in, the first one is adopted and the others are ignored.
+
+ +

The function `odremove' is used in order to remove a database directory.

+ +
+
int odremove(const char *name);
+
`name' specifies the name of a database directory. If successful, the return value is true, else, it is false. A database directory can contain databases of other APIs of QDBM, they are also removed by this function.
+
+ +

The function `oddocopen' is used in order to get a document handle.

+ +
+
ODDOC *oddocopen(const char *uri);
+
`uri' specifies the URI of a document. The return value is a document handle. The ID number of a new document is not defined. It is defined when the document is stored in a database.
+
+ +

The function `oddocclose' is used in order to close a document handle.

+ +
+
void oddocclose(ODDOC *doc);
+
`doc' specifies a document handle. Because the region of a closed handle is released, it becomes impossible to use the handle.
+
+ +

The function `oddocaddattr' is used in order to add an attribute to a document.

+ +
+
void oddocaddattr(ODDOC *doc, const char *name, const char *value);
+
`doc' specifies a document handle. `name' specifies the string of the name of an attribute. `value' specifies the string of the value of the attribute.
+
+ +

The function `oddocaddword' is used in order to add a word to a document.

+ +
+
void oddocaddword(ODDOC *doc, const char *normal, const char *asis);
+
`doc' specifies a document handle. `normal' specifies the string of the normalized form of a word. Normalized forms are treated as keys of the inverted index. If the normalized form of a word is an empty string, the word is not reflected in the inverted index. `asis' specifies the string of the appearance form of the word. Appearance forms are used after the document is retrieved by an application.
+
+ +

The function `oddocid' is used in order to get the ID number of a document.

+ +
+
int oddocid(const ODDOC *doc);
+
`doc' specifies a document handle. The return value is the ID number of a document.
+
+ +

The function `oddocuri' is used in order to get the URI of a document.

+ +
+
const char *oddocuri(const ODDOC *doc);
+
`doc' specifies a document handle. The return value is the string of the URI of a document.
+
+ +

The function `oddocgetattr' is used in order to get the value of an attribute of a document.

+ +
+
const char *oddocgetattr(const ODDOC *doc, const char *name);
+
`doc' specifies a document handle. `name' specifies the string of the name of an attribute. The return value is the string of the value of the attribute, or `NULL' if no attribute corresponds.
+
+ +

The function `oddocnwords' is used in order to get the list handle contains words in normalized form of a document.

+ +
+
const CBLIST *oddocnwords(const ODDOC *doc);
+
`doc' specifies a document handle. The return value is the list handle contains words in normalized form.
+
+ +

The function `oddocawords' is used in order to get the list handle contains words in appearance form of a document.

+ +
+
const CBLIST *oddocawords(const ODDOC *doc);
+
`doc' specifies a document handle. The return value is the list handle contains words in appearance form.
+
+ +

The function `oddocscores' is used in order to get the map handle contains keywords in normalized form and their scores.

+ +
+
CBMAP *oddocscores(const ODDOC *doc, int max, ODEUM *odeum);
+
`doc' specifies a document handle. `max' specifies the max number of keywords to get. `odeum' specifies a database handle with which the IDF for weighting is calculate. If it is `NULL', it is not used. The return value is the map handle contains keywords and their scores. Scores are expressed as decimal strings. Because the handle of the return value is opened with the function `cbmapopen', it should be closed with the function `cbmapclose' if it is no longer in use.
+
+ +

The function `odbreaktext' is used in order to break a text into words in appearance form.

+ +
+
CBLIST *odbreaktext(const char *text);
+
`text' specifies the string of a text. The return value is the list handle contains words in appearance form. Words are separated with space characters and such delimiters as period, comma and so on. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.
+
+ +

The function `odnormalizeword' is used in order to make the normalized form of a word.

+ +
+
char *odnormalizeword(const char *asis);
+
`asis' specifies the string of the appearance form of a word. The return value is is the string of the normalized form of the word. Alphabets of the ASCII code are unified into lower cases. Words composed of only delimiters are treated as empty strings. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `odpairsand' is used in order to get the common elements of two sets of documents.

+ +
+
ODPAIR *odpairsand(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np);
+
`apairs' specifies the pointer to the former document array. `anum' specifies the number of the elements of the former document array. `bpairs' specifies the pointer to the latter document array. `bnum' specifies the number of the elements of the latter document array. `np' specifies the pointer to a variable to which the number of the elements of the return value is assigned. The return value is the pointer to a new document array whose elements commonly belong to the specified two sets. Elements of the array are sorted in descending order of their scores. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `odpairsor' is used in order to get the sum of elements of two sets of documents.

+ +
+
ODPAIR *odpairsor(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np);
+
`apairs' specifies the pointer to the former document array. `anum' specifies the number of the elements of the former document array. `bpairs' specifies the pointer to the latter document array. `bnum' specifies the number of the elements of the latter document array. `np' specifies the pointer to a variable to which the number of the elements of the return value is assigned. The return value is the pointer to a new document array whose elements belong to both or either of the specified two sets. Elements of the array are sorted in descending order of their scores. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `odpairsnotand' is used in order to get the difference set of documents.

+ +
+
ODPAIR *odpairsnotand(ODPAIR *apairs, int anum, ODPAIR *bpairs, int bnum, int *np);
+
`apairs' specifies the pointer to the former document array. `anum' specifies the number of the elements of the former document array. `bpairs' specifies the pointer to the latter document array of the sum of elements. `bnum' specifies the number of the elements of the latter document array. `np' specifies the pointer to a variable to which the number of the elements of the return value is assigned. The return value is the pointer to a new document array whose elements belong to the former set but not to the latter set. Elements of the array are sorted in descending order of their scores. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.
+
+ +

The function `odpairssort' is used in order to sort a set of documents in descending order of scores.

+ +
+
void odpairssort(ODPAIR *pairs, int pnum);
+
`pairs' specifies the pointer to a document array. `pnum' specifies the number of the elements of the document array.
+
+ +

The function `odlogarithm' is used in order to get the natural logarithm of a number.

+ +
+
double odlogarithm(double x);
+
`x' specifies a number. The return value is the natural logarithm of the number. If the number is equal to or less than 1.0, the return value is 0.0. This function is useful when an application calculates the IDF of search results.
+
+ +

The function `odvectorcosine' is used in order to get the cosine of the angle of two vectors.

+ +
+
double odvectorcosine(const int *avec, const int *bvec, int vnum);
+
`avec' specifies the pointer to one array of numbers. `bvec' specifies the pointer to the other array of numbers. `vnum' specifies the number of elements of each array. The return value is the cosine of the angle of two vectors. This function is useful when an application calculates similarity of documents.
+
+ +

The function `odsettuning' is used in order to set the global tuning parameters.

+ +
+
void odsettuning(int ibnum, int idnum, int cbnum, int csiz);
+
`ibnum' specifies the number of buckets for inverted indexes. `idnum' specifies the division number of inverted index. `cbnum' specifies the number of buckets for dirty buffers. `csiz' specifies the maximum bytes to use memory for dirty buffers. The default setting is equivalent to `odsettuning(32749, 7, 262139, 8388608)'. This function should be called before opening a handle.
+
+ +

The function `odanalyzetext' is used in order to break a text into words and store appearance forms and normalized form into lists.

+ +
+
void odanalyzetext(ODEUM *odeum, const char *text, CBLIST *awords, CBLIST *nwords);
+
`odeum' specifies a database handle. `text' specifies the string of a text. `awords' specifies a list handle into which appearance form is store. `nwords' specifies a list handle into which normalized form is store. If it is `NULL', it is ignored. Words are separated with space characters and such delimiters as period, comma and so on.
+
+ +

The function `odsetcharclass' is used in order to set the classes of characters used by `odanalyzetext'.

+ +
+
void odsetcharclass(ODEUM *odeum, const char *spacechars, const char *delimchars, const char *gluechars);
+
`odeum' specifies a database handle. `spacechars' spacifies a string contains space characters. `delimchars' spacifies a string contains delimiter characters. `gluechars' spacifies a string contains glue characters.
+
+ +

The function `odquery' is used in order to query a database using a small boolean query language.

+ +
+
ODPAIR *odquery(ODEUM *odeum, const char *query, int *np, CBLIST *errors);
+
`odeum' specifies a database handle. 'query' specifies the text of the query. `np' specifies the pointer to a variable to which the number of the elements of the return value is assigned. `errors' specifies a list handle into which error messages are stored. If it is `NULL', it is ignored. If successful, the return value is the pointer to an array, else, it is `NULL'. Each element of the array is a pair of the ID number and the score of a document, and sorted in descending order of their scores. Even if no document corresponds to the specified condition, it is not error but returns an dummy array. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Note that each element of the array of the return value can be data of a deleted document.
+
+ +

Examples

+ +

The following example stores a document into the database.

+ +
#include <depot.h>
+#include <cabin.h>
+#include <odeum.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define DBNAME   "index"
+
+int main(int argc, char **argv){
+  ODEUM *odeum;
+  ODDOC *doc;
+  CBLIST *awords;
+  const char *asis;
+  char *normal;
+  int i;
+
+  /* open the database */
+  if(!(odeum = odopen(DBNAME, OD_OWRITER | OD_OCREAT))){
+    fprintf(stderr, "odopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* get the document handle */
+  doc = oddocopen("http://www.foo.bar/baz.txt");
+
+  /* set attributes of the document */
+  oddocaddattr(doc, "title", "Balcony Scene");
+  oddocaddattr(doc, "author", "Shakespeare");
+
+  /* break the text and get the word list */
+  awords = odbreaktext("Parting is such sweet sorrow.");
+
+  /* set each word into the document handle */
+  for(i = 0; i < cblistnum(awords); i++){
+    /* get one word of the list */
+    asis = cblistval(awords, i, NULL);
+    /* get the normalized form from the appearance form */
+    normal = odnormalizeword(asis);
+    /* add the word into the document handle */
+    oddocaddword(doc, normal, asis);
+    /* release the region of the normalized form */
+    free(normal);
+  }
+
+  /* store the document into the database */
+  if(!odput(odeum, doc, -1, 1)){
+    fprintf(stderr, "odput: %s\n", dperrmsg(dpecode));
+  }
+
+  /* release the word list */
+  cblistclose(awords);
+
+  /* release the document handle */
+  oddocclose(doc);
+
+  /* close the database */
+  if(!odclose(odeum)){
+    fprintf(stderr, "odclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

The following example retrieves documents.

+ +
#include <depot.h>
+#include <cabin.h>
+#include <odeum.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define DBNAME   "index"
+
+int main(int argc, char **argv){
+  ODEUM *odeum;
+  ODPAIR *pairs;
+  ODDOC *doc;
+  const CBLIST *words;
+  const char *title, *author, *asis;
+  int i, j, pnum;
+
+  /* open the database */
+  if(!(odeum = odopen(DBNAME, OD_OREADER))){
+    fprintf(stderr, "odopen: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  /* retrieve documents */
+  if((pairs = odsearch(odeum, "sorrow", -1, &pnum)) != NULL){
+
+    /* scan each element of the document array */
+    for(i = 0; i < pnum; i++){
+      /* get the document handle */
+      if(!(doc = odgetbyid(odeum, pairs[i].id))) continue;
+      /* show the attributes */
+      printf("URI: %s\n", oddocuri(doc));
+      title = oddocgetattr(doc, "title");
+      if(title) printf("TITLE: %s\n", title);
+      author = oddocgetattr(doc, "author");
+      if(author) printf("AUTHOR: %s\n", author);
+      /* show words in appearance form */
+      printf("WORDS:");
+      words = oddocawords(doc);
+      for(j = 0; j < cblistnum(words); j++){
+        asis = cblistval(words, j, NULL);
+        printf(" %s", asis);
+      }
+      putchar('\n');
+      /* release the document handle */
+      oddocclose(doc);
+    }
+
+    /* release the document array */
+    free(pairs);
+
+  } else {
+    fprintf(stderr, "odsearch: %s\n", dperrmsg(dpecode));
+  }
+
+  /* close the database */
+  if(!odclose(odeum)){
+    fprintf(stderr, "odclose: %s\n", dperrmsg(dpecode));
+    return 1;
+  }
+
+  return 0;
+}
+
+ +

Notes

+ +

How to build programs using Odeum is the same as the case of Depot.

+ +
gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
+
+ +

If QDBM was built with POSIX thread enabled, the global variable `dpecode' is treated as thread specific data, and functions of Odeum are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.

+ +

If QDBM was built with ZLIB enabled, records in the database for document attributes are compressed. In that case, the size of the database is reduced to 30% or less. Thus, you should enable ZLIB if you use Odeum. A database of Odeum created without ZLIB enabled is not available on environment with ZLIB enabled, and vice versa. If ZLIB was not enabled but LZO, LZO is used instead.

+ +

Query Language

+ +

The query language of the function `odquery' is a basic language following this grammar:

+ +
expr ::= subexpr ( op subexpr )*
+subexpr ::= WORD
+subexpr ::= LPAREN expr RPAREN
+
+ +

Operators are "&" (AND), "|" (OR), and "!" (NOTAND). You can use parenthesis to group sub-expressions together in order to change order of operations. The given query is broken up using the function `odanalyzetext', so if you want to specify different text breaking rules, then make sure that you at least set "&", "|", "!", "(", and ")" to be delimiter characters. Consecutive words are treated as having an implicit "&" operator between them, so "zed shaw" is actually "zed & shaw".

+ +

The encoding of the query text should be the same with the encoding of target documents. Moreover, each of space characters, delimiter characters, and glue characters should be single byte.

+ +
+ +

Commands for Odeum

+ +

Odeum has the following command line interfaces.

+ +

The command `odmgr' is a utility for debugging Odeum and its applications. It features editing and checking of a database. It can be used for full-text search systems with shell scripts. This command is used in the following format. `name' specifies a database name. `file' specifies a file name, `expr' specifies the URI or the ID number of a document, `words' specifies searching words. `elems' specifies element databases.

+ +
+
odmgr create name
+
Create a database file.
+
odmgr put [-uri str] [-title str] [-author str] [-date str] [-wmax num] [-keep] name [file]
+
Add a document by reading a file. If `file' is omitted, the standard input is read and URI is needed.
+
odmgr out [-id] name expr
+
Delete a document specified by a URI.
+
odmgr get [-id] [-t|-h] name expr
+
Show a document specified by a URI. The output is the ID number and the URI of a document, in tab separated format.
+
odmgr search [-max num] [-or] [-idf] [-t|-h|-n] name words...
+
Retrieve documents including specified words. The first line of the output is the total number of hits and each word with its number of hits, in tab separated format. The second line and below are the ID numbers and the scores of documents, in tab separated format.
+
odmgr list [-t|-h] name
+
Show all documents in a database. Each line of the output is the ID number and the score of a document, in tab separated format.
+
odmgr optimize name
+
Optimize a database.
+
odmgr inform name
+
Output miscellaneous information.
+
odmgr merge name elems...
+
Merge plural databases.
+
odmgr remove name
+
Remove a database directory.
+
odmgr break [-h|-k|-s] [file]
+
Read a file and output words in the text. Each line of the output is the appearance form and the normalized form of a word, in tab separated format.
+
odmgr version
+
Output version information of QDBM.
+
+ +

Options feature the following.

+ +
    +
  • -uri str : specify the URI of the document explicitly.
  • +
  • -title str : specify the title of the document.
  • +
  • -author str : specify the author of the document.
  • +
  • -date str : specify the modified date of the document.
  • +
  • -wmax num : specify the max number of words to be stored.
  • +
  • -keep : the storing mode is not to be overwrite.
  • +
  • -id : specify a document not by a URI but by an ID number.
  • +
  • -t : output the details of a document in tab separated format.
  • +
  • -h : output the details of a document in human-readable format.
  • +
  • -k : output keywords of a document.
  • +
  • -s : output summary of a document.
  • +
  • -max num : specify the max number of documents of the output.
  • +
  • -or : perform OR search, nut AND search.
  • +
  • -idf : tune scores with IDF.
  • +
  • -n : show ID numbers and scores only.
  • +
+ +

This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.

+ +

The command `odtest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `dnum' specifies the number of the documents. `wnum' specifies the number of words per document. `pnum' specifies the number of patterns of words.

+ +
+
odtest write [-tune ibnum idnum cbnum csiz] name dnum wnum pnum
+
Store documents with random attributes and random words.
+
odtest read name
+
Retrieve all documents of the database above.
+
odtest combo name
+
Perform combination test of various operations.
+
odtest wicked name dnum
+
Perform updating operations selected at random.
+
+ +

Options feature the following.

+ +
    +
  • -tune ibnum idnum cbnum csiz : set tuning parameters.
  • +
+ +

This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.

+ +

The command `odidx' is a utility for indexing files on the local file system. This command is useful for a full-text search system of a Web site. Supported file format are plain text and HTML. Supported character encoding are US-ASCII and ISO-8859-1. The URI of each document is specified with the path of its file. Attributes named as `title' and `date' are given to each documents. When a document is already existing in the database, it is registered if its last modification time is newer, or it is ignored. Modification times are stored in the sub database `_mtime' in the main database directory. Score information are stored in the sub database `_score' in the main database directory. This command is used in the following format. `name' specifies a database name. `dir' specifies a directory name.

+ +
+
odidx register [-l file] [-wmax num] [-tsuf sufs] [-hsuf sufs] name [dir]
+
Register files in the specified directory. If `dir' is omitted, the current directory is specified.
+
odidx relate name
+
Add score information for relational document search to each documents in the database.
+
odidx purge name
+
Purge documents which are not existing on the local files system.
+
+ +

Options feature the following.

+ +
    +
  • -l file : read a file and get list of paths of files to register. If `-' is specified, the standard input is read.
  • +
  • -wmax num : specify the max number of words to be stored in the document database.
  • +
  • -tsuf sufs : specify suffixes of plain text files in comma separated format. The default is `-tsuf .txt,.text'.
  • +
  • -hsuf sufs : specify suffixes of HTML files in comma separated format. The default is `-hsuf .html,.htm'.
  • +
+ +

This command returns 0 on success, another on failure.

+ +

Commands of Odeum make it easy to realize a full-text search system. For example, to register files which are under `/home/mikio' and whose suffix are `.txt', `.c', or `.h', perform the following command.

+ +
odidx register -tsuf ".txt,.c,.h" -hsuf "" casket /home/mikio
+
+ +

Thus, to retrieve documents which include `unix' and `posix' and show the top 8 terms, perform the following command.

+ +
odmgr search -max 8 -h casket "unix posix"
+
+ +

A database generated by `odidx' is available with the CGI script which is included in QDBM for full-text search.

+ +
+ +

File Format

+ +

File Format of Depot

+ +

The contents of a database file managed by Depot is divided roughly into the following three sections: the header section, the bucket section and the record section.

+ +

The header section places at the beginning of the file and its length is constant 48 bytes. The following information are stored in the header section.

+ +
    +
  1. magic number: from offset 0, contains "[DEPOT]\n\f" for big endian or "[depot]\n\f" for little endian.
  2. +
  3. version number: decimal string of the version number of the library.
  4. +
  5. flags for wrappers: from offset 16, type of `int'.
  6. +
  7. file size: from offset 24, type of `int'.
  8. +
  9. number of the bucket: from offset 32, type of `int'.
  10. +
  11. number of records: from offset 40, type of `int'.
  12. +
+ +

The bucket section places after the header section and its length is determined according to the number of the bucket. Each element of the bucket stores an offset of the root node of each separate chain.

+ +

The record section places after the bucket section and occupies to the end of the file. The element of the record section contains the following information.

+ +
    +
  1. flags: type of `int'.
  2. +
  3. second hash value: type of `int'.
  4. +
  5. size of the key: type of `int'.
  6. +
  7. size of the value: type of `int'.
  8. +
  9. size of the padding: type of `int'.
  10. +
  11. offset of the left child: type of `int'.
  12. +
  13. offset of the right child: type of `int'.
  14. +
  15. entity of the key: serial bytes with variable length.
  16. +
  17. entity of the value: serial bytes with variable length.
  18. +
  19. padding data: void serial bytes with variable length.
  20. +
+ +

File Format of Villa

+ +

Every data handled by Villa is stored in a database of Depot. Storing data is divided into meta data and logical pages. Logical pages can be classified into leaf nodes and non-leaf nodes. Meta data are such managing information as the number of records. Both of its key and its value are type of `int'. Leaf nodes hold records. Non-leaf nodes hold sparse index referring to pages.

+ +

Villa uses variable length numeric format (BER compression) to handle small natural number with frugal storage. A variable length numeric object is parsed from the top of the region and parsing ends at the byte of positive value. Each byte are evaluated as absolute value and calculated as little endian number based on the radix 128.

+ +

Record is logical unit of user data. Some records overlapping keys are shaped into one physical record. A Physical record is serialized in the following format.

+ +
    +
  1. size of the key: type of variable length number
  2. +
  3. entity of the key: serial bytes with variable length
  4. +
  5. number of values: type of variable length number
  6. +
  7. list of values: serial bytes repeating the following expressions
      +
    1. size: type of variable length number
    2. +
    3. entity of the key: serial bytes with variable length
    4. +
  8. +
+ +

Leaf node is physical unit to store a set of records. The key of a leaf node is its ID whose type is `int'. A leaf node is stored in a database of Depot with the following values. Its records are sorted in ascending order of each key.

+ +
    +
  1. ID of the previous leaf: type of variable length number
  2. +
  3. ID of the next leaf: type of variable length number
  4. +
  5. list of records: concatenation of serialized records
  6. +
+ +

Index is logical unit of a pointer to search for pages. An index is serialized int the following format.

+ +
    +
  1. ID of the referring page: type of variable length number
  2. +
  3. size of the key: type of variable length number
  4. +
  5. entity of the key: serial bytes with variable length
  6. +
+ +

Non-leaf node is physical unit to store a set of indexes. The key of a non-leaf node is its ID whose type is `int'. A non-leaf node is stored in a database of Depot with the following values. Its indexes are sorted in ascending order of each key.

+ +
    +
  1. ID of the first child node: type of variable length number
  2. +
  3. list of indexes: concatenation of serialized indexes
  4. +
+ +

Notes

+ +

Because the database file is not sparse, move, copy, unlink, ftp, and so on with the file are possible. Because Depot reads and writes data without normalization of byte order, it is impossible to share the same file between the environment with different byte order.

+ +

When you distribute a database file of Depot or Villa via network, the MIME type suggested to be `application/x-qdbm'. Suffix of the file name is suggested to be `.qdb'. When you distribute a database directory of Curia, you may convert the directory tree to an archive of such type as TAR.

+ +

For the command `file' to recognize database files, append the following expressions into `magic' file.

+ +
0       string          [DEPOT]\n\f     QDBM, big endian
+>12     string          x               \b, version=%s
+>19     byte            ^1              \b, Hash
+>19     byte            &1              \b, B+ tree
+>19     byte            &2              \b (deflated:ZLIB)
+>19     byte            &4              \b (deflated:LZO)
+>19     byte            &8              \b (deflated:BZIP2)
+>24     belong          x               \b, filesize=%d
+>32     belong          x               \b, buckets=%d
+>40     belong          x               \b, records=%d
+0       string          [depot]\n\f     QDBM, little endian
+>12     string          x               \b, version=%s
+>16     byte            ^1              \b, Hash
+>16     byte            &1              \b, B+ tree
+>16     byte            &2              \b (deflated:ZLIB)
+>16     byte            &4              \b (deflated:LZO)
+>16     byte            &8              \b (deflated:BZIP2)
+>24     lelong          x               \b, filesize=%d
+>32     lelong          x               \b, buckets=%d
+>40     lelong          x               \b, records=%d
+
+ +
+ +

Porting

+ +

One of the goal of QDBM is to work on all platforms which conform to POSIX. Even if some APIs are not implemented, QDBM should work. Moreover, it should be possible to build QDBM using compilers other than GCC. Porting to various platforms is performed to add a new `Makefile' or modify some parts of source files. As for APIs of C, some of the following files should be modified. Otherwise, you can create new files based on them.

+ +
    +
  • Makefile.in : base of `Makefile', used by `./configure'.
  • +
  • myconf.h : configuration of system dependency.
  • +
  • depot.h : header of the basic API.
  • +
  • curia.h : header of the extended API.
  • +
  • relic.h : header of the NDBM-compatible API.
  • +
  • hovel.h : header of the GDBM-compatible API.
  • +
  • cabin.h : header of the utility API.
  • +
  • villa.h : header of the advanced API.
  • +
  • vista.h : header of the extended advanced API.
  • +
  • odeum.h : header of the inverted API.
  • +
  • myconf.c : implementation of system dependency.
  • +
  • depot.c : implementation of the basic API.
  • +
  • curia.c : implementation of the extended API.
  • +
  • relic.c : implementation of the NDBM-compatible API.
  • +
  • hovel.c : implementation of the GDBM-compatible API.
  • +
  • cabin.c : implementation of the utility API.
  • +
  • villa.c : implementation of the advanced API.
  • +
  • vista.c : implementation of the extended advanced API.
  • +
  • odeum.c : implementation of the inverted API.
  • +
+ +

On platforms which do not support file locking with `fcntl' call, you should append `-DMYNOLOCK' to the macro `CFLAGS' defined in `Makefile'. In that case, you should consider another exclusion control. As with it, on platforms without `mmap' call, you should append `-DMYNOMMAP' to `CFLAGS'. As for `mmap', its emulation using `malloc' and so on is provided. If other system calls are not implemented, you should define emulation by modification of `myconf.h' and `myconf.c'.

+ +

Because POSIX thread is used in C++ API, it is impossible to port C++ API to platforms without the package. Because JNI is used in Java API, you should pay attention to location of the headers and libraries. Moreover, you should consider such type definitions as `long long' or `int64'. Because APIs of Perl and Ruby use building commands provided with each language system, you should be knowledgeable about their specifications.

+ +
+ +

Bugs

+ +

Each document of QDBM should be calibrated by native English speakers.

+ +

There is no such bug which are found but not fixed, as crash by segmentation fault, unexpected data vanishing, memory leak and so on.

+ +

If you find any bug, report it to the author, with the information of the version of QDBM, the operating system and the compiler.

+ +

Databases created with QDBM version 1.7.13 or earlier are not compatible to ones of the later versions.

+ +
+ +

Frequently Asked Questions

+ +
+
Q. : Does QDBM support SQL?
+
A. : No, it does not. QDBM is not a RDBMS (Relational Database Management System). If you want an embedded RDBMS, use SQLite and so on.
+
Q. : After all, how different from GDBM (NDBM, SDBM, Berkeley DB)?
+
A. : Processing speed is higher, a database file is smaller, API is simpler. A highly important thing is that efficiency in time and space is very good when records are frequently overwritten, so, scalability in practical use is high. Moreover, even when constructing such a large database that the number of storing record is more than one million, processing speed does not slowdown deathly, filesize does not grow extremely. However, because other DBM or DBMS may be more suitable in some cases, comparing performance and functionality by yourself is suggested.
+
Q. : Which API should I use?
+
A. : If you search for records as complete accord, try Depot. If the scale is large, try Curia. If you access records in some order, try Villa. If the scale is large, try Vista. If you pursue the greatest number of records, build QDBM with ZLIB or LZO enabled and use Vista.
+
Q. : What is bibliography?
+
A. : Algorithms of QDBM are mainly based on the descriptions in `Data Structures and Algorithms' by Aho et al and `Algorithms in C' by Sedgewick.
+
Q. : Are there good sample codes for applications?
+
A. : Refer to the source code of commands of each API. `dptsv.c', `crtsv.c' and `vltsv.c' are simplest.
+
Q. : My database file has been broken. Why?
+
A. : In most cases, the reason is that your application did not close the database on exit. No matter whether it is a demon process or a CGI script, any application should close handling databases when it exits. Moreover, we should remember that a process of CGI may be killed by SIGPIPE or SIGTERM.
+
Q. : How robust are databases of QDBM?
+
A. : QDBM does not assure absolute robustness. A database may be broken if your operating system crashes. Although transaction of Villa can save a database from crashes of applications, it is inadequate to crashes of operating systems. So, you should consider multiplexing of a database or backup system if you use QDBM for mission critical applications.
+
Q: How should I use alignment of Depot and Curia?
+
A: If your application repeats writing with overwrite or concatenate mode. Alignment saves the rapid growth of the size of the database file. Because the best suited size of alignment of each application is different, you should learn it by experiment. For the meantime, about 32 is suitable.
+
Q. : How should I tune performance parameters of Villa?
+
A. : If you perform mainly ordering access, `lrecmax' and `nidxmax' should be larger. If you perform mainly random access, they should be less. If RAM of your system is abundant, `lcnum' and `ncnum' should be increased in order to improve performance. If ZLIB, LZO, or BZIP2 is enabled, increase `lrecmax' and compression efficiency is improved.
+
Q. : Which is the most preferable of ZLIB, LZO or BZIP2 for Villa?
+
A. : BZIP2 has the best compression retio. LZO has the best compression speed. ZLIB takes a mean position of them. If you don't have any special reason, using ZLIB is suggested. However, if updating of the database is frequent, LZO is more preferable. If updating of the database is very infrequently, BZIP2 is more preferable. Note that the license of LZO is the GNU LGPL.
+
Q. : What is `sparse file'?
+
A. : It is a file where some holes are. `Hole' means a block where any data has never written in. If a file system supports sparse file, holes are not allocated into any physical storage. As for QDBM, if a database is created with such flags as DP_OSPARSE, the bucket array is not initialized and its blocks become holes. According to that mechanism, you can use greatly huge hash tables. However, its performance is strongly depends on the setting of the file system.
+
Q. : Why Depot and Curia do not feature transaction?
+
A. : If an application implements its own transaction, inner transaction of database is superfluous. You can implement transaction for application easily with hash map provided by Cabin.
+
Q. : How should I tune the system for performance?
+
A. : Install more RAM on your machine than the size of a database. Then, enlarge I/O buffer and cut down on flushing dirty buffers. File system is also important. On Linux, although EXT2 is usually fastest, EXT3 is faster in some cases. ReiserFS is okey. The other modes of EXT3 are very slow. About other file systems, you should learn them by experiment.
+
Q. : Can I build QDBM using `cc' instead of `gcc'?
+
A. : Yes. Try to build QDBM with `LTmakefile'.
+
Q. : Can I build QDBM using Visual C++?
+
A. : Yes. Use `VCmakefile' instead of `Makefile'.
+
Q. : Can I use QDBM in other languages?
+
A. : As for PHP, Scheme (Gauche), and OCaml, interfaces of QDBM have been released. If you need it for another language, try to turn it out.
+
Q. : What does `QDBM' mean?
+
A. : `QDBM' stands for `Quick Database Manager'. It means that processing speed is high, and that you can write applications quickly.
+
+ +
+ +

Copying

+ +

QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License or any later version.

+ +

QDBM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

+ +

You should have received a copy of the GNU Lesser General Public License along with QDBM (See the file `COPYING'); if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

+ +

QDBM was written by Mikio Hirabayashi. You can contact the author by e-mail to `mikio@users.sourceforge.net'. However, as for topics which can be shared among other users, please send it to the mailing list. To join the mailing list, refer to `http://lists.sourceforge.net/lists/listinfo/qdbm-users'.

+ +
+ + + + + + diff --git a/qdbm/villa.c b/qdbm/villa.c new file mode 100644 index 00000000..0783ac5d --- /dev/null +++ b/qdbm/villa.c @@ -0,0 +1,2666 @@ +/************************************************************************************************* + * Implementation of Villa + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#define QDBM_INTERNAL 1 + +#include "villa.h" +#include "myconf.h" + +#define VL_LEAFIDMIN 1 /* minimum number of leaf ID */ +#define VL_NODEIDMIN 100000000 /* minimum number of node ID */ +#define VL_VNUMBUFSIZ 8 /* size of a buffer for variable length number */ +#define VL_NUMBUFSIZ 32 /* size of a buffer for a number */ +#define VL_PAGEBUFSIZ 32768 /* size of a buffer to read each page */ +#define VL_MAXLEAFSIZ 49152 /* maximum size of each leaf */ +#define VL_DEFLRECMAX 49 /* default number of records in each leaf */ +#define VL_DEFNIDXMAX 192 /* default number of indexes in each node */ +#define VL_DEFLCNUM 1024 /* default number of leaf cache */ +#define VL_DEFNCNUM 512 /* default number of node cache */ +#define VL_CACHEOUT 8 /* number of pages in a process of cacheout */ +#define VL_INITBNUM 32749 /* initial bucket number */ +#define VL_PAGEALIGN -3 /* alignment for pages */ +#define VL_FBPOOLSIZ 128 /* size of free block pool */ +#define VL_PATHBUFSIZ 1024 /* size of a path buffer */ +#define VL_TMPFSUF MYEXTSTR "vltmp" /* suffix of a temporary file */ +#define VL_ROOTKEY -1 /* key of the root key */ +#define VL_LASTKEY -2 /* key of the last key */ +#define VL_LNUMKEY -3 /* key of the number of leaves */ +#define VL_NNUMKEY -4 /* key of the number of nodes */ +#define VL_RNUMKEY -5 /* key of the number of records */ +#define VL_CRDNUM 7 /* default division number for Vista */ + +/* set a buffer for a variable length number */ +#define VL_SETVNUMBUF(VL_len, VL_buf, VL_num) \ + do { \ + int _VL_num; \ + _VL_num = VL_num; \ + if(_VL_num == 0){ \ + ((signed char *)(VL_buf))[0] = 0; \ + (VL_len) = 1; \ + } else { \ + (VL_len) = 0; \ + while(_VL_num > 0){ \ + int _VL_rem = _VL_num & 0x7f; \ + _VL_num >>= 7; \ + if(_VL_num > 0){ \ + ((signed char *)(VL_buf))[(VL_len)] = -_VL_rem - 1; \ + } else { \ + ((signed char *)(VL_buf))[(VL_len)] = _VL_rem; \ + } \ + (VL_len)++; \ + } \ + } \ + } while(FALSE) + +/* read a variable length buffer */ +#define VL_READVNUMBUF(VL_buf, VL_size, VL_num, VL_step) \ + do { \ + int _VL_i, _VL_base; \ + (VL_num) = 0; \ + _VL_base = 1; \ + if((VL_size) < 2){ \ + (VL_num) = ((signed char *)(VL_buf))[0]; \ + (VL_step) = 1; \ + } else { \ + for(_VL_i = 0; _VL_i < (VL_size); _VL_i++){ \ + if(((signed char *)(VL_buf))[_VL_i] >= 0){ \ + (VL_num) += ((signed char *)(VL_buf))[_VL_i] * _VL_base; \ + break; \ + } \ + (VL_num) += _VL_base * (((signed char *)(VL_buf))[_VL_i] + 1) * -1; \ + _VL_base *= 128; \ + } \ + (VL_step) = _VL_i + 1; \ + } \ + } while(FALSE) + +enum { /* enumeration for flags */ + VL_FLISVILLA = 1 << 0, /* whether for Villa */ + VL_FLISZLIB = 1 << 1, /* whether with ZLIB */ + VL_FLISLZO = 1 << 2, /* whether with LZO */ + VL_FLISBZIP = 1 << 3 /* whether with BZIP2 */ +}; + + +/* private function prototypes */ +static int vllexcompare(const char *aptr, int asiz, const char *bptr, int bsiz); +static int vlintcompare(const char *aptr, int asiz, const char *bptr, int bsiz); +static int vlnumcompare(const char *aptr, int asiz, const char *bptr, int bsiz); +static int vldeccompare(const char *aptr, int asiz, const char *bptr, int bsiz); +static int vldpputnum(DEPOT *depot, int knum, int vnum); +static int vldpgetnum(DEPOT *depot, int knum, int *vnp); +static VLLEAF *vlleafnew(VILLA *villa, int prev, int next); +static int vlleafcacheout(VILLA *villa, int id); +static int vlleafsave(VILLA *villa, VLLEAF *leaf); +static VLLEAF *vlleafload(VILLA *villa, int id); +static VLLEAF *vlgethistleaf(VILLA *villa, const char *kbuf, int ksiz); +static int vlleafaddrec(VILLA *villa, VLLEAF *leaf, int dmode, + const char *kbuf, int ksiz, const char *vbuf, int vsiz); +static int vlleafdatasize(VLLEAF *leaf); +static VLLEAF *vlleafdivide(VILLA *villa, VLLEAF *leaf); +static VLNODE *vlnodenew(VILLA *villa, int heir); +static int vlnodecacheout(VILLA *villa, int id); +static int vlnodesave(VILLA *villa, VLNODE *node); +static VLNODE *vlnodeload(VILLA *villa, int id); +static void vlnodeaddidx(VILLA *villa, VLNODE *node, int order, + int pid, const char *kbuf, int ksiz); +static int vlsearchleaf(VILLA *villa, const char *kbuf, int ksiz); +static int vlcacheadjust(VILLA *villa); +static VLREC *vlrecsearch(VILLA *villa, VLLEAF *leaf, const char *kbuf, int ksiz, int *ip); + + + +/************************************************************************************************* + * public objects + *************************************************************************************************/ + + +/* Comparing functions. */ +VLCFUNC VL_CMPLEX = vllexcompare; +VLCFUNC VL_CMPINT = vlintcompare; +VLCFUNC VL_CMPNUM = vlnumcompare; +VLCFUNC VL_CMPDEC = vldeccompare; + + +/* Get a database handle. */ +VILLA *vlopen(const char *name, int omode, VLCFUNC cmp){ + DEPOT *depot; + int dpomode, flags, cmode, root, last, lnum, nnum, rnum; + VILLA *villa; + VLLEAF *leaf; + assert(name && cmp); + dpomode = DP_OREADER; + if(omode & VL_OWRITER){ + dpomode = DP_OWRITER; + if(omode & VL_OCREAT) dpomode |= DP_OCREAT; + if(omode & VL_OTRUNC) dpomode |= DP_OTRUNC; + } + if(omode & VL_ONOLCK) dpomode |= DP_ONOLCK; + if(omode & VL_OLCKNB) dpomode |= DP_OLCKNB; + if(!(depot = dpopen(name, dpomode, VL_INITBNUM))) return NULL; + flags = dpgetflags(depot); + cmode = 0; + root = -1; + last = -1; + lnum = 0; + nnum = 0; + rnum = 0; + if(dprnum(depot) > 0){ + if(!(flags & VL_FLISVILLA) || + !vldpgetnum(depot, VL_ROOTKEY, &root) || !vldpgetnum(depot, VL_LASTKEY, &last) || + !vldpgetnum(depot, VL_LNUMKEY, &lnum) || !vldpgetnum(depot, VL_NNUMKEY, &nnum) || + !vldpgetnum(depot, VL_RNUMKEY, &rnum) || root < VL_LEAFIDMIN || last < VL_LEAFIDMIN || + lnum < 0 || nnum < 0 || rnum < 0){ + dpclose(depot); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + if(flags & VL_FLISZLIB){ + cmode = VL_OZCOMP; + } else if(flags & VL_FLISLZO){ + cmode = VL_OYCOMP; + } else if(flags & VL_FLISBZIP){ + cmode = VL_OXCOMP; + } + } else if(omode & VL_OWRITER){ + if(omode & VL_OZCOMP){ + cmode = VL_OZCOMP; + } else if(omode & VL_OYCOMP){ + cmode = VL_OYCOMP; + } else if(omode & VL_OXCOMP){ + cmode = VL_OXCOMP; + } + } + if(omode & VL_OWRITER){ + flags |= VL_FLISVILLA; + if(_qdbm_deflate && cmode == VL_OZCOMP){ + flags |= VL_FLISZLIB; + } else if(_qdbm_lzoencode && cmode == VL_OYCOMP){ + flags |= VL_FLISLZO; + } else if(_qdbm_bzencode && cmode == VL_OXCOMP){ + flags |= VL_FLISBZIP; + } + if(!dpsetflags(depot, flags) || !dpsetalign(depot, VL_PAGEALIGN) || + !dpsetfbpsiz(depot, VL_FBPOOLSIZ)){ + dpclose(depot); + return NULL; + } + } + CB_MALLOC(villa, sizeof(VILLA)); + villa->depot = depot; + villa->cmp = cmp; + villa->wmode = (omode & VL_OWRITER); + villa->cmode = cmode; + villa->root = root; + villa->last = last; + villa->lnum = lnum; + villa->nnum = nnum; + villa->rnum = rnum; + villa->leafc = cbmapopen(); + villa->nodec = cbmapopen(); + villa->hnum = 0; + villa->hleaf = -1; + villa->lleaf = -1; + villa->curleaf = -1; + villa->curknum = -1; + villa->curvnum = -1; + villa->leafrecmax = VL_DEFLRECMAX; + villa->nodeidxmax = VL_DEFNIDXMAX; + villa->leafcnum = VL_DEFLCNUM; + villa->nodecnum = VL_DEFNCNUM; + villa->tran = FALSE; + villa->rbroot = -1; + villa->rblast = -1; + villa->rblnum = -1; + villa->rbnnum = -1; + villa->rbrnum = -1; + if(root == -1){ + leaf = vlleafnew(villa, -1, -1); + villa->root = leaf->id; + villa->last = leaf->id; + if(!vltranbegin(villa) || !vltranabort(villa)){ + vlclose(villa); + return NULL; + } + } + return villa; +} + + +/* Close a database handle. */ +int vlclose(VILLA *villa){ + int err, pid; + const char *tmp; + assert(villa); + err = FALSE; + if(villa->tran){ + if(!vltranabort(villa)) err = TRUE; + } + cbmapiterinit(villa->leafc); + while((tmp = cbmapiternext(villa->leafc, NULL)) != NULL){ + pid = *(int *)tmp; + if(!vlleafcacheout(villa, pid)) err = TRUE; + } + cbmapiterinit(villa->nodec); + while((tmp = cbmapiternext(villa->nodec, NULL)) != NULL){ + pid = *(int *)tmp; + if(!vlnodecacheout(villa, pid)) err = TRUE; + } + if(villa->wmode){ + if(!dpsetalign(villa->depot, 0)) err = TRUE; + if(!vldpputnum(villa->depot, VL_ROOTKEY, villa->root)) err = TRUE; + if(!vldpputnum(villa->depot, VL_LASTKEY, villa->last)) err = TRUE; + if(!vldpputnum(villa->depot, VL_LNUMKEY, villa->lnum)) err = TRUE; + if(!vldpputnum(villa->depot, VL_NNUMKEY, villa->nnum)) err = TRUE; + if(!vldpputnum(villa->depot, VL_RNUMKEY, villa->rnum)) err = TRUE; + } + cbmapclose(villa->leafc); + cbmapclose(villa->nodec); + if(!dpclose(villa->depot)) err = TRUE; + free(villa); + return err ? FALSE : TRUE; +} + + +/* Store a record. */ +int vlput(VILLA *villa, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode){ + VLLEAF *leaf, *newleaf; + VLNODE *node, *newnode; + VLIDX *idxp; + CBDATUM *key; + int i, pid, todiv, heir, parent, mid; + assert(villa && kbuf && vbuf); + villa->curleaf = -1; + villa->curknum = -1; + villa->curvnum = -1; + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(ksiz < 0) ksiz = strlen(kbuf); + if(vsiz < 0) vsiz = strlen(vbuf); + if(villa->hleaf < VL_LEAFIDMIN || !(leaf = vlgethistleaf(villa, kbuf, ksiz))){ + if((pid = vlsearchleaf(villa, kbuf, ksiz)) == -1) return FALSE; + if(!(leaf = vlleafload(villa, pid))) return FALSE; + } + if(!vlleafaddrec(villa, leaf, dmode, kbuf, ksiz, vbuf, vsiz)){ + dpecodeset(DP_EKEEP, __FILE__, __LINE__); + return FALSE; + } + todiv = FALSE; + switch(CB_LISTNUM(leaf->recs) % 4){ + case 0: + if(CB_LISTNUM(leaf->recs) >= 4 && + vlleafdatasize(leaf) > VL_MAXLEAFSIZ * (villa->cmode > 0 ? 2 : 1)){ + todiv = TRUE; + break; + } + case 2: + if(CB_LISTNUM(leaf->recs) > villa->leafrecmax) todiv = TRUE; + break; + } + if(todiv){ + if(!(newleaf = vlleafdivide(villa, leaf))) return FALSE; + if(leaf->id == villa->last) villa->last = newleaf->id; + heir = leaf->id; + pid = newleaf->id; + key = ((VLREC *)CB_LISTVAL(newleaf->recs, 0))->key; + key = cbdatumdup(key); + while(TRUE){ + if(villa->hnum < 1){ + node = vlnodenew(villa, heir); + vlnodeaddidx(villa, node, TRUE, pid, CB_DATUMPTR(key), CB_DATUMSIZE(key)); + villa->root = node->id; + CB_DATUMCLOSE(key); + break; + } + parent = villa->hist[--villa->hnum]; + if(!(node = vlnodeload(villa, parent))){ + CB_DATUMCLOSE(key); + return FALSE; + } + vlnodeaddidx(villa, node, FALSE, pid, CB_DATUMPTR(key), CB_DATUMSIZE(key)); + CB_DATUMCLOSE(key); + if(CB_LISTNUM(node->idxs) <= villa->nodeidxmax) break; + mid = CB_LISTNUM(node->idxs) / 2; + idxp = (VLIDX *)CB_LISTVAL(node->idxs, mid); + newnode = vlnodenew(villa, idxp->pid); + heir = node->id; + pid = newnode->id; + CB_DATUMOPEN2(key, CB_DATUMPTR(idxp->key), CB_DATUMSIZE(idxp->key)); + for(i = mid + 1; i < CB_LISTNUM(node->idxs); i++){ + idxp = (VLIDX *)CB_LISTVAL(node->idxs, i); + vlnodeaddidx(villa, newnode, TRUE, idxp->pid, + CB_DATUMPTR(idxp->key), CB_DATUMSIZE(idxp->key)); + } + for(i = 0; i < CB_LISTNUM(newnode->idxs); i++){ + idxp = (VLIDX *)cblistpop(node->idxs, NULL); + CB_DATUMCLOSE(idxp->key); + free(idxp); + } + node->dirty = TRUE; + } + } + if(!villa->tran && !vlcacheadjust(villa)) return FALSE; + return TRUE; +} + + +/* Delete a record. */ +int vlout(VILLA *villa, const char *kbuf, int ksiz){ + VLLEAF *leaf; + VLREC *recp; + int pid, ri, vsiz; + char *vbuf; + assert(villa && kbuf); + villa->curleaf = -1; + villa->curknum = -1; + villa->curvnum = -1; + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(ksiz < 0) ksiz = strlen(kbuf); + if(villa->hleaf < VL_LEAFIDMIN || !(leaf = vlgethistleaf(villa, kbuf, ksiz))){ + if((pid = vlsearchleaf(villa, kbuf, ksiz)) == -1) return FALSE; + if(!(leaf = vlleafload(villa, pid))) return FALSE; + } + if(!(recp = vlrecsearch(villa, leaf, kbuf, ksiz, &ri))){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(recp->rest){ + CB_DATUMCLOSE(recp->first); + vbuf = cblistshift(recp->rest, &vsiz); + CB_DATUMOPEN2(recp->first, vbuf, vsiz); + free(vbuf); + if(CB_LISTNUM(recp->rest) < 1){ + CB_LISTCLOSE(recp->rest); + recp->rest = NULL; + } + } else { + CB_DATUMCLOSE(recp->key); + CB_DATUMCLOSE(recp->first); + free(cblistremove(leaf->recs, ri, NULL)); + } + leaf->dirty = TRUE; + villa->rnum--; + if(!villa->tran && !vlcacheadjust(villa)) return FALSE; + return TRUE; +} + + +/* Retrieve a record. */ +char *vlget(VILLA *villa, const char *kbuf, int ksiz, int *sp){ + VLLEAF *leaf; + VLREC *recp; + char *rv; + int pid; + assert(villa && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if(villa->hleaf < VL_LEAFIDMIN || !(leaf = vlgethistleaf(villa, kbuf, ksiz))){ + if((pid = vlsearchleaf(villa, kbuf, ksiz)) == -1) return NULL; + if(!(leaf = vlleafload(villa, pid))) return NULL; + } + if(!(recp = vlrecsearch(villa, leaf, kbuf, ksiz, NULL))){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return NULL; + } + if(!villa->tran && !vlcacheadjust(villa)) return NULL; + if(sp) *sp = CB_DATUMSIZE(recp->first); + CB_MEMDUP(rv, CB_DATUMPTR(recp->first), CB_DATUMSIZE(recp->first)); + return rv; +} + + +/* Get the size of the value of a record. */ +int vlvsiz(VILLA *villa, const char *kbuf, int ksiz){ + VLLEAF *leaf; + VLREC *recp; + int pid; + assert(villa && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if(villa->hleaf < VL_LEAFIDMIN || !(leaf = vlgethistleaf(villa, kbuf, ksiz))){ + if((pid = vlsearchleaf(villa, kbuf, ksiz)) == -1) return -1; + if(!(leaf = vlleafload(villa, pid))) return -1; + } + if(!(recp = vlrecsearch(villa, leaf, kbuf, ksiz, NULL))){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return -1; + } + if(!villa->tran && !vlcacheadjust(villa)) return -1; + return CB_DATUMSIZE(recp->first); +} + + +/* Get the number of records corresponding a key. */ +int vlvnum(VILLA *villa, const char *kbuf, int ksiz){ + VLLEAF *leaf; + VLREC *recp; + int pid; + assert(villa && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if(villa->hleaf < VL_LEAFIDMIN || !(leaf = vlgethistleaf(villa, kbuf, ksiz))){ + if((pid = vlsearchleaf(villa, kbuf, ksiz)) == -1) return 0; + if(!(leaf = vlleafload(villa, pid))) return 0; + } + if(!(recp = vlrecsearch(villa, leaf, kbuf, ksiz, NULL))){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return 0; + } + if(!villa->tran && !vlcacheadjust(villa)) return 0; + return 1 + (recp->rest ? CB_LISTNUM(recp->rest) : 0); +} + + +/* Store plural records corresponding a key. */ +int vlputlist(VILLA *villa, const char *kbuf, int ksiz, const CBLIST *vals){ + int i, vsiz; + const char *vbuf; + assert(villa && kbuf && vals); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(CB_LISTNUM(vals) < 1){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + if(ksiz < 0) ksiz = strlen(kbuf); + for(i = 0; i < CB_LISTNUM(vals); i++){ + vbuf = CB_LISTVAL2(vals, i, vsiz); + if(!vlput(villa, kbuf, ksiz, vbuf, vsiz, VL_DDUP)) return FALSE; + } + return TRUE; +} + + +/* Delete all records corresponding a key. */ +int vloutlist(VILLA *villa, const char *kbuf, int ksiz){ + int i, vnum; + assert(villa && kbuf); + if(!villa->wmode){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + if(ksiz < 0) ksiz = strlen(kbuf); + if((vnum = vlvnum(villa, kbuf, ksiz)) < 1) return FALSE; + for(i = 0; i < vnum; i++){ + if(!vlout(villa, kbuf, ksiz)) return FALSE; + } + return TRUE; +} + + +/* Retrieve values of all records corresponding a key. */ +CBLIST *vlgetlist(VILLA *villa, const char *kbuf, int ksiz){ + VLLEAF *leaf; + VLREC *recp; + int pid, i, vsiz; + CBLIST *vals; + const char *vbuf; + assert(villa && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if(villa->hleaf < VL_LEAFIDMIN || !(leaf = vlgethistleaf(villa, kbuf, ksiz))){ + if((pid = vlsearchleaf(villa, kbuf, ksiz)) == -1) return NULL; + if(!(leaf = vlleafload(villa, pid))) return NULL; + } + if(!(recp = vlrecsearch(villa, leaf, kbuf, ksiz, NULL))){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return NULL; + } + CB_LISTOPEN(vals); + CB_LISTPUSH(vals, CB_DATUMPTR(recp->first), CB_DATUMSIZE(recp->first)); + if(recp->rest){ + for(i = 0; i < CB_LISTNUM(recp->rest); i++){ + vbuf = CB_LISTVAL2(recp->rest, i, vsiz); + CB_LISTPUSH(vals, vbuf, vsiz); + } + } + if(!villa->tran && !vlcacheadjust(villa)){ + CB_LISTCLOSE(vals); + return NULL; + } + return vals; +} + + +/* Retrieve concatenated values of all records corresponding a key. */ +char *vlgetcat(VILLA *villa, const char *kbuf, int ksiz, int *sp){ + VLLEAF *leaf; + VLREC *recp; + int pid, i, vsiz, rsiz; + char *rbuf; + const char *vbuf; + assert(villa && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if(villa->hleaf < VL_LEAFIDMIN || !(leaf = vlgethistleaf(villa, kbuf, ksiz))){ + if((pid = vlsearchleaf(villa, kbuf, ksiz)) == -1) return NULL; + if(!(leaf = vlleafload(villa, pid))) return NULL; + } + if(!(recp = vlrecsearch(villa, leaf, kbuf, ksiz, NULL))){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return NULL; + } + rsiz = CB_DATUMSIZE(recp->first); + CB_MALLOC(rbuf, rsiz + 1); + memcpy(rbuf, CB_DATUMPTR(recp->first), rsiz); + if(recp->rest){ + for(i = 0; i < CB_LISTNUM(recp->rest); i++){ + vbuf = CB_LISTVAL2(recp->rest, i, vsiz); + CB_REALLOC(rbuf, rsiz + vsiz + 1); + memcpy(rbuf + rsiz, vbuf, vsiz); + rsiz += vsiz; + } + } + rbuf[rsiz] = '\0'; + if(!villa->tran && !vlcacheadjust(villa)){ + free(rbuf); + return NULL; + } + if(sp) *sp = rsiz; + return rbuf; +} + + +/* Move the cursor to the first record. */ +int vlcurfirst(VILLA *villa){ + VLLEAF *leaf; + assert(villa); + villa->curleaf = VL_LEAFIDMIN; + villa->curknum = 0; + villa->curvnum = 0; + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + while(CB_LISTNUM(leaf->recs) < 1){ + villa->curleaf = leaf->next; + villa->curknum = 0; + villa->curvnum = 0; + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + } + return TRUE; +} + + +/* Move the cursor to the last record. */ +int vlcurlast(VILLA *villa){ + VLLEAF *leaf; + VLREC *recp; + assert(villa); + villa->curleaf = villa->last; + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + while(CB_LISTNUM(leaf->recs) < 1){ + villa->curleaf = leaf->prev; + if(villa->curleaf == -1){ + villa->curleaf = -1; + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + } + villa->curknum = CB_LISTNUM(leaf->recs) - 1; + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + villa->curvnum = recp->rest ? CB_LISTNUM(recp->rest) : 0; + return TRUE; +} + + +/* Move the cursor to the previous record. */ +int vlcurprev(VILLA *villa){ + VLLEAF *leaf; + VLREC *recp; + assert(villa); + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf)) || CB_LISTNUM(leaf->recs) < 1){ + villa->curleaf = -1; + return FALSE; + } + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + villa->curvnum--; + if(villa->curvnum < 0){ + villa->curknum--; + if(villa->curknum < 0){ + villa->curleaf = leaf->prev; + if(villa->curleaf == -1){ + villa->curleaf = -1; + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + while(CB_LISTNUM(leaf->recs) < 1){ + villa->curleaf = leaf->prev; + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + } + villa->curknum = CB_LISTNUM(leaf->recs) - 1; + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + villa->curvnum = recp->rest ? CB_LISTNUM(recp->rest) : 0; + } + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + villa->curvnum = recp->rest ? CB_LISTNUM(recp->rest) : 0; + } + if(!villa->tran && !vlcacheadjust(villa)) return FALSE; + return TRUE; +} + + +/* Move the cursor to the next record. */ +int vlcurnext(VILLA *villa){ + VLLEAF *leaf; + VLREC *recp; + assert(villa); + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf)) || CB_LISTNUM(leaf->recs) < 1){ + villa->curleaf = -1; + return FALSE; + } + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + villa->curvnum++; + if(villa->curvnum > (recp->rest ? CB_LISTNUM(recp->rest) : 0)){ + villa->curknum++; + villa->curvnum = 0; + } + if(villa->curknum >= CB_LISTNUM(leaf->recs)){ + villa->curleaf = leaf->next; + villa->curknum = 0; + villa->curvnum = 0; + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + while(CB_LISTNUM(leaf->recs) < 1){ + villa->curleaf = leaf->next; + villa->curknum = 0; + villa->curvnum = 0; + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + } + } + if(!villa->tran && !vlcacheadjust(villa)) return FALSE; + return TRUE; +} + + +/* Move the cursor to a position around a record. */ +int vlcurjump(VILLA *villa, const char *kbuf, int ksiz, int jmode){ + VLLEAF *leaf; + VLREC *recp; + int pid, index; + assert(villa && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if((pid = vlsearchleaf(villa, kbuf, ksiz)) == -1){ + villa->curleaf = -1; + return FALSE; + } + if(!(leaf = vlleafload(villa, pid))){ + villa->curleaf = -1; + return FALSE; + } + while(CB_LISTNUM(leaf->recs) < 1){ + villa->curleaf = (jmode == VL_JFORWARD) ? leaf->next : leaf->prev; + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + } + if(!(recp = vlrecsearch(villa, leaf, kbuf, ksiz, &index))){ + if(jmode == VL_JFORWARD){ + villa->curleaf = leaf->id; + if(index >= CB_LISTNUM(leaf->recs)) index--; + villa->curknum = index; + villa->curvnum = 0; + recp = (VLREC *)CB_LISTVAL(leaf->recs, index); + if(villa->cmp(kbuf, ksiz, CB_DATUMPTR(recp->key), CB_DATUMSIZE(recp->key)) < 0) return TRUE; + villa->curvnum = (recp->rest ? CB_LISTNUM(recp->rest) : 0); + return vlcurnext(villa); + } else { + villa->curleaf = leaf->id; + if(index >= CB_LISTNUM(leaf->recs)) index--; + villa->curknum = index; + recp = (VLREC *)CB_LISTVAL(leaf->recs, index); + villa->curvnum = (recp->rest ? CB_LISTNUM(recp->rest) : 0); + if(villa->cmp(kbuf, ksiz, CB_DATUMPTR(recp->key), CB_DATUMSIZE(recp->key)) > 0) return TRUE; + villa->curvnum = 0; + return vlcurprev(villa); + } + } + if(jmode == VL_JFORWARD){ + villa->curleaf = pid; + villa->curknum = index; + villa->curvnum = 0; + } else { + villa->curleaf = pid; + villa->curknum = index; + villa->curvnum = (recp->rest ? CB_LISTNUM(recp->rest) : 0); + } + return TRUE; +} + + +/* Get the key of the record where the cursor is. */ +char *vlcurkey(VILLA *villa, int *sp){ + VLLEAF *leaf; + VLREC *recp; + const char *kbuf; + char *rv; + int ksiz; + assert(villa); + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + kbuf = CB_DATUMPTR(recp->key); + ksiz = CB_DATUMSIZE(recp->key); + if(sp) *sp = ksiz; + CB_MEMDUP(rv, kbuf, ksiz); + return rv; +} + + +/* Get the value of the record where the cursor is. */ +char *vlcurval(VILLA *villa, int *sp){ + VLLEAF *leaf; + VLREC *recp; + const char *vbuf; + char *rv; + int vsiz; + assert(villa); + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + if(villa->curvnum < 1){ + vbuf = CB_DATUMPTR(recp->first); + vsiz = CB_DATUMSIZE(recp->first); + } else { + vbuf = CB_LISTVAL2(recp->rest, villa->curvnum - 1, vsiz); + } + if(sp) *sp = vsiz; + CB_MEMDUP(rv, vbuf, vsiz); + return rv; +} + + +/* Insert a record around the cursor. */ +int vlcurput(VILLA *villa, const char *vbuf, int vsiz, int cpmode){ + VLLEAF *leaf; + VLREC *recp; + char *tbuf; + int tsiz; + assert(villa && vbuf); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(vsiz < 0) vsiz = strlen(vbuf); + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + switch(cpmode){ + case VL_CPBEFORE: + if(villa->curvnum < 1){ + if(!recp->rest){ + CB_DATUMTOMALLOC(recp->first, tbuf, tsiz); + CB_DATUMOPEN2(recp->first, vbuf, vsiz); + CB_LISTOPEN(recp->rest); + CB_LISTPUSHBUF(recp->rest, tbuf, tsiz); + } else { + cblistunshift(recp->rest, CB_DATUMPTR(recp->first), CB_DATUMSIZE(recp->first)); + CB_DATUMSETSIZE(recp->first, 0); + CB_DATUMCAT(recp->first, vbuf, vsiz); + } + } else { + CB_LISTINSERT(recp->rest, villa->curvnum - 1, vbuf, vsiz); + } + villa->rnum++; + break; + case VL_CPAFTER: + if(!recp->rest) CB_LISTOPEN(recp->rest); + CB_LISTINSERT(recp->rest, villa->curvnum, vbuf, vsiz); + villa->curvnum++; + villa->rnum++; + break; + default: + if(villa->curvnum < 1){ + CB_DATUMSETSIZE(recp->first, 0); + CB_DATUMCAT(recp->first, vbuf, vsiz); + } else { + cblistover(recp->rest, villa->curvnum - 1, vbuf, vsiz); + } + break; + } + leaf->dirty = TRUE; + return TRUE; +} + + +/* Delete the record where the cursor is. */ +int vlcurout(VILLA *villa){ + VLLEAF *leaf; + VLREC *recp; + char *vbuf; + int vsiz; + assert(villa); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + if(villa->curvnum < 1){ + if(recp->rest){ + vbuf = cblistshift(recp->rest, &vsiz); + CB_DATUMSETSIZE(recp->first, 0); + CB_DATUMCAT(recp->first, vbuf, vsiz); + free(vbuf); + if(CB_LISTNUM(recp->rest) < 1){ + CB_LISTCLOSE(recp->rest); + recp->rest = NULL; + } + } else { + CB_DATUMCLOSE(recp->first); + CB_DATUMCLOSE(recp->key); + free(cblistremove(leaf->recs, villa->curknum, NULL)); + } + } else { + free(cblistremove(recp->rest, villa->curvnum - 1, NULL)); + if(villa->curvnum - 1 >= CB_LISTNUM(recp->rest)){ + villa->curknum++; + villa->curvnum = 0; + } + if(CB_LISTNUM(recp->rest) < 1){ + CB_LISTCLOSE(recp->rest); + recp->rest = NULL; + } + } + villa->rnum--; + leaf->dirty = TRUE; + if(villa->curknum >= CB_LISTNUM(leaf->recs)){ + villa->curleaf = leaf->next; + villa->curknum = 0; + villa->curvnum = 0; + while(villa->curleaf != -1 && (leaf = vlleafload(villa, villa->curleaf)) != NULL && + CB_LISTNUM(leaf->recs) < 1){ + villa->curleaf = leaf->next; + } + } + return TRUE; +} + + +/* Set the tuning parameters for performance. */ +void vlsettuning(VILLA *villa, int lrecmax, int nidxmax, int lcnum, int ncnum){ + assert(villa); + if(lrecmax < 1) lrecmax = VL_DEFLRECMAX; + if(lrecmax < 3) lrecmax = 3; + if(nidxmax < 1) nidxmax = VL_DEFNIDXMAX; + if(nidxmax < 4) nidxmax = 4; + if(lcnum < 1) lcnum = VL_DEFLCNUM; + if(lcnum < VL_CACHEOUT * 2) lcnum = VL_CACHEOUT * 2; + if(ncnum < 1) ncnum = VL_DEFNCNUM; + if(ncnum < VL_CACHEOUT * 2) ncnum = VL_CACHEOUT * 2; + villa->leafrecmax = lrecmax; + villa->nodeidxmax = nidxmax; + villa->leafcnum = lcnum; + villa->nodecnum = ncnum; +} + + +/* Set the size of the free block pool of a database handle. */ +int vlsetfbpsiz(VILLA *villa, int size){ + assert(villa && size >= 0); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + return dpsetfbpsiz(villa->depot, size); +} + + +/* Synchronize updating contents with the file and the device. */ +int vlsync(VILLA *villa){ + int err; + err = FALSE; + if(!vlmemsync(villa)) err = TRUE; + if(!dpsync(villa->depot)) err = TRUE; + return err ? FALSE : TRUE; +} + + +/* Optimize a database. */ +int vloptimize(VILLA *villa){ + int err; + assert(villa); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(villa->tran){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + if(!vlsync(villa)) return FALSE; + if(!dpoptimize(villa->depot, -1)) err = TRUE; + return err ? FALSE : TRUE; +} + + +/* Get the name of a database. */ +char *vlname(VILLA *villa){ + assert(villa); + return dpname(villa->depot); +} + + +/* Get the size of a database file. */ +int vlfsiz(VILLA *villa){ + return dpfsiz(villa->depot); +} + + +/* Get the number of the leaf nodes of B+ tree. */ +int vllnum(VILLA *villa){ + assert(villa); + return villa->lnum; +} + + +/* Get the number of the non-leaf nodes of B+ tree. */ +int vlnnum(VILLA *villa){ + assert(villa); + return villa->nnum; +} + + +/* Get the number of the records stored in a database. */ +int vlrnum(VILLA *villa){ + assert(villa); + return villa->rnum; +} + + +/* Check whether a database handle is a writer or not. */ +int vlwritable(VILLA *villa){ + assert(villa); + return villa->wmode; +} + + +/* Check whether a database has a fatal error or not. */ +int vlfatalerror(VILLA *villa){ + assert(villa); + return dpfatalerror(villa->depot); +} + + +/* Get the inode number of a database file. */ +int vlinode(VILLA *villa){ + assert(villa); + return dpinode(villa->depot); +} + + +/* Get the last modified time of a database. */ +time_t vlmtime(VILLA *villa){ + assert(villa); + return dpmtime(villa->depot); +} + + +/* Begin the transaction. */ +int vltranbegin(VILLA *villa){ + int err, pid; + const char *tmp; + VLLEAF *leaf; + VLNODE *node; + assert(villa); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(villa->tran){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + cbmapiterinit(villa->leafc); + while((tmp = cbmapiternext(villa->leafc, NULL)) != NULL){ + pid = *(int *)tmp; + leaf = (VLLEAF *)cbmapget(villa->leafc, (char *)&pid, sizeof(int), NULL); + if(leaf->dirty && !vlleafsave(villa, leaf)) err = TRUE; + } + cbmapiterinit(villa->nodec); + while((tmp = cbmapiternext(villa->nodec, NULL)) != NULL){ + pid = *(int *)tmp; + node = (VLNODE *)cbmapget(villa->nodec, (char *)&pid, sizeof(int), NULL); + if(node->dirty && !vlnodesave(villa, node)) err = TRUE; + } + if(!dpsetalign(villa->depot, 0)) err = TRUE; + if(!vldpputnum(villa->depot, VL_ROOTKEY, villa->root)) err = TRUE; + if(!vldpputnum(villa->depot, VL_LASTKEY, villa->last)) err = TRUE; + if(!vldpputnum(villa->depot, VL_LNUMKEY, villa->lnum)) err = TRUE; + if(!vldpputnum(villa->depot, VL_NNUMKEY, villa->nnum)) err = TRUE; + if(!vldpputnum(villa->depot, VL_RNUMKEY, villa->rnum)) err = TRUE; + if(!dpmemsync(villa->depot)) err = TRUE; + if(!dpsetalign(villa->depot, VL_PAGEALIGN)) err = TRUE; + villa->tran = TRUE; + villa->rbroot = villa->root; + villa->rblast = villa->last; + villa->rblnum = villa->lnum; + villa->rbnnum = villa->nnum; + villa->rbrnum = villa->rnum; + return err ? FALSE : TRUE; +} + + +/* Commit the transaction. */ +int vltrancommit(VILLA *villa){ + int err, pid; + const char *tmp; + VLLEAF *leaf; + VLNODE *node; + assert(villa); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(!villa->tran){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + cbmapiterinit(villa->leafc); + while((tmp = cbmapiternext(villa->leafc, NULL)) != NULL){ + pid = *(int *)tmp; + leaf = (VLLEAF *)cbmapget(villa->leafc, (char *)&pid, sizeof(int), NULL); + if(leaf->dirty && !vlleafsave(villa, leaf)) err = TRUE; + } + cbmapiterinit(villa->nodec); + while((tmp = cbmapiternext(villa->nodec, NULL)) != NULL){ + pid = *(int *)tmp; + node = (VLNODE *)cbmapget(villa->nodec, (char *)&pid, sizeof(int), NULL); + if(node->dirty && !vlnodesave(villa, node)) err = TRUE; + } + if(!dpsetalign(villa->depot, 0)) err = TRUE; + if(!vldpputnum(villa->depot, VL_ROOTKEY, villa->root)) err = TRUE; + if(!vldpputnum(villa->depot, VL_LASTKEY, villa->last)) err = TRUE; + if(!vldpputnum(villa->depot, VL_LNUMKEY, villa->lnum)) err = TRUE; + if(!vldpputnum(villa->depot, VL_NNUMKEY, villa->nnum)) err = TRUE; + if(!vldpputnum(villa->depot, VL_RNUMKEY, villa->rnum)) err = TRUE; + if(!dpmemsync(villa->depot)) err = TRUE; + if(!dpsetalign(villa->depot, VL_PAGEALIGN)) err = TRUE; + villa->tran = FALSE; + villa->rbroot = -1; + villa->rblast = -1; + villa->rblnum = -1; + villa->rbnnum = -1; + villa->rbrnum = -1; + while(cbmaprnum(villa->leafc) > villa->leafcnum || cbmaprnum(villa->nodec) > villa->nodecnum){ + if(!vlcacheadjust(villa)){ + err = TRUE; + break; + } + } + return err ? FALSE : TRUE; +} + + +/* Abort the transaction. */ +int vltranabort(VILLA *villa){ + int err, pid; + const char *tmp; + VLLEAF *leaf; + VLNODE *node; + assert(villa); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(!villa->tran){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + cbmapiterinit(villa->leafc); + while((tmp = cbmapiternext(villa->leafc, NULL)) != NULL){ + pid = *(int *)tmp; + if(!(leaf = (VLLEAF *)cbmapget(villa->leafc, (char *)&pid, sizeof(int), NULL))){ + err = TRUE; + continue; + } + if(leaf->dirty){ + leaf->dirty = FALSE; + if(!vlleafcacheout(villa, pid)) err = TRUE; + } + } + cbmapiterinit(villa->nodec); + while((tmp = cbmapiternext(villa->nodec, NULL)) != NULL){ + pid = *(int *)tmp; + if(!(node = (VLNODE *)cbmapget(villa->nodec, (char *)&pid, sizeof(int), NULL))){ + err = TRUE; + continue; + } + if(node->dirty){ + node->dirty = FALSE; + if(!vlnodecacheout(villa, pid)) err = TRUE; + } + } + villa->tran = FALSE; + villa->root = villa->rbroot; + villa->last = villa->rblast; + villa->lnum = villa->rblnum; + villa->nnum = villa->rbnnum; + villa->rnum = villa->rbrnum; + while(cbmaprnum(villa->leafc) > villa->leafcnum || cbmaprnum(villa->nodec) > villa->nodecnum){ + if(!vlcacheadjust(villa)){ + err = TRUE; + break; + } + } + return err ? FALSE : TRUE; +} + + +/* Remove a database file. */ +int vlremove(const char *name){ + assert(name); + return dpremove(name); +} + + +/* Repair a broken database file. */ +int vlrepair(const char *name, VLCFUNC cmp){ + DEPOT *depot; + VILLA *tvilla; + char path[VL_PATHBUFSIZ], *kbuf, *vbuf, *zbuf, *rp, *tkbuf, *tvbuf; + int i, err, flags, omode, ksiz, vsiz, zsiz, size, step, tksiz, tvsiz, vnum; + assert(name && cmp); + err = FALSE; + if(!dprepair(name)) err = TRUE; + if(!(depot = dpopen(name, DP_OREADER, -1))) return FALSE; + flags = dpgetflags(depot); + if(!(flags & VL_FLISVILLA)){ + dpclose(depot); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return FALSE; + } + sprintf(path, "%s%s", name, VL_TMPFSUF); + omode = VL_OWRITER | VL_OCREAT | VL_OTRUNC; + if(flags & VL_FLISZLIB){ + omode |= VL_OZCOMP; + } else if(flags & VL_FLISLZO){ + omode |= VL_OXCOMP; + } else if(flags & VL_FLISBZIP){ + omode |= VL_OYCOMP; + } + if(!(tvilla = vlopen(path, omode, cmp))){ + dpclose(depot); + return FALSE; + } + if(!dpiterinit(depot)) err = TRUE; + while((kbuf = dpiternext(depot, &ksiz)) != NULL){ + if(ksiz == sizeof(int) && *(int *)kbuf < VL_NODEIDMIN && *(int *)kbuf > 0){ + if((vbuf = dpget(depot, (char *)kbuf, sizeof(int), 0, -1, &vsiz)) != NULL){ + if(_qdbm_inflate && (flags & VL_FLISZLIB) && + (zbuf = _qdbm_inflate(vbuf, vsiz, &zsiz, _QDBM_ZMRAW)) != NULL){ + free(vbuf); + vbuf = zbuf; + vsiz = zsiz; + } else if(_qdbm_lzodecode && (flags & VL_FLISLZO) && + (zbuf = _qdbm_lzodecode(vbuf, vsiz, &zsiz)) != NULL){ + free(vbuf); + vbuf = zbuf; + vsiz = zsiz; + } else if(_qdbm_bzdecode && (flags & VL_FLISBZIP) && + (zbuf = _qdbm_bzdecode(vbuf, vsiz, &zsiz)) != NULL){ + free(vbuf); + vbuf = zbuf; + vsiz = zsiz; + } + rp = vbuf; + size = vsiz; + if(size >= 1){ + VL_READVNUMBUF(rp, size, vnum, step); + rp += step; + size -= step; + } + if(size >= 1){ + VL_READVNUMBUF(rp, size, vnum, step); + rp += step; + size -= step; + } + while(size >= 1){ + VL_READVNUMBUF(rp, size, tksiz, step); + rp += step; + size -= step; + if(size < tksiz) break; + tkbuf = rp; + rp += tksiz; + size -= tksiz; + if(size < 1) break; + VL_READVNUMBUF(rp, size, vnum, step); + rp += step; + size -= step; + if(vnum < 1 || size < 1) break; + for(i = 0; i < vnum && size >= 1; i++){ + VL_READVNUMBUF(rp, size, tvsiz, step); + rp += step; + size -= step; + if(size < tvsiz) break; + tvbuf = rp; + rp += tvsiz; + size -= tvsiz; + if(!vlput(tvilla, tkbuf, tksiz, tvbuf, tvsiz, VL_DDUP)) err = TRUE; + } + } + free(vbuf); + } + } + free(kbuf); + } + if(!vlclose(tvilla)) err = TRUE; + if(!dpclose(depot)) err = TRUE; + if(!dpremove(name)) err = TRUE; + if(rename(path, name) == -1){ + if(!err) dpecodeset(DP_EMISC, __FILE__, __LINE__); + err = TRUE; + } + return err ? FALSE : TRUE; +} + + +/* Dump all records as endian independent data. */ +int vlexportdb(VILLA *villa, const char *name){ + DEPOT *depot; + char path[VL_PATHBUFSIZ], *kbuf, *vbuf, *nkey; + int i, err, ksiz, vsiz, ki; + assert(villa && name); + sprintf(path, "%s%s", name, VL_TMPFSUF); + if(!(depot = dpopen(path, DP_OWRITER | DP_OCREAT | DP_OTRUNC, -1))) return FALSE; + err = FALSE; + vlcurfirst(villa); + for(i = 0; !err && (kbuf = vlcurkey(villa, &ksiz)) != NULL; i++){ + if((vbuf = vlcurval(villa, &vsiz)) != NULL){ + CB_MALLOC(nkey, ksiz + VL_NUMBUFSIZ); + ki = sprintf(nkey, "%X\t", i); + memcpy(nkey + ki, kbuf, ksiz); + if(!dpput(depot, nkey, ki + ksiz, vbuf, vsiz, DP_DKEEP)) err = TRUE; + free(nkey); + free(vbuf); + } else { + err = TRUE; + } + free(kbuf); + vlcurnext(villa); + } + if(!dpexportdb(depot, name)) err = TRUE; + if(!dpclose(depot)) err = TRUE; + if(!dpremove(path)) err = TRUE; + return !err && !vlfatalerror(villa); +} + + +/* Load all records from endian independent data. */ +int vlimportdb(VILLA *villa, const char *name){ + DEPOT *depot; + char path[VL_PATHBUFSIZ], *kbuf, *vbuf, *rp; + int err, ksiz, vsiz; + assert(villa && name); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(vlrnum(villa) > 0){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + kbuf = dpname(villa->depot); + sprintf(path, "%s%s", kbuf, VL_TMPFSUF); + free(kbuf); + if(!(depot = dpopen(path, DP_OWRITER | DP_OCREAT | DP_OTRUNC, -1))) return FALSE; + err = FALSE; + if(!dpimportdb(depot, name)) err = TRUE; + dpiterinit(depot); + while(!err && (kbuf = dpiternext(depot, &ksiz)) != NULL){ + if((vbuf = dpget(depot, kbuf, ksiz, 0, -1, &vsiz)) != NULL){ + if((rp = strchr(kbuf, '\t')) != NULL){ + rp++; + if(!vlput(villa, rp, ksiz - (rp - kbuf), vbuf, vsiz, VL_DDUP)) err = TRUE; + } else { + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + err = TRUE; + } + free(vbuf); + } else { + err = TRUE; + } + free(kbuf); + } + if(!dpclose(depot)) err = TRUE; + if(!dpremove(path)) err = TRUE; + return !err && !vlfatalerror(villa); +} + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Number of division of the database for Vista. */ +int *vlcrdnumptr(void){ + static int defvlcrdnum = VL_CRDNUM; + void *ptr; + if(_qdbm_ptsafe){ + if(!(ptr = _qdbm_settsd(&defvlcrdnum, sizeof(int), &defvlcrdnum))){ + defvlcrdnum = DP_EMISC; + return &defvlcrdnum; + } + return (int *)ptr; + } + return &defvlcrdnum; +} + + +/* Synchronize updating contents on memory. */ +int vlmemsync(VILLA *villa){ + int err, pid; + const char *tmp; + assert(villa); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(villa->tran){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + cbmapiterinit(villa->leafc); + while((tmp = cbmapiternext(villa->leafc, NULL)) != NULL){ + pid = *(int *)tmp; + if(!vlleafcacheout(villa, pid)) err = TRUE; + } + cbmapiterinit(villa->nodec); + while((tmp = cbmapiternext(villa->nodec, NULL)) != NULL){ + pid = *(int *)tmp; + if(!vlnodecacheout(villa, pid)) err = TRUE; + } + if(!dpsetalign(villa->depot, 0)) err = TRUE; + if(!vldpputnum(villa->depot, VL_ROOTKEY, villa->root)) err = TRUE; + if(!vldpputnum(villa->depot, VL_LASTKEY, villa->last)) err = TRUE; + if(!vldpputnum(villa->depot, VL_LNUMKEY, villa->lnum)) err = TRUE; + if(!vldpputnum(villa->depot, VL_NNUMKEY, villa->nnum)) err = TRUE; + if(!vldpputnum(villa->depot, VL_RNUMKEY, villa->rnum)) err = TRUE; + if(!dpsetalign(villa->depot, VL_PAGEALIGN)) err = TRUE; + if(!dpmemsync(villa->depot)) err = TRUE; + return err ? FALSE : TRUE; +} + + +/* Synchronize updating contents on memory, not physically. */ +int vlmemflush(VILLA *villa){ + int err, pid; + const char *tmp; + assert(villa); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + if(villa->tran){ + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + err = FALSE; + cbmapiterinit(villa->leafc); + while((tmp = cbmapiternext(villa->leafc, NULL)) != NULL){ + pid = *(int *)tmp; + if(!vlleafcacheout(villa, pid)) err = TRUE; + } + cbmapiterinit(villa->nodec); + while((tmp = cbmapiternext(villa->nodec, NULL)) != NULL){ + pid = *(int *)tmp; + if(!vlnodecacheout(villa, pid)) err = TRUE; + } + if(!dpsetalign(villa->depot, 0)) err = TRUE; + if(!vldpputnum(villa->depot, VL_ROOTKEY, villa->root)) err = TRUE; + if(!vldpputnum(villa->depot, VL_LASTKEY, villa->last)) err = TRUE; + if(!vldpputnum(villa->depot, VL_LNUMKEY, villa->lnum)) err = TRUE; + if(!vldpputnum(villa->depot, VL_NNUMKEY, villa->nnum)) err = TRUE; + if(!vldpputnum(villa->depot, VL_RNUMKEY, villa->rnum)) err = TRUE; + if(!dpsetalign(villa->depot, VL_PAGEALIGN)) err = TRUE; + if(!dpmemflush(villa->depot)) err = TRUE; + return err ? FALSE : TRUE; +} + + +/* Refer to a volatile cache of a value of a record. */ +const char *vlgetcache(VILLA *villa, const char *kbuf, int ksiz, int *sp){ + VLLEAF *leaf; + VLREC *recp; + int pid; + assert(villa && kbuf); + if(ksiz < 0) ksiz = strlen(kbuf); + if(villa->hleaf < VL_LEAFIDMIN || !(leaf = vlgethistleaf(villa, kbuf, ksiz))){ + if((pid = vlsearchleaf(villa, kbuf, ksiz)) == -1) return NULL; + if(!(leaf = vlleafload(villa, pid))) return NULL; + } + if(!(recp = vlrecsearch(villa, leaf, kbuf, ksiz, NULL))){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return NULL; + } + if(!villa->tran && !vlcacheadjust(villa)) return NULL; + if(sp) *sp = CB_DATUMSIZE(recp->first); + return CB_DATUMPTR(recp->first); +} + + +/* Refer to volatile cache of the key of the record where the cursor is. */ +const char *vlcurkeycache(VILLA *villa, int *sp){ + VLLEAF *leaf; + VLREC *recp; + const char *kbuf; + int ksiz; + assert(villa); + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + kbuf = CB_DATUMPTR(recp->key); + ksiz = CB_DATUMSIZE(recp->key); + if(sp) *sp = ksiz; + return kbuf; +} + + +/* Refer to volatile cache of the value of the record where the cursor is. */ +const char *vlcurvalcache(VILLA *villa, int *sp){ + VLLEAF *leaf; + VLREC *recp; + const char *vbuf; + int vsiz; + assert(villa); + if(villa->curleaf == -1){ + dpecodeset(DP_ENOITEM, __FILE__, __LINE__); + return FALSE; + } + if(!(leaf = vlleafload(villa, villa->curleaf))){ + villa->curleaf = -1; + return FALSE; + } + recp = (VLREC *)CB_LISTVAL(leaf->recs, villa->curknum); + if(villa->curvnum < 1){ + vbuf = CB_DATUMPTR(recp->first); + vsiz = CB_DATUMSIZE(recp->first); + } else { + vbuf = CB_LISTVAL2(recp->rest, villa->curvnum - 1, vsiz); + } + if(sp) *sp = vsiz; + return vbuf; +} + + +/* Get a multiple cursor handle. */ +VLMULCUR *vlmulcuropen(VILLA *villa){ + VLMULCUR *mulcur; + assert(villa); + if(villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return NULL; + } + CB_MALLOC(mulcur, sizeof(VLMULCUR)); + mulcur->villa = villa; + mulcur->curleaf = -1; + mulcur->curknum = -1; + mulcur->curvnum = -1; + return mulcur; +} + + +/* Close a multiple cursor handle. */ +void vlmulcurclose(VLMULCUR *mulcur){ + assert(mulcur); + free(mulcur); +} + + +/* Move a multiple cursor to the first record. */ +int vlmulcurfirst(VLMULCUR *mulcur){ + VLMULCUR swap; + int rv; + assert(mulcur); + swap.curleaf = mulcur->villa->curleaf; + swap.curknum = mulcur->villa->curknum; + swap.curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = mulcur->curleaf; + mulcur->villa->curknum = mulcur->curknum; + mulcur->villa->curvnum = mulcur->curvnum; + rv = vlcurfirst(mulcur->villa); + mulcur->curleaf = mulcur->villa->curleaf; + mulcur->curknum = mulcur->villa->curknum; + mulcur->curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = swap.curleaf; + mulcur->villa->curknum = swap.curknum; + mulcur->villa->curvnum = swap.curvnum; + return rv; +} + + +/* Move a multiple cursor to the last record. */ +int vlmulcurlast(VLMULCUR *mulcur){ + VLMULCUR swap; + int rv; + assert(mulcur); + swap.curleaf = mulcur->villa->curleaf; + swap.curknum = mulcur->villa->curknum; + swap.curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = mulcur->curleaf; + mulcur->villa->curknum = mulcur->curknum; + mulcur->villa->curvnum = mulcur->curvnum; + rv = vlcurlast(mulcur->villa); + mulcur->curleaf = mulcur->villa->curleaf; + mulcur->curknum = mulcur->villa->curknum; + mulcur->curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = swap.curleaf; + mulcur->villa->curknum = swap.curknum; + mulcur->villa->curvnum = swap.curvnum; + return rv; +} + + +/* Move a multiple cursor to the previous record. */ +int vlmulcurprev(VLMULCUR *mulcur){ + VLMULCUR swap; + int rv; + assert(mulcur); + swap.curleaf = mulcur->villa->curleaf; + swap.curknum = mulcur->villa->curknum; + swap.curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = mulcur->curleaf; + mulcur->villa->curknum = mulcur->curknum; + mulcur->villa->curvnum = mulcur->curvnum; + rv = vlcurprev(mulcur->villa); + mulcur->curleaf = mulcur->villa->curleaf; + mulcur->curknum = mulcur->villa->curknum; + mulcur->curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = swap.curleaf; + mulcur->villa->curknum = swap.curknum; + mulcur->villa->curvnum = swap.curvnum; + return rv; +} + + +/* Move a multiple cursor to the next record. */ +int vlmulcurnext(VLMULCUR *mulcur){ + VLMULCUR swap; + int rv; + assert(mulcur); + swap.curleaf = mulcur->villa->curleaf; + swap.curknum = mulcur->villa->curknum; + swap.curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = mulcur->curleaf; + mulcur->villa->curknum = mulcur->curknum; + mulcur->villa->curvnum = mulcur->curvnum; + rv = vlcurnext(mulcur->villa); + mulcur->curleaf = mulcur->villa->curleaf; + mulcur->curknum = mulcur->villa->curknum; + mulcur->curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = swap.curleaf; + mulcur->villa->curknum = swap.curknum; + mulcur->villa->curvnum = swap.curvnum; + return rv; +} + + +/* Move a multiple cursor to a position around a record. */ +int vlmulcurjump(VLMULCUR *mulcur, const char *kbuf, int ksiz, int jmode){ + VLMULCUR swap; + int rv; + assert(mulcur); + swap.curleaf = mulcur->villa->curleaf; + swap.curknum = mulcur->villa->curknum; + swap.curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = mulcur->curleaf; + mulcur->villa->curknum = mulcur->curknum; + mulcur->villa->curvnum = mulcur->curvnum; + rv = vlcurjump(mulcur->villa, kbuf, ksiz, jmode); + mulcur->curleaf = mulcur->villa->curleaf; + mulcur->curknum = mulcur->villa->curknum; + mulcur->curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = swap.curleaf; + mulcur->villa->curknum = swap.curknum; + mulcur->villa->curvnum = swap.curvnum; + return rv; +} + + +/* Get the key of the record where a multiple cursor is. */ +char *vlmulcurkey(VLMULCUR *mulcur, int *sp){ + VLMULCUR swap; + char *rv; + assert(mulcur); + swap.curleaf = mulcur->villa->curleaf; + swap.curknum = mulcur->villa->curknum; + swap.curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = mulcur->curleaf; + mulcur->villa->curknum = mulcur->curknum; + mulcur->villa->curvnum = mulcur->curvnum; + rv = vlcurkey(mulcur->villa, sp); + mulcur->curleaf = mulcur->villa->curleaf; + mulcur->curknum = mulcur->villa->curknum; + mulcur->curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = swap.curleaf; + mulcur->villa->curknum = swap.curknum; + mulcur->villa->curvnum = swap.curvnum; + return rv; +} + + +/* Get the value of the record where a multiple cursor is. */ +char *vlmulcurval(VLMULCUR *mulcur, int *sp){ + VLMULCUR swap; + char *rv; + assert(mulcur); + swap.curleaf = mulcur->villa->curleaf; + swap.curknum = mulcur->villa->curknum; + swap.curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = mulcur->curleaf; + mulcur->villa->curknum = mulcur->curknum; + mulcur->villa->curvnum = mulcur->curvnum; + rv = vlcurval(mulcur->villa, sp); + mulcur->curleaf = mulcur->villa->curleaf; + mulcur->curknum = mulcur->villa->curknum; + mulcur->curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = swap.curleaf; + mulcur->villa->curknum = swap.curknum; + mulcur->villa->curvnum = swap.curvnum; + return rv; +} + + +/* Refer to volatile cache of the key of the record where a multiple cursor is. */ +const char *vlmulcurkeycache(VLMULCUR *mulcur, int *sp){ + VLMULCUR swap; + const char *rv; + assert(mulcur); + swap.curleaf = mulcur->villa->curleaf; + swap.curknum = mulcur->villa->curknum; + swap.curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = mulcur->curleaf; + mulcur->villa->curknum = mulcur->curknum; + mulcur->villa->curvnum = mulcur->curvnum; + rv = vlcurkeycache(mulcur->villa, sp); + mulcur->curleaf = mulcur->villa->curleaf; + mulcur->curknum = mulcur->villa->curknum; + mulcur->curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = swap.curleaf; + mulcur->villa->curknum = swap.curknum; + mulcur->villa->curvnum = swap.curvnum; + return rv; +} + + +/* Refer to volatile cache of the value of the record where a multiple cursor is. */ +const char *vlmulcurvalcache(VLMULCUR *mulcur, int *sp){ + VLMULCUR swap; + const char *rv; + assert(mulcur); + swap.curleaf = mulcur->villa->curleaf; + swap.curknum = mulcur->villa->curknum; + swap.curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = mulcur->curleaf; + mulcur->villa->curknum = mulcur->curknum; + mulcur->villa->curvnum = mulcur->curvnum; + rv = vlcurvalcache(mulcur->villa, sp); + mulcur->curleaf = mulcur->villa->curleaf; + mulcur->curknum = mulcur->villa->curknum; + mulcur->curvnum = mulcur->villa->curvnum; + mulcur->villa->curleaf = swap.curleaf; + mulcur->villa->curknum = swap.curknum; + mulcur->villa->curvnum = swap.curvnum; + return rv; +} + + + +/************************************************************************************************* + * private objects + *************************************************************************************************/ + + +/* Compare keys of two records by lexical order. + `aptr' specifies the pointer to the region of one key. + `asiz' specifies the size of the region of one key. + `bptr' specifies the pointer to the region of the other key. + `bsiz' specifies the size of the region of the other key. + The return value is positive if the former is big, negative if the latter is big, 0 if both + are equivalent. */ +static int vllexcompare(const char *aptr, int asiz, const char *bptr, int bsiz){ + int i, min; + assert(aptr && asiz >= 0 && bptr && bsiz >= 0); + min = asiz < bsiz ? asiz : bsiz; + for(i = 0; i < min; i++){ + if(((unsigned char *)aptr)[i] != ((unsigned char *)bptr)[i]) + return ((unsigned char *)aptr)[i] - ((unsigned char *)bptr)[i]; + } + if(asiz == bsiz) return 0; + return asiz - bsiz; +} + + +/* Compare keys of two records as native integers. + `aptr' specifies the pointer to the region of one key. + `asiz' specifies the size of the region of one key. + `bptr' specifies the pointer to the region of the other key. + `bsiz' specifies the size of the region of the other key. + The return value is positive if the former is big, negative if the latter is big, 0 if both + are equivalent. */ +static int vlintcompare(const char *aptr, int asiz, const char *bptr, int bsiz){ + int anum, bnum; + assert(aptr && asiz >= 0 && bptr && bsiz >= 0); + if(asiz != bsiz) return asiz - bsiz; + anum = (asiz == sizeof(int) ? *(int *)aptr : INT_MIN); + bnum = (bsiz == sizeof(int) ? *(int *)bptr : INT_MIN); + return anum - bnum; +} + + +/* Compare keys of two records as numbers of big endian. + `aptr' specifies the pointer to the region of one key. + `asiz' specifies the size of the region of one key. + `bptr' specifies the pointer to the region of the other key. + `bsiz' specifies the size of the region of the other key. + The return value is positive if the former is big, negative if the latter is big, 0 if both + are equivalent. */ +static int vlnumcompare(const char *aptr, int asiz, const char *bptr, int bsiz){ + int i; + assert(aptr && asiz >= 0 && bptr && bsiz >= 0); + if(asiz != bsiz) return asiz - bsiz; + for(i = 0; i < asiz; i++){ + if(aptr[i] != bptr[i]) return aptr[i] - bptr[i]; + } + return 0; +} + + +/* Compare keys of two records as numeric strings of octal, decimal or hexadecimal. + `aptr' specifies the pointer to the region of one key. + `asiz' specifies the size of the region of one key. + `bptr' specifies the pointer to the region of the other key. + `bsiz' specifies the size of the region of the other key. + The return value is positive if the former is big, negative if the latter is big, 0 if both + are equivalent. */ +static int vldeccompare(const char *aptr, int asiz, const char *bptr, int bsiz){ + assert(aptr && asiz >= 0 && bptr && bsiz >= 0); + return (int)(strtod(aptr, NULL) - strtod(bptr, NULL)); +} + + +/* Store a record composed of a pair of integers. + `depot' specifies an internal database handle. + `knum' specifies an integer of the key. + `vnum' specifies an integer of the value. + The return value is true if successful, else, it is false. */ +static int vldpputnum(DEPOT *depot, int knum, int vnum){ + assert(depot); + return dpput(depot, (char *)&knum, sizeof(int), (char *)&vnum, sizeof(int), DP_DOVER); +} + + +/* Retrieve a record composed of a pair of integers. + `depot' specifies an internal database handle. + `knum' specifies an integer of the key. + `vip' specifies the pointer to a variable to assign the result to. + The return value is true if successful, else, it is false. */ +static int vldpgetnum(DEPOT *depot, int knum, int *vnp){ + char *vbuf; + int vsiz; + assert(depot && vnp); + vbuf = dpget(depot, (char *)&knum, sizeof(int), 0, -1, &vsiz); + if(!vbuf || vsiz != sizeof(int)){ + free(vbuf); + return FALSE; + } + *vnp = *(int *)vbuf; + free(vbuf); + return TRUE; +} + + +/* Create a new leaf. + `villa' specifies a database handle. + `prev' specifies the ID number of the previous leaf. + `next' specifies the ID number of the previous leaf. + The return value is a handle of the leaf. */ +static VLLEAF *vlleafnew(VILLA *villa, int prev, int next){ + VLLEAF lent; + assert(villa); + lent.id = villa->lnum + VL_LEAFIDMIN; + lent.dirty = TRUE; + CB_LISTOPEN(lent.recs); + lent.prev = prev; + lent.next = next; + villa->lnum++; + cbmapput(villa->leafc, (char *)&(lent.id), sizeof(int), (char *)&lent, sizeof(VLLEAF), TRUE); + return (VLLEAF *)cbmapget(villa->leafc, (char *)&(lent.id), sizeof(int), NULL); +} + + +/* Remove a leaf from the cache. + `villa' specifies a database handle. + `id' specifies the ID number of the leaf. + The return value is true if successful, else, it is false. */ +static int vlleafcacheout(VILLA *villa, int id){ + VLLEAF *leaf; + VLREC *recp; + CBLIST *recs; + int i, err, ln; + assert(villa && id >= VL_LEAFIDMIN); + if(!(leaf = (VLLEAF *)cbmapget(villa->leafc, (char *)&id, sizeof(int), NULL))) return FALSE; + err = FALSE; + if(leaf->dirty && !vlleafsave(villa, leaf)) err = TRUE; + recs = leaf->recs; + ln = CB_LISTNUM(recs); + for(i = 0; i < ln; i++){ + recp = (VLREC *)CB_LISTVAL(recs, i); + CB_DATUMCLOSE(recp->key); + CB_DATUMCLOSE(recp->first); + if(recp->rest) CB_LISTCLOSE(recp->rest); + } + CB_LISTCLOSE(recs); + cbmapout(villa->leafc, (char *)&id, sizeof(int)); + return err ? FALSE : TRUE; +} + + +/* Save a leaf into the database. + `villa' specifies a database handle. + `leaf' specifies a leaf handle. + The return value is true if successful, else, it is false. */ +static int vlleafsave(VILLA *villa, VLLEAF *leaf){ + VLREC *recp; + CBLIST *recs; + CBDATUM *buf; + char vnumbuf[VL_VNUMBUFSIZ], *zbuf; + const char *vbuf; + int i, j, ksiz, vnum, vsiz, prev, next, vnumsiz, ln, zsiz; + assert(villa && leaf); + CB_DATUMOPEN(buf); + prev = leaf->prev; + if(prev == -1) prev = VL_NODEIDMIN - 1; + VL_SETVNUMBUF(vnumsiz, vnumbuf, prev); + CB_DATUMCAT(buf, vnumbuf, vnumsiz); + next = leaf->next; + if(next == -1) next = VL_NODEIDMIN - 1; + VL_SETVNUMBUF(vnumsiz, vnumbuf, next); + CB_DATUMCAT(buf, vnumbuf, vnumsiz); + recs = leaf->recs; + ln = CB_LISTNUM(recs); + for(i = 0; i < ln; i++){ + recp = (VLREC *)CB_LISTVAL(recs, i); + ksiz = CB_DATUMSIZE(recp->key); + VL_SETVNUMBUF(vnumsiz, vnumbuf, ksiz); + CB_DATUMCAT(buf, vnumbuf, vnumsiz); + CB_DATUMCAT(buf, CB_DATUMPTR(recp->key), ksiz); + vnum = 1 + (recp->rest ? CB_LISTNUM(recp->rest) : 0); + VL_SETVNUMBUF(vnumsiz, vnumbuf, vnum); + CB_DATUMCAT(buf, vnumbuf, vnumsiz); + vsiz = CB_DATUMSIZE(recp->first); + VL_SETVNUMBUF(vnumsiz, vnumbuf, vsiz); + CB_DATUMCAT(buf, vnumbuf, vnumsiz); + CB_DATUMCAT(buf, CB_DATUMPTR(recp->first), vsiz); + if(recp->rest){ + for(j = 0; j < CB_LISTNUM(recp->rest); j++){ + vbuf = CB_LISTVAL2(recp->rest, j, vsiz); + VL_SETVNUMBUF(vnumsiz, vnumbuf, vsiz); + CB_DATUMCAT(buf, vnumbuf, vnumsiz); + CB_DATUMCAT(buf, vbuf, vsiz); + } + } + } + if(_qdbm_deflate && villa->cmode == VL_OZCOMP){ + if(!(zbuf = _qdbm_deflate(CB_DATUMPTR(buf), CB_DATUMSIZE(buf), &zsiz, _QDBM_ZMRAW))){ + CB_DATUMCLOSE(buf); + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + if(!dpput(villa->depot, (char *)&(leaf->id), sizeof(int), zbuf, zsiz, DP_DOVER)){ + CB_DATUMCLOSE(buf); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return FALSE; + } + free(zbuf); + } else if(_qdbm_lzoencode && villa->cmode == VL_OYCOMP){ + if(!(zbuf = _qdbm_lzoencode(CB_DATUMPTR(buf), CB_DATUMSIZE(buf), &zsiz))){ + CB_DATUMCLOSE(buf); + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + if(!dpput(villa->depot, (char *)&(leaf->id), sizeof(int), zbuf, zsiz, DP_DOVER)){ + CB_DATUMCLOSE(buf); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return FALSE; + } + free(zbuf); + } else if(_qdbm_bzencode && villa->cmode == VL_OXCOMP){ + if(!(zbuf = _qdbm_bzencode(CB_DATUMPTR(buf), CB_DATUMSIZE(buf), &zsiz))){ + CB_DATUMCLOSE(buf); + dpecodeset(DP_EMISC, __FILE__, __LINE__); + return FALSE; + } + if(!dpput(villa->depot, (char *)&(leaf->id), sizeof(int), zbuf, zsiz, DP_DOVER)){ + CB_DATUMCLOSE(buf); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return FALSE; + } + free(zbuf); + } else { + if(!dpput(villa->depot, (char *)&(leaf->id), sizeof(int), + CB_DATUMPTR(buf), CB_DATUMSIZE(buf), DP_DOVER)){ + CB_DATUMCLOSE(buf); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return FALSE; + } + } + CB_DATUMCLOSE(buf); + leaf->dirty = FALSE; + return TRUE; +} + + +/* Load a leaf from the database. + `villa' specifies a database handle. + `id' specifies the ID number of the leaf. + If successful, the return value is the pointer to the leaf, else, it is `NULL'. */ +static VLLEAF *vlleafload(VILLA *villa, int id){ + char wbuf[VL_PAGEBUFSIZ], *buf, *rp, *kbuf, *vbuf, *zbuf; + int i, size, step, ksiz, vnum, vsiz, prev, next, zsiz; + VLLEAF *leaf, lent; + VLREC rec; + assert(villa && id >= VL_LEAFIDMIN); + if((leaf = (VLLEAF *)cbmapget(villa->leafc, (char *)&id, sizeof(int), NULL)) != NULL){ + cbmapmove(villa->leafc, (char *)&id, sizeof(int), FALSE); + return leaf; + } + ksiz = -1; + prev = -1; + next = -1; + if((size = dpgetwb(villa->depot, (char *)&id, sizeof(int), 0, VL_PAGEBUFSIZ, wbuf)) > 0 && + size < VL_PAGEBUFSIZ){ + buf = NULL; + } else if(!(buf = dpget(villa->depot, (char *)&id, sizeof(int), 0, -1, &size))){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + if(_qdbm_inflate && villa->cmode == VL_OZCOMP){ + if(!(zbuf = _qdbm_inflate(buf ? buf : wbuf, size, &zsiz, _QDBM_ZMRAW))){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + free(buf); + return NULL; + } + free(buf); + buf = zbuf; + size = zsiz; + } else if(_qdbm_lzodecode && villa->cmode == VL_OYCOMP){ + if(!(zbuf = _qdbm_lzodecode(buf ? buf : wbuf, size, &zsiz))){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + free(buf); + return NULL; + } + free(buf); + buf = zbuf; + size = zsiz; + } else if(_qdbm_bzdecode && villa->cmode == VL_OXCOMP){ + if(!(zbuf = _qdbm_bzdecode(buf ? buf : wbuf, size, &zsiz))){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + free(buf); + return NULL; + } + free(buf); + buf = zbuf; + size = zsiz; + } + rp = buf ? buf : wbuf; + if(size >= 1){ + VL_READVNUMBUF(rp, size, prev, step); + rp += step; + size -= step; + if(prev >= VL_NODEIDMIN - 1) prev = -1; + } + if(size >= 1){ + VL_READVNUMBUF(rp, size, next, step); + rp += step; + size -= step; + if(next >= VL_NODEIDMIN - 1) next = -1; + } + lent.id = id; + lent.dirty = FALSE; + CB_LISTOPEN(lent.recs); + lent.prev = prev; + lent.next = next; + while(size >= 1){ + VL_READVNUMBUF(rp, size, ksiz, step); + rp += step; + size -= step; + if(size < ksiz) break; + kbuf = rp; + rp += ksiz; + size -= ksiz; + VL_READVNUMBUF(rp, size, vnum, step); + rp += step; + size -= step; + if(vnum < 1 || size < 1) break; + for(i = 0; i < vnum && size >= 1; i++){ + VL_READVNUMBUF(rp, size, vsiz, step); + rp += step; + size -= step; + if(size < vsiz) break; + vbuf = rp; + rp += vsiz; + size -= vsiz; + if(i < 1){ + CB_DATUMOPEN2(rec.key, kbuf, ksiz); + CB_DATUMOPEN2(rec.first, vbuf, vsiz); + rec.rest = NULL; + } else { + if(!rec.rest) CB_LISTOPEN(rec.rest); + CB_LISTPUSH(rec.rest, vbuf, vsiz); + } + } + if(i > 0) CB_LISTPUSH(lent.recs, (char *)&rec, sizeof(VLREC)); + } + free(buf); + cbmapput(villa->leafc, (char *)&(lent.id), sizeof(int), (char *)&lent, sizeof(VLLEAF), TRUE); + return (VLLEAF *)cbmapget(villa->leafc, (char *)&(lent.id), sizeof(int), NULL); +} + + +/* Load the historical leaf from the database. + `villa' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. + If successful, the return value is the pointer to the leaf, else, it is `NULL'. */ +static VLLEAF *vlgethistleaf(VILLA *villa, const char *kbuf, int ksiz){ + VLLEAF *leaf; + VLREC *recp; + int ln, rv; + assert(villa && kbuf && ksiz >= 0); + if(!(leaf = vlleafload(villa, villa->hleaf))) return NULL; + if((ln = CB_LISTNUM(leaf->recs)) < 2) return NULL; + recp = (VLREC *)CB_LISTVAL(leaf->recs, 0); + rv = villa->cmp(kbuf, ksiz, CB_DATUMPTR(recp->key), CB_DATUMSIZE(recp->key)); + if(rv == 0) return leaf; + if(rv < 0) return NULL; + recp = (VLREC *)CB_LISTVAL(leaf->recs, ln - 1); + rv = villa->cmp(kbuf, ksiz, CB_DATUMPTR(recp->key), CB_DATUMSIZE(recp->key)); + if(rv <= 0 || leaf->next < VL_LEAFIDMIN) return leaf; + return NULL; +} + + +/* Add a record to a leaf. + `villa' specifies a database handle. + `leaf' specifies a leaf handle. + `dmode' specifies behavior when the key overlaps. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region of the value. + The return value is true if successful, else, it is false. */ +static int vlleafaddrec(VILLA *villa, VLLEAF *leaf, int dmode, + const char *kbuf, int ksiz, const char *vbuf, int vsiz){ + VLREC *recp, rec; + CBLIST *recs; + int i, rv, left, right, ln, tsiz; + char *tbuf; + assert(villa && leaf && kbuf && ksiz >= 0 && vbuf && vsiz >= 0); + left = 0; + recs = leaf->recs; + ln = CB_LISTNUM(recs); + right = ln; + i = (left + right) / 2; + while(right >= left && i < ln){ + recp = (VLREC *)CB_LISTVAL(recs, i); + rv = villa->cmp(kbuf, ksiz, CB_DATUMPTR(recp->key), CB_DATUMSIZE(recp->key)); + if(rv == 0){ + break; + } else if(rv <= 0){ + right = i - 1; + } else { + left = i + 1; + } + i = (left + right) / 2; + } + while(i < ln){ + recp = (VLREC *)CB_LISTVAL(recs, i); + rv = villa->cmp(kbuf, ksiz, CB_DATUMPTR(recp->key), CB_DATUMSIZE(recp->key)); + if(rv == 0){ + switch(dmode){ + case VL_DKEEP: + return FALSE; + case VL_DCAT: + CB_DATUMCAT(recp->first, vbuf, vsiz); + break; + case VL_DDUP: + if(!recp->rest) CB_LISTOPEN(recp->rest); + CB_LISTPUSH(recp->rest, vbuf, vsiz); + villa->rnum++; + break; + case VL_DDUPR: + if(!recp->rest){ + CB_DATUMTOMALLOC(recp->first, tbuf, tsiz); + CB_DATUMOPEN2(recp->first, vbuf, vsiz); + CB_LISTOPEN(recp->rest); + CB_LISTPUSHBUF(recp->rest, tbuf, tsiz); + } else { + cblistunshift(recp->rest, CB_DATUMPTR(recp->first), CB_DATUMSIZE(recp->first)); + CB_DATUMSETSIZE(recp->first, 0); + CB_DATUMCAT(recp->first, vbuf, vsiz); + } + villa->rnum++; + break; + default: + CB_DATUMSETSIZE(recp->first, 0); + CB_DATUMCAT(recp->first, vbuf, vsiz); + break; + } + break; + } else if(rv < 0){ + CB_DATUMOPEN2(rec.key, kbuf, ksiz); + CB_DATUMOPEN2(rec.first, vbuf, vsiz); + rec.rest = NULL; + CB_LISTINSERT(recs, i, (char *)&rec, sizeof(VLREC)); + villa->rnum++; + break; + } + i++; + } + if(i >= ln){ + CB_DATUMOPEN2(rec.key, kbuf, ksiz); + CB_DATUMOPEN2(rec.first, vbuf, vsiz); + rec.rest = NULL; + CB_LISTPUSH(recs, (char *)&rec, sizeof(VLREC)); + villa->rnum++; + } + leaf->dirty = TRUE; + return TRUE; +} + + +/* Calculate the size of data of a leaf. + `leaf' specifies a leaf handle. + The return value is size of data of the leaf. */ +static int vlleafdatasize(VLLEAF *leaf){ + VLREC *recp; + CBLIST *recs, *rest; + const char *vbuf; + int i, j, sum, rnum, restnum, vsiz; + assert(leaf); + sum = 0; + recs = leaf->recs; + rnum = CB_LISTNUM(recs); + for(i = 0; i < rnum; i++){ + recp = (VLREC *)CB_LISTVAL(recs, i); + sum += CB_DATUMSIZE(recp->key); + sum += CB_DATUMSIZE(recp->first); + if(recp->rest){ + rest = recp->rest; + restnum = CB_LISTNUM(rest); + for(j = 0; j < restnum; j++){ + vbuf = CB_LISTVAL2(rest, j, vsiz); + sum += vsiz; + } + } + } + return sum; +} + + +/* Divide a leaf into two. + `villa' specifies a database handle. + `leaf' specifies a leaf handle. + The return value is the handle of a new leaf, or `NULL' on failure. */ +static VLLEAF *vlleafdivide(VILLA *villa, VLLEAF *leaf){ + VLLEAF *newleaf, *nextleaf; + VLREC *recp; + CBLIST *recs, *newrecs; + int i, mid, ln; + assert(villa && leaf); + villa->hleaf = -1; + recs = leaf->recs; + mid = CB_LISTNUM(recs) / 2; + recp = (VLREC *)CB_LISTVAL(recs, mid); + newleaf = vlleafnew(villa, leaf->id, leaf->next); + if(newleaf->next != -1){ + if(!(nextleaf = vlleafload(villa, newleaf->next))) return NULL; + nextleaf->prev = newleaf->id; + nextleaf->dirty = TRUE; + } + leaf->next = newleaf->id; + leaf->dirty = TRUE; + ln = CB_LISTNUM(recs); + newrecs = newleaf->recs; + for(i = mid; i < ln; i++){ + recp = (VLREC *)CB_LISTVAL(recs, i); + CB_LISTPUSH(newrecs, (char *)recp, sizeof(VLREC)); + } + ln = CB_LISTNUM(newrecs); + for(i = 0; i < ln; i++){ + CB_LISTDROP(recs); + } + return newleaf; +} + + +/* Create a new node. + `villa' specifies a database handle. + `heir' specifies the ID of the child before the first index. + The return value is a handle of the node. */ +static VLNODE *vlnodenew(VILLA *villa, int heir){ + VLNODE nent; + assert(villa && heir >= VL_LEAFIDMIN); + nent.id = villa->nnum + VL_NODEIDMIN; + nent.dirty = TRUE; + nent.heir = heir; + CB_LISTOPEN(nent.idxs); + villa->nnum++; + cbmapput(villa->nodec, (char *)&(nent.id), sizeof(int), (char *)&nent, sizeof(VLNODE), TRUE); + return (VLNODE *)cbmapget(villa->nodec, (char *)&(nent.id), sizeof(int), NULL); +} + + +/* Remove a node from the cache. + `villa' specifies a database handle. + `id' specifies the ID number of the node. + The return value is true if successful, else, it is false. */ +static int vlnodecacheout(VILLA *villa, int id){ + VLNODE *node; + VLIDX *idxp; + int i, err, ln; + assert(villa && id >= VL_NODEIDMIN); + if(!(node = (VLNODE *)cbmapget(villa->nodec, (char *)&id, sizeof(int), NULL))) return FALSE; + err = FALSE; + if(node->dirty && !vlnodesave(villa, node)) err = TRUE; + ln = CB_LISTNUM(node->idxs); + for(i = 0; i < ln; i++){ + idxp = (VLIDX *)CB_LISTVAL(node->idxs, i); + CB_DATUMCLOSE(idxp->key); + } + CB_LISTCLOSE(node->idxs); + cbmapout(villa->nodec, (char *)&id, sizeof(int)); + return err ? FALSE : TRUE; +} + + +/* Save a node into the database. + `villa' specifies a database handle. + `node' specifies a node handle. + The return value is true if successful, else, it is false. */ +static int vlnodesave(VILLA *villa, VLNODE *node){ + CBDATUM *buf; + char vnumbuf[VL_VNUMBUFSIZ]; + VLIDX *idxp; + int i, heir, pid, ksiz, vnumsiz, ln; + assert(villa && node); + CB_DATUMOPEN(buf); + heir = node->heir; + VL_SETVNUMBUF(vnumsiz, vnumbuf, heir); + CB_DATUMCAT(buf, vnumbuf, vnumsiz); + ln = CB_LISTNUM(node->idxs); + for(i = 0; i < ln; i++){ + idxp = (VLIDX *)CB_LISTVAL(node->idxs, i); + pid = idxp->pid; + VL_SETVNUMBUF(vnumsiz, vnumbuf, pid); + CB_DATUMCAT(buf, vnumbuf, vnumsiz); + ksiz = CB_DATUMSIZE(idxp->key); + VL_SETVNUMBUF(vnumsiz, vnumbuf, ksiz); + CB_DATUMCAT(buf, vnumbuf, vnumsiz); + CB_DATUMCAT(buf, CB_DATUMPTR(idxp->key), ksiz); + } + if(!dpput(villa->depot, (char *)&(node->id), sizeof(int), + CB_DATUMPTR(buf), CB_DATUMSIZE(buf), DP_DOVER)){ + CB_DATUMCLOSE(buf); + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return FALSE; + } + CB_DATUMCLOSE(buf); + node->dirty = FALSE; + return TRUE; +} + + +/* Load a node from the database. + `villa' specifies a database handle. + `id' specifies the ID number of the node. + If successful, the return value is the pointer to the node, else, it is `NULL'. */ +static VLNODE *vlnodeload(VILLA *villa, int id){ + char wbuf[VL_PAGEBUFSIZ], *buf, *rp, *kbuf; + int size, step, heir, pid, ksiz; + VLNODE *node, nent; + VLIDX idx; + assert(villa && id >= VL_NODEIDMIN); + if((node = (VLNODE *)cbmapget(villa->nodec, (char *)&id, sizeof(int), NULL)) != NULL){ + cbmapmove(villa->nodec, (char *)&id, sizeof(int), FALSE); + return node; + } + heir = -1; + if((size = dpgetwb(villa->depot, (char *)&id, sizeof(int), 0, VL_PAGEBUFSIZ, wbuf)) > 0 && + size < VL_PAGEBUFSIZ){ + buf = NULL; + } else if(!(buf = dpget(villa->depot, (char *)&id, sizeof(int), 0, -1, &size))){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return NULL; + } + rp = buf ? buf : wbuf; + if(size >= 1){ + VL_READVNUMBUF(rp, size, heir, step); + rp += step; + size -= step; + } + if(heir < 0){ + free(buf); + return NULL; + } + nent.id = id; + nent.dirty = FALSE; + nent.heir = heir; + CB_LISTOPEN(nent.idxs); + while(size >= 1){ + VL_READVNUMBUF(rp, size, pid, step); + rp += step; + size -= step; + if(size < 1) break; + VL_READVNUMBUF(rp, size, ksiz, step); + rp += step; + size -= step; + if(size < ksiz) break; + kbuf = rp; + rp += ksiz; + size -= ksiz; + idx.pid = pid; + CB_DATUMOPEN2(idx.key, kbuf, ksiz); + CB_LISTPUSH(nent.idxs, (char *)&idx, sizeof(VLIDX)); + } + free(buf); + cbmapput(villa->nodec, (char *)&(nent.id), sizeof(int), (char *)&nent, sizeof(VLNODE), TRUE); + return (VLNODE *)cbmapget(villa->nodec, (char *)&(nent.id), sizeof(int), NULL); +} + + +/* Add an index to a node. + `villa' specifies a database handle. + `node' specifies a node handle. + `order' specifies whether the calling sequence is orderd or not. + `pid' specifies the ID number of referred page. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. */ +static void vlnodeaddidx(VILLA *villa, VLNODE *node, int order, + int pid, const char *kbuf, int ksiz){ + VLIDX idx, *idxp; + int i, rv, left, right, ln; + assert(villa && node && pid >= VL_LEAFIDMIN && kbuf && ksiz >= 0); + idx.pid = pid; + CB_DATUMOPEN2(idx.key, kbuf, ksiz); + if(order){ + CB_LISTPUSH(node->idxs, (char *)&idx, sizeof(VLIDX)); + } else { + left = 0; + right = CB_LISTNUM(node->idxs); + i = (left + right) / 2; + ln = CB_LISTNUM(node->idxs); + while(right >= left && i < ln){ + idxp = (VLIDX *)CB_LISTVAL(node->idxs, i); + rv = villa->cmp(kbuf, ksiz, CB_DATUMPTR(idxp->key), CB_DATUMSIZE(idxp->key)); + if(rv == 0){ + break; + } else if(rv <= 0){ + right = i - 1; + } else { + left = i + 1; + } + i = (left + right) / 2; + } + ln = CB_LISTNUM(node->idxs); + while(i < ln){ + idxp = (VLIDX *)CB_LISTVAL(node->idxs, i); + if(villa->cmp(kbuf, ksiz, CB_DATUMPTR(idxp->key), CB_DATUMSIZE(idxp->key)) < 0){ + CB_LISTINSERT(node->idxs, i, (char *)&idx, sizeof(VLIDX)); + break; + } + i++; + } + if(i >= CB_LISTNUM(node->idxs)) CB_LISTPUSH(node->idxs, (char *)&idx, sizeof(VLIDX)); + } + node->dirty = TRUE; +} + + +/* Search the leaf corresponding to a key. + `villa' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. + The return value is the ID number of the leaf, or -1 on failure. */ +static int vlsearchleaf(VILLA *villa, const char *kbuf, int ksiz){ + VLNODE *node; + VLIDX *idxp; + int i, pid, rv, left, right, ln; + assert(villa && kbuf && ksiz >= 0); + pid = villa->root; + idxp = NULL; + villa->hnum = 0; + villa->hleaf = -1; + while(pid >= VL_NODEIDMIN){ + if(!(node = vlnodeload(villa, pid)) || (ln = CB_LISTNUM(node->idxs)) < 1){ + dpecodeset(DP_EBROKEN, __FILE__, __LINE__); + return -1; + } + villa->hist[villa->hnum++] = node->id; + left = 1; + right = ln; + i = (left + right) / 2; + while(right >= left && i < ln){ + idxp = (VLIDX *)CB_LISTVAL(node->idxs, i); + rv = villa->cmp(kbuf, ksiz, CB_DATUMPTR(idxp->key), CB_DATUMSIZE(idxp->key)); + if(rv == 0){ + break; + } else if(rv <= 0){ + right = i - 1; + } else { + left = i + 1; + } + i = (left + right) / 2; + } + if(i > 0) i--; + while(i < ln){ + idxp = (VLIDX *)CB_LISTVAL(node->idxs, i); + if(villa->cmp(kbuf, ksiz, CB_DATUMPTR(idxp->key), CB_DATUMSIZE(idxp->key)) < 0){ + if(i == 0){ + pid = node->heir; + break; + } + idxp = (VLIDX *)CB_LISTVAL(node->idxs, i - 1); + pid = idxp->pid; + break; + } + i++; + } + if(i >= ln) pid = idxp->pid; + } + if(villa->lleaf == pid) villa->hleaf = pid; + villa->lleaf = pid; + return pid; +} + + +/* Adjust the caches for leaves and nodes. + `villa' specifies a database handle. + The return value is true if successful, else, it is false. */ +static int vlcacheadjust(VILLA *villa){ + const char *tmp; + int i, pid, err; + err = FALSE; + if(cbmaprnum(villa->leafc) > villa->leafcnum){ + cbmapiterinit(villa->leafc); + for(i = 0; i < VL_CACHEOUT; i++){ + tmp = cbmapiternext(villa->leafc, NULL); + pid = *(int *)tmp; + if(!vlleafcacheout(villa, pid)) err = TRUE; + } + } + if(cbmaprnum(villa->nodec) > villa->nodecnum){ + cbmapiterinit(villa->nodec); + for(i = 0; i < VL_CACHEOUT; i++){ + tmp = cbmapiternext(villa->nodec, NULL); + pid = *(int *)tmp; + if(!vlnodecacheout(villa, pid)) err = TRUE; + } + } + return err ? FALSE : TRUE; +} + + +/* Search a record of a leaf. + `villa' specifies a database handle. + `leaf' specifies a leaf handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. + `ip' specifies the pointer to a variable to fetch the index of the correspnding record. + The return value is the pointer to a corresponding record, or `NULL' on failure. */ +static VLREC *vlrecsearch(VILLA *villa, VLLEAF *leaf, const char *kbuf, int ksiz, int *ip){ + VLREC *recp; + CBLIST *recs; + int i, rv, left, right, ln; + assert(villa && leaf && kbuf && ksiz >= 0); + recs = leaf->recs; + ln = CB_LISTNUM(recs); + left = 0; + right = ln; + i = (left + right) / 2; + while(right >= left && i < ln){ + recp = (VLREC *)CB_LISTVAL(recs, i); + rv = villa->cmp(kbuf, ksiz, CB_DATUMPTR(recp->key), CB_DATUMSIZE(recp->key)); + if(rv == 0){ + if(ip) *ip = i; + return recp; + } else if(rv <= 0){ + right = i - 1; + } else { + left = i + 1; + } + i = (left + right) / 2; + } + if(ip) *ip = i; + return NULL; +} + + +/* Get flags of a database. */ +int vlgetflags(VILLA *villa){ + assert(villa); + return dpgetflags(villa->depot); +} + + +/* Set flags of a database. + `villa' specifies a database handle connected as a writer. + `flags' specifies flags to set. Lesser ten bits are reserved for internal use. + If successful, the return value is true, else, it is false. */ +int vlsetflags(VILLA *villa, int flags){ + assert(villa); + if(!villa->wmode){ + dpecodeset(DP_EMODE, __FILE__, __LINE__); + return FALSE; + } + return dpsetflags(villa->depot, flags); +} + + + +/* END OF FILE */ diff --git a/qdbm/villa.h b/qdbm/villa.h new file mode 100644 index 00000000..01f396bf --- /dev/null +++ b/qdbm/villa.h @@ -0,0 +1,758 @@ +/************************************************************************************************* + * The advanced API of QDBM + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#ifndef _VILLA_H /* duplication check */ +#define _VILLA_H + +#if defined(__cplusplus) /* export for C++ */ +extern "C" { +#endif + + +#include +#include +#include +#include + + +#if defined(_MSC_VER) && !defined(QDBM_INTERNAL) && !defined(QDBM_STATIC) +#define MYEXTERN extern __declspec(dllimport) +#else +#define MYEXTERN extern +#endif + + + +/************************************************************************************************* + * API + *************************************************************************************************/ + + +#define VL_LEVELMAX 64 /* max level of B+ tree */ + +typedef struct { /* type of structure for a record */ + CBDATUM *key; /* datum of the key */ + CBDATUM *first; /* datum of the first value */ + CBLIST *rest; /* list of the rest values */ +} VLREC; + +typedef struct { /* type of structure for index of a page */ + int pid; /* ID number of the referring page */ + CBDATUM *key; /* threshold key of the page */ +} VLIDX; + +typedef struct { /* type of structure for a leaf page */ + int id; /* ID number of the leaf */ + int dirty; /* whether to be written back */ + CBLIST *recs; /* list of records */ + int prev; /* ID number of the previous leaf */ + int next; /* ID number of the next leaf */ +} VLLEAF; + +typedef struct { /* type of structure for a node page */ + int id; /* ID number of the node */ + int dirty; /* whether to be written back */ + int heir; /* ID of the child before the first index */ + CBLIST *idxs; /* list of indexes */ +} VLNODE; + +/* type of the pointer to a comparing function. + `aptr' specifies the pointer to the region of one key. + `asiz' specifies the size of the region of one key. + `bptr' specifies the pointer to the region of the other key. + `bsiz' specifies the size of the region of the other key. + The return value is positive if the former is big, negative if the latter is big, 0 if both + are equivalent. */ +typedef int (*VLCFUNC)(const char *aptr, int asiz, const char *bptr, int bsiz); +MYEXTERN VLCFUNC VL_CMPLEX; /* lexical comparing function */ +MYEXTERN VLCFUNC VL_CMPINT; /* native integer comparing function */ +MYEXTERN VLCFUNC VL_CMPNUM; /* big endian number comparing function */ +MYEXTERN VLCFUNC VL_CMPDEC; /* decimal string comparing function */ + +typedef struct { /* type of structure for a database handle */ + DEPOT *depot; /* internal database handle */ + VLCFUNC cmp; /* pointer to the comparing function */ + int wmode; /* whether to be writable */ + int cmode; /* compression mode for leaves */ + int root; /* ID number of the root page */ + int last; /* ID number of the last leaf */ + int lnum; /* number of leaves */ + int nnum; /* number of nodes */ + int rnum; /* number of records */ + CBMAP *leafc; /* cache for leaves */ + CBMAP *nodec; /* cache for nodes */ + int hist[VL_LEVELMAX]; /* array history of visited nodes */ + int hnum; /* number of elements of the history */ + int hleaf; /* ID number of the leaf referred by the history */ + int lleaf; /* ID number of the last visited leaf */ + int curleaf; /* ID number of the leaf where the cursor is */ + int curknum; /* index of the key where the cursor is */ + int curvnum; /* index of the value where the cursor is */ + int leafrecmax; /* max number of records in a leaf */ + int nodeidxmax; /* max number of indexes in a node */ + int leafcnum; /* max number of caching leaves */ + int nodecnum; /* max number of caching nodes */ + int avglsiz; /* average size of each leave */ + int avgnsiz; /* average size of each node */ + int tran; /* whether in the transaction */ + int rbroot; /* root for rollback */ + int rblast; /* last for rollback */ + int rblnum; /* lnum for rollback */ + int rbnnum; /* nnum for rollback */ + int rbrnum; /* rnum for rollback */ +} VILLA; + +typedef struct { /* type of structure for a multiple cursor handle */ + VILLA *villa; /* database handle */ + int curleaf; /* ID number of the leaf where the cursor is */ + int curknum; /* index of the key where the cursor is */ + int curvnum; /* index of the value where the cursor is */ +} VLMULCUR; + +enum { /* enumeration for open modes */ + VL_OREADER = 1 << 0, /* open as a reader */ + VL_OWRITER = 1 << 1, /* open as a writer */ + VL_OCREAT = 1 << 2, /* a writer creating */ + VL_OTRUNC = 1 << 3, /* a writer truncating */ + VL_ONOLCK = 1 << 4, /* open without locking */ + VL_OLCKNB = 1 << 5, /* lock without blocking */ + VL_OZCOMP = 1 << 6, /* compress leaves with ZLIB */ + VL_OYCOMP = 1 << 7, /* compress leaves with LZO */ + VL_OXCOMP = 1 << 8 /* compress leaves with BZIP2 */ +}; + +enum { /* enumeration for write modes */ + VL_DOVER, /* overwrite the existing value */ + VL_DKEEP, /* keep the existing value */ + VL_DCAT, /* concatenate values */ + VL_DDUP, /* allow duplication of keys */ + VL_DDUPR /* allow duplication with reverse order */ +}; + +enum { /* enumeration for jump modes */ + VL_JFORWARD, /* step forward */ + VL_JBACKWARD /* step backward */ +}; + +enum { /* enumeration for insertion modes */ + VL_CPCURRENT, /* overwrite the current record */ + VL_CPBEFORE, /* insert before the current record */ + VL_CPAFTER /* insert after the current record */ +}; + + +/* Get a database handle. + `name' specifies the name of a database file. + `omode' specifies the connection mode: `VL_OWRITER' as a writer, `VL_OREADER' as a reader. + If the mode is `VL_OWRITER', the following may be added by bitwise or: `VL_OCREAT', which + means it creates a new database if not exist, `VL_OTRUNC', which means it creates a new + database regardless if one exists, `VL_OZCOMP', which means leaves in the database are + compressed with ZLIB, `VL_OYCOMP', which means leaves in the database are compressed with LZO, + `VL_OXCOMP', which means leaves in the database are compressed with BZIP2. Both of + `VL_OREADER' and `VL_OWRITER' can be added to by bitwise or: `VL_ONOLCK', which means it opens + a database file without file locking, or `VL_OLCKNB', which means locking is performed without + blocking. + `cmp' specifies a comparing function: `VL_CMPLEX' comparing keys in lexical order, + `VL_CMPINT' comparing keys as objects of `int' in native byte order, `VL_CMPNUM' comparing + keys as numbers of big endian, `VL_CMPDEC' comparing keys as decimal strings. Any function + based on the declaration of the type `VLCFUNC' can be assigned to the comparing function. + The comparing function should be kept same in the life of a database. + The return value is the database handle or `NULL' if it is not successful. + While connecting as a writer, an exclusive lock is invoked to the database file. + While connecting as a reader, a shared lock is invoked to the database file. The thread + blocks until the lock is achieved. `VL_OZCOMP', `VL_OYCOMP', and `VL_OXCOMP' are available + only if QDBM was built each with ZLIB, LZO, and BZIP2 enabled. If `VL_ONOLCK' is used, the + application is responsible for exclusion control. */ +VILLA *vlopen(const char *name, int omode, VLCFUNC cmp); + + +/* Close a database handle. + `villa' specifies a database handle. + If successful, the return value is true, else, it is false. + Because the region of a closed handle is released, it becomes impossible to use the handle. + Updating a database is assured to be written when the handle is closed. If a writer opens + a database but does not close it appropriately, the database will be broken. If the + transaction is activated and not committed, it is aborted. */ +int vlclose(VILLA *villa); + + +/* Store a record. + `villa' specifies a database handle connected as a writer. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region of the value. If it is negative, the size is + assigned with `strlen(vbuf)'. + `dmode' specifies behavior when the key overlaps, by the following values: `VL_DOVER', + which means the specified value overwrites the existing one, `VL_DKEEP', which means the + existing value is kept, `VL_DCAT', which means the specified value is concatenated at the + end of the existing value, `VL_DDUP', which means duplication of keys is allowed and the + specified value is added as the last one, `VL_DDUPR', which means duplication of keys is + allowed and the specified value is added as the first one. + If successful, the return value is true, else, it is false. + The cursor becomes unavailable due to updating database. */ +int vlput(VILLA *villa, const char *kbuf, int ksiz, const char *vbuf, int vsiz, int dmode); + + +/* Delete a record. + `villa' specifies a database handle connected as a writer. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is true, else, it is false. False is returned when no + record corresponds to the specified key. + When the key of duplicated records is specified, the first record of the same key is deleted. + The cursor becomes unavailable due to updating database. */ +int vlout(VILLA *villa, const char *kbuf, int ksiz); + + +/* Retrieve a record. + `villa' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to + the specified key. + When the key of duplicated records is specified, the value of the first record of the same + key is selected. Because an additional zero code is appended at the end of the region of the + return value, the return value can be treated as a character string. Because the region of + the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +char *vlget(VILLA *villa, const char *kbuf, int ksiz, int *sp); + + +/* Get the size of the value of a record. + `villa' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is the size of the value of the corresponding record, else, + it is -1. If multiple records correspond, the size of the first is returned. */ +int vlvsiz(VILLA *villa, const char *kbuf, int ksiz); + + +/* Get the number of records corresponding a key. + `villa' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + The return value is the number of corresponding records. If no record corresponds, 0 is + returned. */ +int vlvnum(VILLA *villa, const char *kbuf, int ksiz); + + +/* Store plural records corresponding a key. + `villa' specifies a database handle connected as a writer. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `vals' specifies a list handle of values. The list should not be empty. + If successful, the return value is true, else, it is false. + The cursor becomes unavailable due to updating database. */ +int vlputlist(VILLA *villa, const char *kbuf, int ksiz, const CBLIST *vals); + + +/* Delete all records corresponding a key. + `villa' specifies a database handle connected as a writer. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is true, else, it is false. False is returned when no + record corresponds to the specified key. + The cursor becomes unavailable due to updating database. */ +int vloutlist(VILLA *villa, const char *kbuf, int ksiz); + + +/* Retrieve values of all records corresponding a key. + `villa' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + If successful, the return value is a list handle of the values of the corresponding records, + else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. + Because the handle of the return value is opened with the function `cblistopen', it should + be closed with the function `cblistclose' if it is no longer in use. */ +CBLIST *vlgetlist(VILLA *villa, const char *kbuf, int ksiz); + + +/* Retrieve concatenated values of all records corresponding a key. + `villa' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the concatenated values of + the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds + to the specified key. Because an additional zero code is appended at the end of the region of + the return value, the return value can be treated as a character string. Because the region + of the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +char *vlgetcat(VILLA *villa, const char *kbuf, int ksiz, int *sp); + + +/* Move the cursor to the first record. + `villa' specifies a database handle. + If successful, the return value is true, else, it is false. False is returned if there is + no record in the database. */ +int vlcurfirst(VILLA *villa); + + +/* Move the cursor to the last record. + `villa' specifies a database handle. + If successful, the return value is true, else, it is false. False is returned if there is + no record in the database. */ +int vlcurlast(VILLA *villa); + + +/* Move the cursor to the previous record. + `villa' specifies a database handle. + If successful, the return value is true, else, it is false. False is returned if there is + no previous record. */ +int vlcurprev(VILLA *villa); + + +/* Move the cursor to the next record. + `villa' specifies a database handle. + If successful, the return value is true, else, it is false. False is returned if there is + no next record. */ +int vlcurnext(VILLA *villa); + + +/* Move the cursor to a position around a record. + `villa' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `jmode' specifies detail adjustment: `VL_JFORWARD', which means that the cursor is set to + the first record of the same key and that the cursor is set to the next substitute if + completely matching record does not exist, `VL_JBACKWARD', which means that the cursor is + set to the last record of the same key and that the cursor is set to the previous substitute + if completely matching record does not exist. + If successful, the return value is true, else, it is false. False is returned if there is + no record corresponding the condition. */ +int vlcurjump(VILLA *villa, const char *kbuf, int ksiz, int jmode); + + +/* Get the key of the record where the cursor is. + `villa' specifies a database handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the key of the corresponding + record, else, it is `NULL'. `NULL' is returned when no record corresponds to the cursor. + Because an additional zero code is appended at the end of the region of the + return value, the return value can be treated as a character string. Because the region of + the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +char *vlcurkey(VILLA *villa, int *sp); + + +/* Get the value of the record where the cursor is. + `villa' specifies a database handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to + the cursor. + Because an additional zero code is appended at the end of the region of the + return value, the return value can be treated as a character string. Because the region of + the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +char *vlcurval(VILLA *villa, int *sp); + + +/* Insert a record around the cursor. + `villa' specifies a database handle connected as a writer. + `vbuf' specifies the pointer to the region of a value. + `vsiz' specifies the size of the region of the value. If it is negative, the size is + assigned with `strlen(vbuf)'. + `cpmode' specifies detail adjustment: `VL_CPCURRENT', which means that the value of the + current record is overwritten, `VL_CPBEFORE', which means that a new record is inserted before + the current record, `VL_CPAFTER', which means that a new record is inserted after the current + record. + If successful, the return value is true, else, it is false. False is returned when no record + corresponds to the cursor. + After insertion, the cursor is moved to the inserted record. */ +int vlcurput(VILLA *villa, const char *vbuf, int vsiz, int cpmode); + + +/* Delete the record where the cursor is. + `villa' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. False is returned when no record + corresponds to the cursor. + After deletion, the cursor is moved to the next record if possible. */ +int vlcurout(VILLA *villa); + + +/* Set the tuning parameters for performance. + `villa' specifies a database handle. + `lrecmax' specifies the max number of records in a leaf node of B+ tree. If it is not more + than 0, the default value is specified. + `nidxmax' specifies the max number of indexes in a non-leaf node of B+ tree. If it is not + more than 0, the default value is specified. + `lcnum' specifies the max number of caching leaf nodes. If it is not more than 0, the + default value is specified. + `ncnum' specifies the max number of caching non-leaf nodes. If it is not more than 0, the + default value is specified. + The default setting is equivalent to `vlsettuning(49, 192, 1024, 512)'. Because tuning + parameters are not saved in a database, you should specify them every opening a database. */ +void vlsettuning(VILLA *villa, int lrecmax, int nidxmax, int lcnum, int ncnum); + + +/* Set the size of the free block pool of a database handle. + `villa' specifies a database handle connected as a writer. + `size' specifies the size of the free block pool of a database. + If successful, the return value is true, else, it is false. + The default size of the free block pool is 256. If the size is greater, the space efficiency + of overwriting values is improved with the time efficiency sacrificed. */ +int vlsetfbpsiz(VILLA *villa, int size); + + +/* Synchronize updating contents with the file and the device. + `villa' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. + This function is useful when another process uses the connected database file. This function + should not be used while the transaction is activated. */ +int vlsync(VILLA *villa); + + +/* Optimize a database. + `villa' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. + In an alternating succession of deleting and storing with overwrite or concatenate, + dispensable regions accumulate. This function is useful to do away with them. This function + should not be used while the transaction is activated. */ +int vloptimize(VILLA *villa); + + +/* Get the name of a database. + `villa' specifies a database handle. + If successful, the return value is the pointer to the region of the name of the database, + else, it is `NULL'. + Because the region of the return value is allocated with the `malloc' call, it should be + released with the `free' call if it is no longer in use. */ +char *vlname(VILLA *villa); + + +/* Get the size of a database file. + `villa' specifies a database handle. + If successful, the return value is the size of the database file, else, it is -1. + Because of the I/O buffer, the return value may be less than the hard size. */ +int vlfsiz(VILLA *villa); + + +/* Get the number of the leaf nodes of B+ tree. + `villa' specifies a database handle. + If successful, the return value is the number of the leaf nodes, else, it is -1. */ +int vllnum(VILLA *villa); + + +/* Get the number of the non-leaf nodes of B+ tree. + `villa' specifies a database handle. + If successful, the return value is the number of the non-leaf nodes, else, it is -1. */ +int vlnnum(VILLA *villa); + + +/* Get the number of the records stored in a database. + `villa' specifies a database handle. + If successful, the return value is the number of the records stored in the database, else, + it is -1. */ +int vlrnum(VILLA *villa); + + +/* Check whether a database handle is a writer or not. + `villa' specifies a database handle. + The return value is true if the handle is a writer, false if not. */ +int vlwritable(VILLA *villa); + + +/* Check whether a database has a fatal error or not. + `villa' specifies a database handle. + The return value is true if the database has a fatal error, false if not. */ +int vlfatalerror(VILLA *villa); + + +/* Get the inode number of a database file. + `villa' specifies a database handle. + The return value is the inode number of the database file. */ +int vlinode(VILLA *villa); + + +/* Get the last modified time of a database. + `villa' specifies a database handle. + The return value is the last modified time of the database. */ +time_t vlmtime(VILLA *villa); + + +/* Begin the transaction. + `villa' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. + Because this function does not perform mutual exclusion control in multi-thread, the + application is responsible for it. Only one transaction can be activated with a database + handle at the same time. */ +int vltranbegin(VILLA *villa); + + +/* Commit the transaction. + `villa' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. + Updating a database in the transaction is fixed when it is committed successfully. */ +int vltrancommit(VILLA *villa); + + +/* Abort the transaction. + `villa' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. + Updating a database in the transaction is discarded when it is aborted. The state of the + database is rollbacked to before transaction. */ +int vltranabort(VILLA *villa); + + +/* Remove a database file. + `name' specifies the name of a database file. + If successful, the return value is true, else, it is false. */ +int vlremove(const char *name); + + +/* Repair a broken database file. + `name' specifies the name of a database file. + `cmp' specifies the comparing function of the database file. + If successful, the return value is true, else, it is false. + There is no guarantee that all records in a repaired database file correspond to the original + or expected state. */ +int vlrepair(const char *name, VLCFUNC cmp); + + +/* Dump all records as endian independent data. + `villa' specifies a database handle. + `name' specifies the name of an output file. + If successful, the return value is true, else, it is false. */ +int vlexportdb(VILLA *villa, const char *name); + + +/* Load all records from endian independent data. + `villa' specifies a database handle connected as a writer. The database of the handle must + be empty. + `name' specifies the name of an input file. + If successful, the return value is true, else, it is false. */ +int vlimportdb(VILLA *villa, const char *name); + + + +/************************************************************************************************* + * features for experts + *************************************************************************************************/ + + +/* Number of division of the database for Vista. */ +#define vlcrdnum (*vlcrdnumptr()) + + +/* Get the pointer of the variable of the number of division of the database for Vista. + The return value is the pointer of the variable. */ +int *vlcrdnumptr(void); + + +/* Synchronize updating contents on memory. + `villa' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. */ +int vlmemsync(VILLA *villa); + + +/* Synchronize updating contents on memory, not physically. + `villa' specifies a database handle connected as a writer. + If successful, the return value is true, else, it is false. */ +int vlmemflush(VILLA *villa); + + +/* Refer to volatile cache of a value of a record. + `villa' specifies a database handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to + the specified key. + Because the region of the return value is volatile and it may be spoiled by another operation + of the database, the data should be copied into another involatile buffer immediately. */ +const char *vlgetcache(VILLA *villa, const char *kbuf, int ksiz, int *sp); + + +/* Refer to volatile cache of the key of the record where the cursor is. + `villa' specifies a database handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the key of the corresponding + record, else, it is `NULL'. `NULL' is returned when no record corresponds to the cursor. + Because the region of the return value is volatile and it may be spoiled by another operation + of the database, the data should be copied into another involatile buffer immediately. */ +const char *vlcurkeycache(VILLA *villa, int *sp); + + +/* Refer to volatile cache of the value of the record where the cursor is. + `villa' specifies a database handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to + the cursor. + Because an additional zero code is appended at the end of the region of the + return value, the return value can be treated as a character string. Because the region of + the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +const char *vlcurvalcache(VILLA *villa, int *sp); + + +/* Get a multiple cursor handle. + `villa' specifies a database handle connected as a reader. + The return value is a multiple cursor handle or `NULL' if it is not successful. + The returned object is should be closed before the database handle is closed. Even if plural + cursors are fetched out of a database handle, they does not share the locations with each + other. Note that this function can be used only if the database handle is connected as a + reader. */ +VLMULCUR *vlmulcuropen(VILLA *villa); + + +/* Close a multiple cursor handle. + `mulcur' specifies a multiple cursor handle. */ +void vlmulcurclose(VLMULCUR *mulcur); + + +/* Move a multiple cursor to the first record. + `mulcur' specifies a multiple cursor handle. + If successful, the return value is true, else, it is false. False is returned if there is + no record in the database. */ +int vlmulcurfirst(VLMULCUR *mulcur); + + +/* Move a multiple cursor to the last record. + `mulcur' specifies a multiple cursor handle. + If successful, the return value is true, else, it is false. False is returned if there is + no record in the database. */ +int vlmulcurlast(VLMULCUR *mulcur); + + +/* Move a multiple cursor to the previous record. + `mulcur' specifies a multiple cursor handle. + If successful, the return value is true, else, it is false. False is returned if there is + no previous record. */ +int vlmulcurprev(VLMULCUR *mulcur); + + +/* Move a multiple cursor to the next record. + `mulcur' specifies a multiple cursor handle. + If successful, the return value is true, else, it is false. False is returned if there is + no next record. */ +int vlmulcurnext(VLMULCUR *mulcur); + + +/* Move a multiple cursor to a position around a record. + `mulcur' specifies a multiple cursor handle. + `kbuf' specifies the pointer to the region of a key. + `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned + with `strlen(kbuf)'. + `jmode' specifies detail adjustment: `VL_JFORWARD', which means that the cursor is set to + the first record of the same key and that the cursor is set to the next substitute if + completely matching record does not exist, `VL_JBACKWARD', which means that the cursor is + set to the last record of the same key and that the cursor is set to the previous substitute + if completely matching record does not exist. + If successful, the return value is true, else, it is false. False is returned if there is + no record corresponding the condition. */ +int vlmulcurjump(VLMULCUR *mulcur, const char *kbuf, int ksiz, int jmode); + + +/* Get the key of the record where a multiple cursor is. + `mulcur' specifies a multiple cursor handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the key of the corresponding + record, else, it is `NULL'. `NULL' is returned when no record corresponds to the cursor. + Because an additional zero code is appended at the end of the region of the + return value, the return value can be treated as a character string. Because the region of + the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +char *vlmulcurkey(VLMULCUR *mulcur, int *sp); + + +/* Get the value of the record where a multiple cursor is. + `mulcur' specifies a multiple cursor handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to + the cursor. + Because an additional zero code is appended at the end of the region of the + return value, the return value can be treated as a character string. Because the region of + the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +char *vlmulcurval(VLMULCUR *mulcur, int *sp); + + +/* Refer to volatile cache of the key of the record where a multiple cursor is. + `mulcur' specifies a multiple cursor handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the key of the corresponding + record, else, it is `NULL'. `NULL' is returned when no record corresponds to the cursor. + Because the region of the return value is volatile and it may be spoiled by another operation + of the database, the data should be copied into another involatile buffer immediately. */ +const char *vlmulcurkeycache(VLMULCUR *mulcur, int *sp); + + +/* Refer to volatile cache of the value of the record where a multiple cursor is. + `mulcur' specifies a multiple cursor handle. + `sp' specifies the pointer to a variable to which the size of the region of the return + value is assigned. If it is `NULL', it is not used. + If successful, the return value is the pointer to the region of the value of the + corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to + the cursor. + Because an additional zero code is appended at the end of the region of the + return value, the return value can be treated as a character string. Because the region of + the return value is allocated with the `malloc' call, it should be released with the `free' + call if it is no longer in use. */ +const char *vlmulcurvalcache(VLMULCUR *mulcur, int *sp); + + +/* Get flags of a database. + `villa' specifies a database handle. + The return value is the flags of a database. */ +int vlgetflags(VILLA *villa); + + +/* Set flags of a database. + `villa' specifies a database handle connected as a writer. + `flags' specifies flags to set. Least ten bits are reserved for internal use. + If successful, the return value is true, else, it is false. */ +int vlsetflags(VILLA *villa, int flags); + + + +#undef MYEXTERN + +#if defined(__cplusplus) /* export for C++ */ +} +#endif + +#endif /* duplication check */ + + +/* END OF FILE */ diff --git a/qdbm/vista.c b/qdbm/vista.c new file mode 100644 index 00000000..011c229a --- /dev/null +++ b/qdbm/vista.c @@ -0,0 +1,171 @@ +/************************************************************************************************* + * Implementation of Vista + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#define QDBM_INTERNAL 1 +#define _VISTA_C 1 + +#include "vista.h" +#include "myconf.h" + + + +/************************************************************************************************* + * macros to convert Depot to Curia + *************************************************************************************************/ + + +#define DEPOT CURIA + +#define \ + dpopen(name, omode, bnum) \ + cropen(name, omode, ((bnum / vlcrdnum) * 2), vlcrdnum) + +#define \ + dpclose(db) \ + crclose(db) + +#define \ + dpput(db, kbuf, ksiz, vbuf, vsiz, dmode) \ + crput(db, kbuf, ksiz, vbuf, vsiz, dmode) + +#define \ + dpout(db, kbuf, ksiz) \ + crout(db, kbuf, ksiz) + +#define \ + dpget(db, kbuf, ksiz, start, max, sp) \ + crget(db, kbuf, ksiz, start, max, sp) + +#define \ + dpgetwb(db, kbuf, ksiz, start, max, vbuf) \ + crgetwb(db, kbuf, ksiz, start, max, vbuf) + +#define \ + dpvsiz(db, kbuf, ksiz) \ + crvsiz(db, kbuf, ksiz) + +#define \ + dpiterinit(db) \ + criterinit(db) + +#define \ + dpiternext(db, sp) \ + criternext(db, sp) + +#define \ + dpsetalign(db, align) \ + crsetalign(db, align) + +#define \ + dpsetfbpsiz(db, size) \ + crsetfbpsiz(db, size) + +#define \ + dpsync(db) \ + crsync(db) + +#define \ + dpoptimize(db, bnum) \ + croptimize(db, bnum) + +#define \ + dpname(db) \ + crname(db) + +#define \ + dpfsiz(db) \ + crfsiz(db) + +#define \ + dpbnum(db) \ + crbnum(db) + +#define \ + dpbusenum(db) \ + crbusenum(db) + +#define \ + dprnum(db) \ + crrnum(db) + +#define \ + dpwritable(db) \ + crwritable(db) + +#define \ + dpfatalerror(db) \ + crfatalerror(db) + +#define \ + dpinode(db) \ + crinode(db) + +#define \ + dpmtime(db) \ + crmtime(db) + +#define \ + dpfdesc(db) \ + crfdesc(db) + +#define \ + dpremove(db) \ + crremove(db) + +#define \ + dprepair(db) \ + crrepair(db) + +#define \ + dpexportdb(db, name) \ + crexportdb(db, name) + +#define \ + dpimportdb(db, name) \ + crimportdb(db, name) + +#define \ + dpsnaffle(db, name) \ + crsnaffle(db, name) + +#define \ + dpmemsync(db) \ + crmemsync(db) + +#define \ + dpmemflush(db) \ + crmemflush(db) + +#define \ + dpgetflags(db) \ + crgetflags(db) + +#define \ + dpsetflags(db, flags) \ + crsetflags(db, flags) + + + +/************************************************************************************************* + * including real implementation + *************************************************************************************************/ + + +#include "villa.c" + + + +/* END OF FILE */ diff --git a/qdbm/vista.h b/qdbm/vista.h new file mode 100644 index 00000000..bb67fbb1 --- /dev/null +++ b/qdbm/vista.h @@ -0,0 +1,138 @@ +/************************************************************************************************* + * The extended advanced API of QDBM + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#ifndef _VISTA_H /* duplication check */ +#define _VISTA_H + +#if defined(__cplusplus) /* export for C++ */ +extern "C" { +#endif + + + +/************************************************************************************************* + * macros to borrow symbols from Villa + *************************************************************************************************/ + + +#include +#include +#include +#include + +#define VLREC VSTREC +#define VLIDX VSTIDX +#define VLLEAF VSTLEAF +#define VLNODE VSTNODE +#define VLCFUNC VSTCFUNC + +#define VL_CMPLEX VST_CMPLEX +#define VL_CMPINT VST_CMPINT +#define VL_CMPNUM VST_CMPNUM +#define VL_CMPDEC VST_CMPDEC + +#define VILLA VISTA + +#define VL_OREADER VST_OREADER +#define VL_OWRITER VST_OWRITER +#define VL_OCREAT VST_OCREAT +#define VL_OTRUNC VST_OTRUNC +#define VL_ONOLCK VST_ONOLCK +#define VL_OLCKNB VST_OLCKNB +#define VL_OZCOMP VST_OZCOMP + +#define VL_DOVER VST_DOVER +#define VL_DKEEP VST_DKEEP +#define VL_DCAT VST_DCAT +#define VL_DDUP VST_DDUP + +#define VL_JFORWARD VST_JFORWARD +#define VL_JBACKWARD VST_JBACKWARD + +#define vlopen vstopen +#define vlclose vstclose +#define vlput vstput +#define vlout vstout +#define vlget vstget +#define vlvsiz vstvsiz +#define vlvnum vstvnum +#define vlputlist vstputlist +#define vloutlist vstoutlist +#define vlgetlist vstgetlist +#define vlgetcat vstgetcat +#define vlcurfirst vstcurfirst +#define vlcurlast vstcurlast +#define vlcurprev vstcurprev +#define vlcurnext vstcurnext +#define vlcurjump vstcurjump +#define vlcurkey vstcurkey +#define vlcurval vstcurval +#define vlcurput vstcurput +#define vlcurout vstcurout +#define vlsettuning vstsettuning +#define vlsync vstsync +#define vloptimize vstoptimize +#define vlname vstname +#define vlfsiz vstfsiz +#define vllnum vstlnum +#define vlnnum vstnnum +#define vlrnum vstrnum +#define vlwritable vstwritable +#define vlfatalerror vstfatalerror +#define vlinode vstinode +#define vlmtime vstmtime +#define vltranbegin vsttranbegin +#define vltrancommit vsttrancommit +#define vltranabort vsttranabort +#define vlremove vstremove +#define vlrepair vstrepair +#define vlexportdb vstexportdb +#define vlimportdb vstimportdb +#define vlcrdnumptr vstcrdnumptr +#define vlmemsync vstmemsync +#define vlmemflush vstmemflush +#define vlgetcache vstgetcache +#define vlcurkeycache vstcurkeycache +#define vlcurvalcache vstcurvalcache +#define vlmulcuropen vstmulcuropen +#define vlmulcurclose vstmulcurclose +#define vlmulcurfirst vstmulcurfirst +#define vlmulcurlast vstmulcurlast +#define vlmulcurprev vstmulcurprev +#define vlmulcurnext vstmulcurnext +#define vlmulcurjump vstmulcurjump +#define vlmulcurkey vstmulcurkey +#define vlmulcurval vstmulcurval +#define vlmulcurkeycache vstmulcurkeycache +#define vlmulcurvalcache vstmulcurvalcache +#define vlsetfbpsiz vstsetfbpsiz +#define vlgetflags vstgetflags +#define vlsetflags vstsetflags + +#if !defined(_VISTA_C) +#include +#endif + + + +#if defined(__cplusplus) /* export for C++ */ +} +#endif + +#endif /* duplication check */ + + +/* END OF FILE */ diff --git a/qdbm/vlmgr.c b/qdbm/vlmgr.c new file mode 100644 index 00000000..59aae394 --- /dev/null +++ b/qdbm/vlmgr.c @@ -0,0 +1,968 @@ +/************************************************************************************************* + * Utility for debugging Villa and its applications + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +char *hextoobj(const char *str, int *sp); +char *dectoiobj(const char *str, int *sp); +int runcreate(int argc, char **argv); +int runput(int argc, char **argv); +int runout(int argc, char **argv); +int runget(int argc, char **argv); +int runlist(int argc, char **argv); +int runoptimize(int argc, char **argv); +int runinform(int argc, char **argv); +int runremove(int argc, char **argv); +int runrepair(int argc, char **argv); +int runexportdb(int argc, char **argv); +int runimportdb(int argc, char **argv); +void pdperror(const char *name); +void printobj(const char *obj, int size); +void printobjhex(const char *obj, int size); +int docreate(const char *name, int cmode); +int doput(const char *name, const char *kbuf, int ksiz, const char *vbuf, int vsiz, + int dmode, VLCFUNC cmp); +int doout(const char *name, const char *kbuf, int ksiz, VLCFUNC cmp, int lb); +int doget(const char *name, int opts, const char *kbuf, int ksiz, VLCFUNC cmp, + int lb, int ox, int nb); +int dolist(const char *name, int opts, const char *tbuf, int tsiz, const char *bbuf, int bsiz, + VLCFUNC cmp, int ki, int kb, int vb, int ox, int gt, int lt, int max, int desc); +int dooptimize(const char *name); +int doinform(const char *name, int opts); +int doremove(const char *name); +int dorepair(const char *name, VLCFUNC cmp); +int doexportdb(const char *name, const char *file, VLCFUNC cmp); +int doimportdb(const char *name, const char *file, VLCFUNC cmp); + + +/* main routine */ +int main(int argc, char **argv){ + char *env; + int rv; + cbstdiobin(); + progname = argv[0]; + if((env = getenv("QDBMDBGFD")) != NULL) dpdbgfd = atoi(env); + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "create")){ + rv = runcreate(argc, argv); + } else if(!strcmp(argv[1], "put")){ + rv = runput(argc, argv); + } else if(!strcmp(argv[1], "out")){ + rv = runout(argc, argv); + } else if(!strcmp(argv[1], "get")){ + rv = runget(argc, argv); + } else if(!strcmp(argv[1], "list")){ + rv = runlist(argc, argv); + } else if(!strcmp(argv[1], "optimize")){ + rv = runoptimize(argc, argv); + } else if(!strcmp(argv[1], "inform")){ + rv = runinform(argc, argv); + } else if(!strcmp(argv[1], "remove")){ + rv = runremove(argc, argv); + } else if(!strcmp(argv[1], "repair")){ + rv = runrepair(argc, argv); + } else if(!strcmp(argv[1], "exportdb")){ + rv = runexportdb(argc, argv); + } else if(!strcmp(argv[1], "importdb")){ + rv = runimportdb(argc, argv); + } else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){ + printf("Powered by QDBM version %s on %s%s\n", + dpversion, dpsysname, dpisreentrant ? " (reentrant)" : ""); + printf("Copyright (c) 2000-2007 Mikio Hirabayashi\n"); + rv = 0; + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: administration utility for Villa\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s create [-cz|-cy|-cx] name\n", progname); + fprintf(stderr, " %s put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat|-dup] name key val\n", progname); + fprintf(stderr, " %s out [-l] [-kx|-ki] name key\n", progname); + fprintf(stderr, " %s get [-nl] [-l] [-kx|-ki] [-ox] [-n] name key\n", progname); + fprintf(stderr, " %s list [-nl] [-k|-v] [-kx|-ki] [-ox] [-top key] [-bot key] [-gt] [-lt]" + " [-max num] [-desc] name\n", progname); + fprintf(stderr, " %s optimize name\n", progname); + fprintf(stderr, " %s inform [-nl] name\n", progname); + fprintf(stderr, " %s remove name\n", progname); + fprintf(stderr, " %s repair [-ki] name\n", progname); + fprintf(stderr, " %s exportdb [-ki] name file\n", progname); + fprintf(stderr, " %s importdb [-ki] name file\n", progname); + fprintf(stderr, " %s version\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* create a binary object from a hexadecimal string */ +char *hextoobj(const char *str, int *sp){ + char *buf, mbuf[3]; + int len, i, j; + len = strlen(str); + if(!(buf = malloc(len + 1))) return NULL; + j = 0; + for(i = 0; i < len; i += 2){ + while(strchr(" \n\r\t\f\v", str[i])){ + i++; + } + if((mbuf[0] = str[i]) == '\0') break; + if((mbuf[1] = str[i+1]) == '\0') break; + mbuf[2] = '\0'; + buf[j++] = (char)strtol(mbuf, NULL, 16); + } + buf[j] = '\0'; + *sp = j; + return buf; +} + + +/* create a integer object from a decimal string */ +char *dectoiobj(const char *str, int *sp){ + char *buf; + int num; + num = atoi(str); + if(!(buf = malloc(sizeof(int)))) return NULL; + *(int *)buf = num; + *sp = sizeof(int); + return buf; +} + + +/* parse arguments of create command */ +int runcreate(int argc, char **argv){ + char *name; + int i, cmode, rv; + name = NULL; + cmode = 0; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-cz")){ + cmode |= VL_OZCOMP; + } else if(!strcmp(argv[i], "-cy")){ + cmode |= VL_OYCOMP; + } else if(!strcmp(argv[i], "-cx")){ + cmode |= VL_OXCOMP; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = docreate(name, cmode); + return rv; +} + + +/* parse arguments of put command */ +int runput(int argc, char **argv){ + char *name, *key, *val, *kbuf, *vbuf; + int i, kx, ki, vx, vi, vf, ksiz, vsiz, rv; + int dmode; + name = NULL; + kx = FALSE; + ki = FALSE; + vx = FALSE; + vi = FALSE; + vf = FALSE; + key = NULL; + val = NULL; + dmode = VL_DOVER; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else if(!strcmp(argv[i], "-vx")){ + vx = TRUE; + } else if(!strcmp(argv[i], "-vi")){ + vi = TRUE; + } else if(!strcmp(argv[i], "-vf")){ + vf = TRUE; + } else if(!strcmp(argv[i], "-keep")){ + dmode = VL_DKEEP; + } else if(!strcmp(argv[i], "-cat")){ + dmode = VL_DCAT; + } else if(!strcmp(argv[i], "-dup")){ + dmode = VL_DDUP; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else if(!val){ + val = argv[i]; + } else { + usage(); + } + } + if(!name || !key || !val) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(vx){ + vbuf = hextoobj(val, &vsiz); + } else if(vi){ + vbuf = dectoiobj(val, &vsiz); + } else if(vf){ + vbuf = cbreadfile(val, &vsiz); + } else { + vbuf = cbmemdup(val, -1); + vsiz = -1; + } + if(kbuf && vbuf){ + rv = doput(name, kbuf, ksiz, vbuf, vsiz, dmode, ki ? VL_CMPINT : VL_CMPLEX); + } else { + if(vf){ + fprintf(stderr, "%s: %s: cannot read\n", progname, val); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + } + rv = 1; + } + free(kbuf); + free(vbuf); + return rv; +} + + +/* parse arguments of out command */ +int runout(int argc, char **argv){ + char *name, *key, *kbuf; + int i, kx, ki, lb, ksiz, rv; + name = NULL; + kx = FALSE; + ki = FALSE; + lb = FALSE; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-l")){ + lb = TRUE; + } else if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(kbuf){ + rv = doout(name, kbuf, ksiz, ki ? VL_CMPINT : VL_CMPLEX, lb); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* parse arguments of get command */ +int runget(int argc, char **argv){ + char *name, *key, *kbuf; + int i, opts, lb, kx, ki, ox, nb, ksiz, rv; + name = NULL; + opts = 0; + lb = FALSE; + kx = FALSE; + ki = FALSE; + ox = FALSE; + nb = FALSE; + key = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-nl")){ + opts |= VL_ONOLCK; + } else if(!strcmp(argv[i], "-l")){ + lb = TRUE; + } else if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else if(!strcmp(argv[i], "-n")){ + nb = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!key){ + key = argv[i]; + } else { + usage(); + } + } + if(!name || !key) usage(); + if(kx){ + kbuf = hextoobj(key, &ksiz); + } else if(ki){ + kbuf = dectoiobj(key, &ksiz); + } else { + kbuf = cbmemdup(key, -1); + ksiz = -1; + } + if(kbuf){ + rv = doget(name, opts, kbuf, ksiz, ki ? VL_CMPINT : VL_CMPLEX, lb, ox, nb); + } else { + fprintf(stderr, "%s: out of memory\n", progname); + rv = 1; + } + free(kbuf); + return rv; +} + + +/* parse arguments of list command */ +int runlist(int argc, char **argv){ + char *name, *top, *bot, *tbuf, *bbuf, *nstr; + int i, opts, kb, vb, kx, ki, ox, gt, lt, max, desc, tsiz, bsiz, rv; + name = NULL; + opts = 0; + kb = FALSE; + vb = FALSE; + kx = FALSE; + ki = FALSE; + ox = FALSE; + gt = FALSE; + lt = FALSE; + max = -1; + desc = FALSE; + top = NULL; + bot = NULL; + nstr = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-nl")){ + opts |= VL_ONOLCK; + } else if(!strcmp(argv[i], "-k")){ + kb = TRUE; + } else if(!strcmp(argv[i], "-v")){ + vb = TRUE; + } else if(!strcmp(argv[i], "-kx")){ + kx = TRUE; + } else if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else if(!strcmp(argv[i], "-ox")){ + ox = TRUE; + } else if(!strcmp(argv[i], "-top")){ + if(++i >= argc) usage(); + top = argv[i]; + } else if(!strcmp(argv[i], "-bot")){ + if(++i >= argc) usage(); + bot = argv[i]; + } else if(!strcmp(argv[i], "-gt")){ + gt = TRUE; + } else if(!strcmp(argv[i], "-lt")){ + lt = TRUE; + } else if(!strcmp(argv[i], "-max")){ + if(++i >= argc) usage(); + max = atoi(argv[i]); + } else if(!strcmp(argv[i], "-desc")){ + desc = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + tbuf = NULL; + bbuf = NULL; + if(kx){ + if(top) tbuf = hextoobj(top, &tsiz); + if(bot) bbuf = hextoobj(bot, &bsiz); + } else if(ki){ + if(top) tbuf = dectoiobj(top, &tsiz); + if(bot) bbuf = dectoiobj(bot, &bsiz); + } else { + if(top){ + tbuf = cbmemdup(top, -1); + tsiz = strlen(tbuf); + } + if(bot){ + bbuf = cbmemdup(bot, -1); + bsiz = strlen(bbuf); + } + } + rv = dolist(name, opts, tbuf, tsiz, bbuf, bsiz, ki ? VL_CMPINT : VL_CMPLEX, ki, + kb, vb, ox, gt, lt, max, desc); + free(tbuf); + free(bbuf); + return rv; +} + + +/* parse arguments of optimize command */ +int runoptimize(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dooptimize(name); + return rv; +} + + +/* parse arguments of inform command */ +int runinform(int argc, char **argv){ + char *name; + int i, opts, rv; + name = NULL; + opts = 0; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-nl")){ + opts |= VL_ONOLCK; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doinform(name, opts); + return rv; +} + + +/* parse arguments of remove command */ +int runremove(int argc, char **argv){ + char *name; + int i, rv; + name = NULL; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + usage(); + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doremove(name); + return rv; +} + + +/* parse arguments of repair command */ +int runrepair(int argc, char **argv){ + char *name; + int i, ki, rv; + name = NULL; + ki = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = dorepair(name, ki ? VL_CMPINT : VL_CMPLEX); + return rv; +} + + +/* parse arguments of exportdb command */ +int runexportdb(int argc, char **argv){ + char *name, *file; + int i, ki, rv; + name = NULL; + file = NULL; + ki = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + if(!name || !file) usage(); + rv = doexportdb(name, file, ki ? VL_CMPINT : VL_CMPLEX); + return rv; +} + + +/* parse arguments of importdb command */ +int runimportdb(int argc, char **argv){ + char *name, *file; + int i, ki, rv; + name = NULL; + file = NULL; + ki = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-ki")){ + ki = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!file){ + file = argv[i]; + } else { + usage(); + } + } + if(!name || !file) usage(); + rv = doimportdb(name, file, ki ? VL_CMPINT : VL_CMPLEX); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* print an object */ +void printobj(const char *obj, int size){ + int i; + for(i = 0; i < size; i++){ + putchar(obj[i]); + } +} + + +/* print an object as a hexadecimal string */ +void printobjhex(const char *obj, int size){ + int i; + for(i = 0; i < size; i++){ + printf("%s%02X", i > 0 ? " " : "", ((const unsigned char *)obj)[i]); + } +} + + +/* perform create command */ +int docreate(const char *name, int cmode){ + VILLA *villa; + int omode; + omode = VL_OWRITER | VL_OCREAT | VL_OTRUNC | cmode; + if(!(villa = vlopen(name, omode, VL_CMPLEX))){ + pdperror(name); + return 1; + } + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform put command */ +int doput(const char *name, const char *kbuf, int ksiz, const char *vbuf, int vsiz, + int dmode, VLCFUNC cmp){ + VILLA *villa; + if(!(villa = vlopen(name, VL_OWRITER, cmp))){ + pdperror(name); + return 1; + } + if(!vlput(villa, kbuf, ksiz, vbuf, vsiz, dmode)){ + pdperror(name); + vlclose(villa); + return 1; + } + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform out command */ +int doout(const char *name, const char *kbuf, int ksiz, VLCFUNC cmp, int lb){ + VILLA *villa; + if(!(villa = vlopen(name, VL_OWRITER, cmp))){ + pdperror(name); + return 1; + } + if(lb){ + if(!vloutlist(villa, kbuf, ksiz)){ + pdperror(name); + vlclose(villa); + return 1; + } + } else { + if(!vlout(villa, kbuf, ksiz)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform get command */ +int doget(const char *name, int opts, const char *kbuf, int ksiz, VLCFUNC cmp, + int lb, int ox, int nb){ + VILLA *villa; + CBLIST *vals; + char *vbuf; + int vsiz; + if(!(villa = vlopen(name, VL_OREADER | opts, cmp))){ + pdperror(name); + return 1; + } + if(lb){ + if(!(vals = vlgetlist(villa, kbuf, ksiz))){ + pdperror(name); + vlclose(villa); + return 1; + } + while((vbuf = cblistshift(vals, &vsiz)) != NULL){ + if(ox){ + printobjhex(vbuf, vsiz); + } else { + printobj(vbuf, vsiz); + } + free(vbuf); + putchar('\n'); + } + cblistclose(vals); + } else { + if(!(vbuf = vlget(villa, kbuf, ksiz, &vsiz))){ + pdperror(name); + vlclose(villa); + return 1; + } + if(ox){ + printobjhex(vbuf, vsiz); + } else { + printobj(vbuf, vsiz); + } + free(vbuf); + if(!nb) putchar('\n'); + } + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform list command */ +int dolist(const char *name, int opts, const char *tbuf, int tsiz, const char *bbuf, int bsiz, + VLCFUNC cmp, int ki, int kb, int vb, int ox, int gt, int lt, int max, int desc){ + VILLA *villa; + char *kbuf, *vbuf; + int ksiz, vsiz, show, rv; + if(!(villa = vlopen(name, VL_OREADER | opts, cmp))){ + pdperror(name); + return 1; + } + if(max < 0) max = vlrnum(villa); + if(desc){ + if(bbuf){ + vlcurjump(villa, bbuf, bsiz, VL_JBACKWARD); + } else { + vlcurlast(villa); + } + show = 0; + while(show < max && (kbuf = vlcurkey(villa, &ksiz)) != NULL){ + if(bbuf && lt){ + if(cmp(kbuf, ksiz, bbuf, bsiz) == 0){ + free(kbuf); + vlcurnext(villa); + continue; + } + lt = FALSE; + } + if(tbuf){ + rv = cmp(kbuf, ksiz, tbuf, tsiz); + if(rv < 0 || (gt && rv == 0)){ + free(kbuf); + break; + } + } + if(!(vbuf = vlcurval(villa, &vsiz))){ + free(kbuf); + break; + } + if(ox){ + if(!vb) printobjhex(kbuf, ksiz); + if(!kb && !vb) putchar('\t'); + if(!kb) printobjhex(vbuf, vsiz); + } else { + if(!vb) printobj(kbuf, ksiz); + if(!kb && !vb) putchar('\t'); + if(!kb) printobj(vbuf, vsiz); + } + putchar('\n'); + free(kbuf); + free(vbuf); + show++; + vlcurprev(villa); + } + } else { + if(tbuf){ + vlcurjump(villa, tbuf, tsiz, VL_JFORWARD); + } else { + vlcurfirst(villa); + } + show = 0; + while(show < max && (kbuf = vlcurkey(villa, &ksiz)) != NULL){ + if(tbuf && gt){ + if(cmp(kbuf, ksiz, tbuf, tsiz) == 0){ + free(kbuf); + vlcurnext(villa); + continue; + } + gt = FALSE; + } + if(bbuf){ + rv = cmp(kbuf, ksiz, bbuf, bsiz); + if(rv > 0 || (lt && rv == 0)){ + free(kbuf); + break; + } + } + if(!(vbuf = vlcurval(villa, &vsiz))){ + free(kbuf); + break; + } + if(ox){ + if(!vb) printobjhex(kbuf, ksiz); + if(!kb && !vb) putchar('\t'); + if(!kb) printobjhex(vbuf, vsiz); + } else { + if(!vb) printobj(kbuf, ksiz); + if(!kb && !vb) putchar('\t'); + if(!kb) printobj(vbuf, vsiz); + } + putchar('\n'); + free(kbuf); + free(vbuf); + show++; + vlcurnext(villa); + } + } + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform optimize command */ +int dooptimize(const char *name){ + VILLA *villa; + if(!(villa = vlopen(name, VL_OWRITER, VL_CMPLEX))){ + pdperror(name); + return 1; + } + if(!vloptimize(villa)){ + pdperror(name); + vlclose(villa); + return 1; + } + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform inform command */ +int doinform(const char *name, int opts){ + VILLA *villa; + char *tmp; + if(!(villa = vlopen(name, VL_OREADER | opts, VL_CMPLEX))){ + pdperror(name); + return 1; + } + tmp = vlname(villa); + printf("name: %s\n", tmp ? tmp : "(null)"); + free(tmp); + printf("file size: %d\n", vlfsiz(villa)); + printf("leaf nodes: %d\n", vllnum(villa)); + printf("non-leaf nodes: %d\n", vlnnum(villa)); + printf("records: %d\n", vlrnum(villa)); + printf("inode number: %d\n", vlinode(villa)); + printf("modified time: %.0f\n", (double)vlmtime(villa)); + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform remove command */ +int doremove(const char *name){ + if(!vlremove(name)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform repair command */ +int dorepair(const char *name, VLCFUNC cmp){ + if(!vlrepair(name, cmp)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform exportdb command */ +int doexportdb(const char *name, const char *file, VLCFUNC cmp){ + VILLA *villa; + if(!(villa = vlopen(name, VL_OREADER, cmp))){ + pdperror(name); + return 1; + } + if(!vlexportdb(villa, file)){ + pdperror(name); + vlclose(villa); + return 1; + } + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return 0; +} + + +/* perform importdb command */ +int doimportdb(const char *name, const char *file, VLCFUNC cmp){ + VILLA *villa; + if(!(villa = vlopen(name, VL_OWRITER | VL_OCREAT | VL_OTRUNC, cmp))){ + pdperror(name); + return 1; + } + if(!vlimportdb(villa, file)){ + pdperror(name); + vlclose(villa); + return 1; + } + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/vltest.c b/qdbm/vltest.c new file mode 100644 index 00000000..97f64e48 --- /dev/null +++ b/qdbm/vltest.c @@ -0,0 +1,1507 @@ +/************************************************************************************************* + * Test cases of Villa + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + +#define RECBUFSIZ 32 /* buffer for records */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +int runwrite(int argc, char **argv); +int runread(int argc, char **argv); +int runrdup(int argc, char **argv); +int runcombo(int argc, char **argv); +int runwicked(int argc, char **argv); +int printfflush(const char *format, ...); +void pdperror(const char *name); +int myrand(void); +int dowrite(const char *name, int rnum, int ii, int cmode, + int lrecmax, int nidxmax, int lcnum, int ncnum, int fbp); +int doread(const char *name, int ii, int vc); +int dordup(const char *name, int rnum, int pnum, int ii, int cmode, int cc, + int lrecmax, int nidxmax, int lcnum, int ncnum, int fbp); +int docombo(const char *name, int cmode); +int dowicked(const char *name, int rnum, int cb, int cmode); + + +/* main routine */ +int main(int argc, char **argv){ + char *env; + int rv; + cbstdiobin(); + if((env = getenv("QDBMDBGFD")) != NULL) dpdbgfd = atoi(env); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "write")){ + rv = runwrite(argc, argv); + } else if(!strcmp(argv[1], "read")){ + rv = runread(argc, argv); + } else if(!strcmp(argv[1], "rdup")){ + rv = runrdup(argc, argv); + } else if(!strcmp(argv[1], "combo")){ + rv = runcombo(argc, argv); + } else if(!strcmp(argv[1], "wicked")){ + rv = runwicked(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: test cases for Villa\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s write [-int] [-cz|-cy|-cx] [-tune lrecmax nidxmax lcnum ncnum]" + " [-fbp num] name rnum\n", progname); + fprintf(stderr, " %s read [-int] [-vc] name\n", progname); + fprintf(stderr, " %s rdup [-int] [-cz|-cy|-cx] [-cc] [-tune lrecmax nidxmax lcnum ncnum]" + " [-fbp num] name rnum pnum\n", progname); + fprintf(stderr, " %s combo [-cz|-cy|-cx] name\n", progname); + fprintf(stderr, " %s wicked [-c] [-cz|-cy|-cx] name rnum\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of write command */ +int runwrite(int argc, char **argv){ + char *name, *rstr; + int i, rnum, ii, cmode, lrecmax, nidxmax, lcnum, ncnum, fbp, rv; + name = NULL; + rstr = NULL; + rnum = 0; + ii = FALSE; + cmode = 0; + lrecmax = -1; + nidxmax = -1; + lcnum = -1; + ncnum = -1; + fbp = -1; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-int")){ + ii = TRUE; + } else if(!strcmp(argv[i], "-cz")){ + cmode |= VL_OZCOMP; + } else if(!strcmp(argv[i], "-cy")){ + cmode |= VL_OYCOMP; + } else if(!strcmp(argv[i], "-cx")){ + cmode |= VL_OXCOMP; + } else if(!strcmp(argv[i], "-tune")){ + if(++i >= argc) usage(); + lrecmax = atoi(argv[i]); + if(++i >= argc) usage(); + nidxmax = atoi(argv[i]); + if(++i >= argc) usage(); + lcnum = atoi(argv[i]); + if(++i >= argc) usage(); + ncnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-fbp")){ + if(++i >= argc) usage(); + fbp = atoi(argv[i]); + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = dowrite(name, rnum, ii, cmode, lrecmax, nidxmax, lcnum, ncnum, fbp); + return rv; +} + + +/* parse arguments of read command */ +int runread(int argc, char **argv){ + char *name; + int i, ii, vc, rv; + name = NULL; + ii = FALSE; + vc = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-int")){ + ii = TRUE; + } else if(!strcmp(argv[i], "-vc")){ + vc = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doread(name, ii, vc); + return rv; +} + + +/* parse arguments of rdup command */ +int runrdup(int argc, char **argv){ + char *name, *rstr, *pstr; + int i, rnum, pnum, ii, cmode, cc, lrecmax, nidxmax, lcnum, ncnum, fbp, rv; + name = NULL; + rstr = NULL; + pstr = NULL; + rnum = 0; + pnum = 0; + ii = FALSE; + cmode = 0; + cc = FALSE; + lrecmax = -1; + nidxmax = -1; + lcnum = -1; + ncnum = -1; + fbp = -1; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-int")){ + ii = TRUE; + } else if(!strcmp(argv[i], "-cz")){ + cmode |= VL_OZCOMP; + } else if(!strcmp(argv[i], "-cy")){ + cmode |= VL_OYCOMP; + } else if(!strcmp(argv[i], "-cx")){ + cmode |= VL_OXCOMP; + } else if(!strcmp(argv[i], "-cc")){ + cc = TRUE; + } else if(!strcmp(argv[i], "-tune")){ + if(++i >= argc) usage(); + lrecmax = atoi(argv[i]); + if(++i >= argc) usage(); + nidxmax = atoi(argv[i]); + if(++i >= argc) usage(); + lcnum = atoi(argv[i]); + if(++i >= argc) usage(); + ncnum = atoi(argv[i]); + } else if(!strcmp(argv[i], "-fbp")){ + if(++i >= argc) usage(); + fbp = atoi(argv[i]); + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else if(!pstr){ + pstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr || !pstr) usage(); + rnum = atoi(rstr); + pnum = atoi(pstr); + if(rnum < 1 || pnum < 1) usage(); + rv = dordup(name, rnum, pnum, ii, cmode, cc, lrecmax, nidxmax, lcnum, ncnum, fbp); + return rv; +} + + +/* parse arguments of combo command */ +int runcombo(int argc, char **argv){ + char *name; + int i, cmode, rv; + name = NULL; + cmode = 0; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-cz")){ + cmode |= VL_OZCOMP; + } else if(!strcmp(argv[i], "-cy")){ + cmode |= VL_OYCOMP; + } else if(!strcmp(argv[i], "-cx")){ + cmode |= VL_OXCOMP; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = docombo(name, cmode); + return rv; +} + + +/* parse arguments of wicked command */ +int runwicked(int argc, char **argv){ + char *name, *rstr; + int i, cb, cmode, rnum, rv; + name = NULL; + rstr = NULL; + cb = FALSE; + cmode = 0; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-c")){ + cb = TRUE; + } else if(!strcmp(argv[i], "-cz")){ + cmode |= VL_OZCOMP; + } else if(!strcmp(argv[i], "-cy")){ + cmode |= VL_OYCOMP; + } else if(!strcmp(argv[i], "-cx")){ + cmode |= VL_OXCOMP; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else if(!rstr){ + rstr = argv[i]; + } else { + usage(); + } + } + if(!name || !rstr) usage(); + rnum = atoi(rstr); + if(rnum < 1) usage(); + rv = dowicked(name, rnum, cb, cmode); + return rv; +} + + +/* print formatted string and flush the buffer */ +int printfflush(const char *format, ...){ + va_list ap; + int rv; + va_start(ap, format); + rv = vprintf(format, ap); + if(fflush(stdout) == EOF) rv = -1; + va_end(ap); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* pseudo random number generator */ +int myrand(void){ + static int cnt = 0; + if(cnt == 0) srand(time(NULL)); + return (rand() * rand() + (rand() >> (sizeof(int) * 4)) + (cnt++)) & INT_MAX; +} + + +/* perform write command */ +int dowrite(const char *name, int rnum, int ii, int cmode, + int lrecmax, int nidxmax, int lcnum, int ncnum, int fbp){ + VILLA *villa; + int i, omode, err, len; + char buf[RECBUFSIZ]; + printfflush("\n name=%s rnum=%d int=%d cmode=%d " + "lrecmax=%d nidxmax=%d lcnum=%d ncnum=%d fbp=%d\n\n", + name, rnum, ii, cmode, lrecmax, nidxmax, lcnum, ncnum, fbp); + /* open a database */ + omode = VL_OWRITER | VL_OCREAT | VL_OTRUNC | cmode; + if(!(villa = vlopen(name, omode, ii ? VL_CMPINT : VL_CMPLEX))){ + pdperror(name); + return 1; + } + err = FALSE; + /* set tuning parameters */ + if(lrecmax > 0) vlsettuning(villa, lrecmax, nidxmax, lcnum, ncnum); + if(fbp >= 0) vlsetfbpsiz(villa, fbp); + /* loop for each record */ + for(i = 1; i <= rnum; i++){ + /* store a record */ + if(ii){ + if(!vlput(villa, (char *)&i, sizeof(int), (char *)&i, sizeof(int), VL_DOVER)){ + pdperror(name); + err = TRUE; + break; + } + } else { + len = sprintf(buf, "%08d", i); + if(!vlput(villa, buf, len, buf, len, VL_DOVER)){ + pdperror(name); + err = TRUE; + break; + } + } + /* print progression */ + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return 0; +} + + +/* perform read command */ +int doread(const char *name, int ii, int vc){ + VILLA *villa; + int i, rnum, err, len; + const char *cval; + char buf[RECBUFSIZ], *val; + printfflush("\n name=%s int=%d\n\n", name, ii); + /* open a database */ + if(!(villa = vlopen(name, VL_OREADER, ii ? VL_CMPINT : VL_CMPLEX))){ + pdperror(name); + return 1; + } + /* get the number of records */ + rnum = vlrnum(villa); + err = FALSE; + /* loop for each record */ + for(i = 1; i <= rnum; i++){ + /* retrieve a record */ + if(ii){ + if(vc){ + if(!(cval = vlgetcache(villa, (char *)&i, sizeof(int), NULL))){ + pdperror(name); + err = TRUE; + break; + } + } else { + if(!(val = vlget(villa, (char *)&i, sizeof(int), NULL))){ + pdperror(name); + err = TRUE; + break; + } + free(val); + } + } else { + len = sprintf(buf, "%08d", i); + if(vc){ + if(!(cval = vlgetcache(villa, buf, len, NULL))){ + pdperror(name); + err = TRUE; + break; + } + } else { + if(!(val = vlget(villa, buf, len, NULL))){ + pdperror(name); + err = TRUE; + break; + } + free(val); + } + } + /* print progression */ + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d)\n", i); + } + } + } + /* close the database */ + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return 0; +} + + +/* perform rdup command */ +int dordup(const char *name, int rnum, int pnum, int ii, int cmode, int cc, + int lrecmax, int nidxmax, int lcnum, int ncnum, int fbp){ + VILLA *villa; + int i, omode, err, dmode, vi, len; + char buf[RECBUFSIZ]; + printfflush("\n name=%s rnum=%d int=%d cmode=%d " + "lrecmax=%d nidxmax=%d lcnum=%d ncnum=%d fbp=%d\n\n", + name, rnum, ii, cmode, lrecmax, nidxmax, lcnum, ncnum, fbp); + omode = VL_OWRITER | VL_OCREAT | VL_OTRUNC | cmode; + if(!(villa = vlopen(name, omode, ii ? VL_CMPINT : VL_CMPLEX))){ + pdperror(name); + return 1; + } + err = FALSE; + if(lrecmax > 0) vlsettuning(villa, lrecmax, nidxmax, lcnum, ncnum); + if(fbp >= 0) vlsetfbpsiz(villa, fbp); + for(i = 1; i <= rnum; i++){ + dmode = i % 3 == 0 ? VL_DDUPR : VL_DDUP; + if(cc && myrand() % 2 == 0) dmode = VL_DCAT; + vi = myrand() % pnum + 1; + if(ii){ + if(!vlput(villa, (char *)&vi, sizeof(int), (char *)&vi, sizeof(int), dmode)){ + pdperror(name); + err = TRUE; + break; + } + } else { + len = sprintf(buf, "%08d", vi); + if(!vlput(villa, buf, len, buf, len, dmode)){ + pdperror(name); + err = TRUE; + break; + } + } + if(rnum > 250 && i % (rnum / 250) == 0){ + putchar('.'); + fflush(stdout); + if(i == rnum || i % (rnum / 10) == 0){ + printfflush(" (%08d: fsiz=%d lnum=%d nnum=%d)\n", + i, vlfsiz(villa), vllnum(villa), vlnnum(villa)); + } + } + } + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return 0; +} + + +/* perform combo command */ +int docombo(const char *name, int cmode){ + VILLA *villa; + VLMULCUR **mulcurs; + char buf[RECBUFSIZ], *vbuf, *kbuf; + int i, j, omode, len, vsiz, ksiz, fsiz, lnum, nnum, rnum; + CBLIST *alist, *dlist; + const char *ap, *dp; + printfflush("\n name=%s cmode=%d\n\n", name, cmode); + printfflush("Creating a database with VL_CMPLEX ... "); + omode = VL_OWRITER | VL_OCREAT | VL_OTRUNC | cmode; + if(!(villa = vlopen(name, omode, VL_CMPLEX))){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Setting tuning parameters with 3, 4, 16, 16 ... "); + vlsettuning(villa, 3, 4, 16, 16); + printfflush("ok\n"); + printfflush("Adding 100 records with VL_DOVER ... "); + for(i = 1; i <= 100; i++){ + len = sprintf(buf, "%08d", i); + if(!vlput(villa, buf, len, buf, len, VL_DOVER)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking records ... "); + for(i = 1; i <= 100; i++){ + len = sprintf(buf, "%08d", i); + if(!(vbuf = vlget(villa, buf, len, &vsiz))){ + pdperror(name); + vlclose(villa); + return 1; + } + free(vbuf); + if(vsiz != 8 || vlvsiz(villa, buf, len) != 8){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + vlclose(villa); + return 1; + } + if(vlvnum(villa, buf, len) != 1){ + fprintf(stderr, "%s: %s: invalid vnum\n", progname, name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Deleting x1 - x5 records ... "); + for(i = 1; i <= 100; i++){ + if(i % 10 < 1 || i % 10 > 5) continue; + len = sprintf(buf, "%08d", i); + if(!vlout(villa, buf, len)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Adding 100 records with VL_DOVER ... "); + for(i = 1; i <= 100; i++){ + len = sprintf(buf, "%08d", i); + if(!vlput(villa, buf, len, buf, len, VL_DOVER)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Deleting x1 - x5 records ... "); + for(i = 1; i <= 100; i++){ + if(i % 10 < 1 || i % 10 > 5) continue; + len = sprintf(buf, "%08d", i); + if(!vlout(villa, buf, len)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Checking number of records ... "); + if(vlrnum(villa) != 50){ + fprintf(stderr, "%s: %s: invalid rnum\n", progname, name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 100 records with VL_DDUP ... "); + for(i = 1; i <= 100; i++){ + len = sprintf(buf, "%08d", i); + if(!vlput(villa, buf, len, buf, len, VL_DDUP)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Deleting x6 - x0 records ... "); + for(i = 1; i <= 100; i++){ + if(i % 10 >= 1 && i % 10 <= 5) continue; + len = sprintf(buf, "%08d", i); + if(!vlout(villa, buf, len)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Optimizing the database ... "); + if(!vloptimize(villa)){ + pdperror(name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Checking number of records ... "); + if(vlrnum(villa) != 100){ + fprintf(stderr, "%s: %s: invalid rnum\n", progname, name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Checking records ... "); + for(i = 1; i <= 100; i++){ + len = sprintf(buf, "%08d", i); + if(!(vbuf = vlget(villa, buf, len, &vsiz))){ + pdperror(name); + vlclose(villa); + return 1; + } + free(vbuf); + if(vsiz != 8){ + fprintf(stderr, "%s: %s: invalid vsiz\n", progname, name); + vlclose(villa); + return 1; + } + if(vlvnum(villa, buf, len) != 1){ + fprintf(stderr, "%s: %s: invalid vnum\n", progname, name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Deleting x6 - x0 records ... "); + for(i = 1; i <= 100; i++){ + if(i % 10 >= 1 && i % 10 <= 5) continue; + len = sprintf(buf, "%08d", i); + if(!vlout(villa, buf, len)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Scanning with the cursor in ascending order ... "); + if(!vlcurfirst(villa)){ + pdperror(name); + vlclose(villa); + return 1; + } + i = 0; + do { + kbuf = NULL; + vbuf = NULL; + if(!(kbuf = vlcurkey(villa, &ksiz)) || !(vbuf = vlcurval(villa, &vsiz))){ + pdperror(name); + free(kbuf); + free(vbuf); + vlclose(villa); + return 1; + } + free(kbuf); + free(vbuf); + i++; + } while(vlcurnext(villa)); + if(i != 50){ + fprintf(stderr, "%s: %s: invalid cursor\n", progname, name); + vlclose(villa); + return 1; + } + if(dpecode != DP_ENOITEM){ + pdperror(name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Scanning with the cursor in decending order ... "); + if(!vlcurlast(villa)){ + pdperror(name); + vlclose(villa); + return 1; + } + i = 0; + do { + kbuf = NULL; + vbuf = NULL; + if(!(kbuf = vlcurkey(villa, &ksiz)) || !(vbuf = vlcurval(villa, &vsiz))){ + pdperror(name); + free(kbuf); + free(vbuf); + vlclose(villa); + return 1; + } + free(kbuf); + free(vbuf); + i++; + } while(vlcurprev(villa)); + if(i != 50){ + fprintf(stderr, "%s: %s: invalid cursor\n", progname, name); + vlclose(villa); + return 1; + } + if(dpecode != DP_ENOITEM){ + pdperror(name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 50 random records with VL_DDUPR ... "); + for(i = 0; i < 50; i++){ + len = sprintf(buf, "%08d", myrand() % 100 + 1); + if(!vlput(villa, buf, len, buf, len, VL_DDUPR)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Deleting 80 random records ... "); + i = 0; + while(i < 80){ + len = sprintf(buf, "%08d", myrand() % 100 + 1); + if(!vlout(villa, buf, len)){ + if(dpecode == DP_ENOITEM) continue; + pdperror(name); + vlclose(villa); + return 1; + } + i++; + } + printfflush("ok\n"); + alist = cblistopen(); + dlist = cblistopen(); + printfflush("Scanning with the cursor in ascending order ... "); + if(!vlcurfirst(villa)){ + pdperror(name); + vlclose(villa); + return 1; + } + i = 0; + do { + kbuf = NULL; + vbuf = NULL; + if(!(kbuf = vlcurkey(villa, &ksiz)) || !(vbuf = vlcurval(villa, &vsiz))){ + pdperror(name); + cblistclose(alist); + cblistclose(dlist); + free(kbuf); + free(vbuf); + vlclose(villa); + return 1; + } + cblistpush(alist, kbuf, ksiz); + free(kbuf); + free(vbuf); + i++; + } while(vlcurnext(villa)); + if(i != 20){ + fprintf(stderr, "%s: %s: invalid cursor\n", progname, name); + cblistclose(alist); + cblistclose(dlist); + vlclose(villa); + return 1; + } + if(dpecode != DP_ENOITEM){ + pdperror(name); + cblistclose(alist); + cblistclose(dlist); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Scanning with the cursor in decending order ... "); + if(!vlcurlast(villa)){ + pdperror(name); + cblistclose(alist); + cblistclose(dlist); + vlclose(villa); + return 1; + } + i = 0; + do { + kbuf = NULL; + vbuf = NULL; + if(!(kbuf = vlcurkey(villa, &ksiz)) || !(vbuf = vlcurval(villa, &vsiz))){ + pdperror(name); + free(kbuf); + free(vbuf); + cblistclose(alist); + cblistclose(dlist); + vlclose(villa); + return 1; + } + cblistunshift(dlist, kbuf, ksiz); + free(kbuf); + free(vbuf); + i++; + } while(vlcurprev(villa)); + if(i != 20){ + fprintf(stderr, "%s: %s: invalid cursor\n", progname, name); + cblistclose(alist); + cblistclose(dlist); + vlclose(villa); + return 1; + } + if(dpecode != DP_ENOITEM){ + pdperror(name); + cblistclose(alist); + cblistclose(dlist); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Matching result of ascending scan and desending scan ... "); + for(i = 0; i < cblistnum(alist); i++){ + ap = cblistval(alist, i, NULL); + dp = cblistval(dlist, i, NULL); + if(strcmp(ap, dp)){ + fprintf(stderr, "%s: %s: not match\n", progname, name); + cblistclose(alist); + cblistclose(dlist); + vlclose(villa); + return 1; + } + } + cblistsort(alist); + for(i = 0; i < cblistnum(alist); i++){ + ap = cblistval(alist, i, NULL); + dp = cblistval(dlist, i, NULL); + if(strcmp(ap, dp)){ + fprintf(stderr, "%s: %s: not match\n", progname, name); + cblistclose(alist); + cblistclose(dlist); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + cblistclose(alist); + cblistclose(dlist); + printfflush("Resetting tuning parameters with 41, 80, 32, 32 ... "); + vlsettuning(villa, 41, 80, 32, 32); + printfflush("ok\n"); + printfflush("Adding 1000 random records with VL_DDUP ... "); + for(i = 0; i < 1000; i++){ + len = sprintf(buf, "%08d", myrand() % 1000 + 1); + if(!vlput(villa, buf, len, buf, len, VL_DDUP)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Resetting tuning parameters with 8, 5, 16, 16 ... "); + vlsettuning(villa, 8, 5, 16, 16); + printfflush("ok\n"); + printfflush("Adding 1000 random records with VL_DDUP ... "); + for(i = 0; i < 1000; i++){ + len = sprintf(buf, "%08d", myrand() % 1000 + 1); + if(!vlput(villa, buf, len, buf, len, VL_DDUP)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Beginning the transaction ... "); + if(!vltranbegin(villa)){ + pdperror(name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 100 random records with VL_DDUP ... "); + for(i = 0; i < 100; i++){ + len = sprintf(buf, "%08d", myrand() % 1000 + 1); + if(!vlput(villa, buf, len, buf, len, VL_DDUP)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Scanning and checking ... "); + i = 0; + for(vlcurlast(villa); (kbuf = vlcurkey(villa, &ksiz)) != NULL; vlcurprev(villa)){ + if(vlvnum(villa, kbuf, ksiz) < 1 || !(vbuf = vlcurval(villa, NULL))){ + pdperror(name); + free(kbuf); + vlclose(villa); + return 1; + } + free(vbuf); + free(kbuf); + i++; + } + if(i != vlrnum(villa)){ + fprintf(stderr, "%s: %s: invalid\n", progname, name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Committing the transaction ... "); + if(!vltrancommit(villa)){ + pdperror(name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Scanning and checking ... "); + i = 0; + for(vlcurlast(villa); (kbuf = vlcurkey(villa, &ksiz)) != NULL; vlcurprev(villa)){ + if(vlvnum(villa, kbuf, ksiz) < 1 || !(vbuf = vlcurval(villa, NULL))){ + pdperror(name); + free(kbuf); + vlclose(villa); + return 1; + } + free(vbuf); + free(kbuf); + i++; + } + if(i != vlrnum(villa)){ + fprintf(stderr, "%s: %s: invalid\n", progname, name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + lnum = vllnum(villa); + nnum = vlnnum(villa); + rnum = vlrnum(villa); + fsiz = vlfsiz(villa); + printfflush("Beginning the transaction ... "); + if(!vltranbegin(villa)){ + pdperror(name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 100 random records with VL_DDUP ... "); + for(i = 0; i < 100; i++){ + len = sprintf(buf, "%08d", myrand() % 1000 + 1); + if(!vlput(villa, buf, len, buf, len, VL_DDUP)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Aborting the transaction ... "); + if(!vltranabort(villa)){ + pdperror(name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Checking rollback ... "); + if(vlfsiz(villa) != fsiz || vllnum(villa) != lnum || + vlnnum(villa) != nnum || vlrnum(villa) != rnum){ + fprintf(stderr, "%s: %s: invalid\n", progname, name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Scanning and checking ... "); + i = 0; + for(vlcurlast(villa); (kbuf = vlcurkey(villa, &ksiz)) != NULL; vlcurprev(villa)){ + if(vlvnum(villa, kbuf, ksiz) < 1 || !(vbuf = vlcurval(villa, NULL))){ + pdperror(name); + free(kbuf); + vlclose(villa); + return 1; + } + free(vbuf); + free(kbuf); + i++; + } + if(i != vlrnum(villa)){ + fprintf(stderr, "%s: %s: invalid\n", progname, name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Closing the database ... "); + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Creating a database with VL_CMPLEX ... "); + omode = VL_OWRITER | VL_OCREAT | VL_OTRUNC | cmode; + if(!(villa = vlopen(name, omode, VL_CMPLEX))){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Setting tuning parameters with 5, 6, 16, 16 ... "); + vlsettuning(villa, 5, 6, 16, 16); + printfflush("ok\n"); + printfflush("Adding 3 * 3 records with VL_DDUP ... "); + for(i = 0; i < 3; i++){ + for(j = 0; j < 3; j++){ + len = sprintf(buf, "%08d", j); + if(!vlput(villa, buf, len, buf, -1, VL_DDUP)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + } + printfflush("ok\n"); + printfflush("Inserting records with the cursor ... "); + if(!vlcurjump(villa, "00000001", -1, VL_JFORWARD) || + !vlcurput(villa, "first", -1, VL_CPAFTER) || !vlcurput(villa, "second", -1, VL_CPAFTER) || + !vlcurnext(villa) || + !vlcurput(villa, "third", -1, VL_CPAFTER) || + strcmp(vlcurvalcache(villa, NULL), "third") || + !vlcurput(villa, "fourth", -1, VL_CPCURRENT) || + strcmp(vlcurvalcache(villa, NULL), "fourth") || + !vlcurjump(villa, "00000001", -1, VL_JFORWARD) || + strcmp(vlcurvalcache(villa, NULL), "00000001") || + !vlcurput(villa, "one", -1, VL_CPBEFORE) || !vlcurput(villa, "two", -1, VL_CPBEFORE) || + !vlcurput(villa, "three", -1, VL_CPBEFORE) || !vlcurput(villa, "five", -1, VL_CPBEFORE) || + !vlcurnext(villa) || + !vlcurput(villa, "four", -1, VL_CPBEFORE) || + strcmp(vlcurvalcache(villa, NULL), "four") || + !vlcurjump(villa, "00000001*", -1, VL_JBACKWARD) || + strcmp(vlcurvalcache(villa, NULL), "00000001") || + !vlcurput(villa, "omega", -1, VL_CPAFTER) || + strcmp(vlcurkeycache(villa, NULL), "00000001") || + strcmp(vlcurvalcache(villa, NULL), "omega") || + !vlcurjump(villa, "00000000*", -1, VL_JFORWARD) || + !vlcurput(villa, "alpha", -1, VL_CPBEFORE) || + strcmp(vlcurvalcache(villa, NULL), "alpha") || + !vlcurprev(villa) || + strcmp(vlcurkeycache(villa, NULL), "00000000") || + strcmp(vlcurvalcache(villa, NULL), "00000000") || + !vlcurput(villa, "before", -1, VL_CPAFTER) || + strcmp(vlcurvalcache(villa, NULL), "before") || + !vlcurjump(villa, "00000001*", -1, VL_JFORWARD) || + !vlcurput(villa, "after", -1, VL_CPBEFORE) || + strcmp(vlcurvalcache(villa, NULL), "after") || + !vlcurfirst(villa) || + strcmp(vlcurvalcache(villa, NULL), "00000000") || + !vlcurput(villa, "top", -1, VL_CPBEFORE) || + strcmp(vlcurvalcache(villa, NULL), "top") || + !vlcurlast(villa) || + !vlcurput(villa, "bottom", -1, VL_CPAFTER) || + strcmp(vlcurvalcache(villa, NULL), "bottom")){ + fprintf(stderr, "%s: %s: invalid\n", progname, name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Deleting records with the cursor ... "); + if(!vlcurjump(villa, "00000000*", -1, VL_JBACKWARD) || + strcmp(vlcurvalcache(villa, NULL), "before") || + !vlcurout(villa) || + strcmp(vlcurvalcache(villa, NULL), "alpha") || + !vlcurout(villa) || + strcmp(vlcurvalcache(villa, NULL), "five") || + !vlcurfirst(villa) || !vlcurnext(villa) || + !vlcurout(villa) || !vlcurout(villa) || !vlcurout(villa) || + strcmp(vlcurvalcache(villa, NULL), "five") || + !vlcurprev(villa) || + strcmp(vlcurvalcache(villa, NULL), "top") || + !vlcurout(villa) || + strcmp(vlcurvalcache(villa, NULL), "five") || + !vlcurjump(villa, "00000002", -1, VL_JBACKWARD) || + strcmp(vlcurvalcache(villa, NULL), "bottom") || + !vlcurout(villa) || + !vlcurjump(villa, "00000001", -1, VL_JBACKWARD) || + !vlcurout(villa) || + !vlcurout(villa) || !vlcurout(villa) || !vlcurout(villa) || + strcmp(vlcurkeycache(villa, NULL), "00000002") || + strcmp(vlcurvalcache(villa, NULL), "00000002") || + !vlcurout(villa) || vlcurout(villa) || + !vlcurfirst(villa) || + strcmp(vlcurvalcache(villa, NULL), "five")){ + fprintf(stderr, "%s: %s: invalid\n", progname, name); + vlclose(villa); + return 1; + } + vlcurfirst(villa); + while(vlcurout(villa)){ + free(vlcurval(villa, NULL)); + } + if(vlrnum(villa) != 0){ + printf("%d\n", vlrnum(villa)); + fprintf(stderr, "%s: %s: invalid\n", progname, name); + vlclose(villa); + return 1; + } + for(i = 0; i < 1000; i++){ + len = sprintf(buf, "%08d", i); + if(!vlput(villa, buf, len, buf, -1, VL_DKEEP)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + for(i = 200; i < 800; i++){ + len = sprintf(buf, "%08d", i); + if(!vlout(villa, buf, len)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + vlcurfirst(villa); + while(vlcurout(villa)){ + free(vlcurval(villa, NULL)); + } + if(vlrnum(villa) != 0){ + printf("%d\n", vlrnum(villa)); + fprintf(stderr, "%s: %s: invalid\n", progname, name); + vlclose(villa); + return 1; + } + printfflush("ok\n"); + printfflush("Adding 3 * 100 records with VL_DDUP ... "); + for(i = 1; i <= 100; i++){ + len = sprintf(buf, "%08d", i); + for(j = 0; j < 3; j++){ + if(!vlput(villa, buf, len, buf, len, VL_DDUP)){ + pdperror(name); + vlclose(villa); + return 1; + } + } + } + printfflush("ok\n"); + printfflush("Closing the database ... "); + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Opening the database as a reader ... "); + if(!(villa = vlopen(name, VL_OREADER, VL_CMPLEX))){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("Opening multiple cursors ... "); + mulcurs = cbmalloc(sizeof(VLMULCUR *) * 8); + for(i = 0; i < 8; i++){ + if(!(mulcurs[i] = vlmulcuropen(villa))){ + pdperror(name); + vlclose(villa); + return 1; + } + } + printfflush("ok\n"); + printfflush("Scanning multiple cursors ... "); + for(i = 0; i < 8; i++){ + if(i % 2 == 0){ + vlmulcurfirst(mulcurs[i]); + } else { + vlmulcurlast(mulcurs[i]); + } + } + for(i = 0; i < 300; i++){ + for(j = 0; j < 8; j++){ + if(j % 2 == 0){ + if(!(vbuf = vlmulcurkey(mulcurs[j], &vsiz))){ + pdperror(name); + vlclose(villa); + return 1; + } + free(vbuf); + vlmulcurnext(mulcurs[j]); + } else { + if(!(vbuf = vlmulcurval(mulcurs[j], &vsiz))){ + pdperror(name); + vlclose(villa); + return 1; + } + free(vbuf); + vlmulcurprev(mulcurs[j]); + } + } + } + printfflush("ok\n"); + printfflush("Closing multiple cursors ... "); + for(i = 0; i < 8; i++){ + vlmulcurclose(mulcurs[i]); + } + free(mulcurs); + printfflush("ok\n"); + printfflush("Closing the database ... "); + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + printfflush("ok\n"); + printfflush("all ok\n\n"); + return 0; +} + + +/* perform wicked command */ +int dowicked(const char *name, int rnum, int cb, int cmode){ + VILLA *villa; + CBMAP *map; + int i, j, omode, len, err, ksiz, vsiz, tran, mksiz, mvsiz, rsiz; + const char *mkbuf, *mvbuf; + char buf[32], *kbuf, *vbuf; + CBLIST *list; + printfflush("\n name=%s rnum=%d\n\n", name, rnum); + omode = VL_OWRITER | VL_OCREAT | VL_OTRUNC | cmode; + if(!(villa = vlopen(name, omode, VL_CMPLEX))){ + pdperror(name); + return 1; + } + err = FALSE; + tran = FALSE; + vlsettuning(villa, 5, 10, 64, 64); + map = NULL; + if(cb) map = cbmapopen(); + for(i = 1; i <= rnum; i++){ + len = sprintf(buf, "%08d", myrand() % rnum + 1); + switch(cb ? (myrand() % 5) : myrand() % 16){ + case 0: + putchar('O'); + if(!vlput(villa, buf, len, buf, len, VL_DOVER)) err = TRUE; + if(map) cbmapput(map, buf, len, buf, len, TRUE); + break; + case 1: + putchar('K'); + if(!vlput(villa, buf, len, buf, len, VL_DKEEP) && dpecode != DP_EKEEP) err = TRUE; + if(map) cbmapput(map, buf, len, buf, len, FALSE); + break; + case 2: + putchar('C'); + if(!vlput(villa, buf, len, buf, len, VL_DCAT)) err = TRUE; + if(map) cbmapputcat(map, buf, len, buf, len); + break; + case 3: + putchar('D'); + if(!vlout(villa, buf, len) && dpecode != DP_ENOITEM) err = TRUE; + if(map) cbmapout(map, buf, len); + break; + case 4: + putchar('G'); + if((vbuf = vlget(villa, buf, len, NULL)) != NULL){ + free(vbuf); + } else if(dpecode != DP_ENOITEM){ + err = TRUE; + } + break; + case 5: + putchar('V'); + if(vlvsiz(villa, buf, len) < 0 && dpecode != DP_ENOITEM) err = TRUE; + if(!vlvnum(villa, buf, len) && dpecode != DP_ENOITEM) err = TRUE; + break; + case 6: + putchar('X'); + list = cblistopen(); + cblistpush(list, buf, len); + cblistpush(list, buf, len); + if(!vlputlist(villa, buf, len, list)) err = TRUE; + cblistclose(list); + break; + case 7: + putchar('Y'); + if(!vloutlist(villa, buf, len) && dpecode != DP_ENOITEM) err = TRUE; + break; + case 8: + putchar('Z'); + if((list = vlgetlist(villa, buf, len)) != NULL){ + cblistclose(list); + } else if(dpecode != DP_ENOITEM){ + err = TRUE; + } + if((vbuf = vlgetcat(villa, buf, len, NULL)) != NULL){ + free(vbuf); + } else if(dpecode != DP_ENOITEM){ + err = TRUE; + } + break; + case 9: + putchar('Q'); + if(vlcurjump(villa, buf, len, VL_JFORWARD)){ + for(j = 0; j < 3 && (kbuf = vlcurkey(villa, &ksiz)); j++){ + if(VL_CMPLEX(buf, len, kbuf, ksiz) > 0) err = TRUE; + if(strcmp(vlcurkeycache(villa, NULL), kbuf)) err = TRUE; + if((vbuf = vlcurval(villa, &vsiz)) != NULL){ + if(strcmp(vlcurvalcache(villa, NULL), vbuf)) err = TRUE; + free(vbuf); + } else { + err = TRUE; + } + free(kbuf); + if(!vlcurnext(villa) && dpecode != DP_ENOITEM) err = TRUE; + } + } else { + if(dpecode != DP_ENOITEM) err = TRUE; + } + break; + case 10: + putchar('W'); + if(vlcurjump(villa, buf, len, VL_JBACKWARD)){ + for(j = 0; j < 3 && (kbuf = vlcurkey(villa, &ksiz)); j++){ + if(VL_CMPLEX(buf, len, kbuf, ksiz) < 0) err = TRUE; + if(strcmp(vlcurkeycache(villa, NULL), kbuf)) err = TRUE; + if((vbuf = vlcurval(villa, &vsiz)) != NULL){ + if(strcmp(vlcurvalcache(villa, NULL), vbuf)) err = TRUE; + free(vbuf); + } else { + err = TRUE; + } + free(kbuf); + if(!vlcurprev(villa) && dpecode != DP_ENOITEM) err = TRUE; + } + } else { + if(dpecode != DP_ENOITEM) err = TRUE; + } + break; + case 11: + putchar('L'); + if(myrand() % 3 == 0 && + !vlcurjump(villa, buf, len, i % 3 == 0 ? VL_JFORWARD : VL_JBACKWARD) && + dpecode != DP_ENOITEM) err = TRUE; + for(j = myrand() % 5; j >= 0; j--){ + switch(myrand() % 6){ + case 0: + if(!vlcurput(villa, buf, len, VL_CPAFTER) && dpecode != DP_ENOITEM) err = TRUE; + break; + case 1: + if(!vlcurput(villa, buf, len, VL_CPBEFORE) && dpecode != DP_ENOITEM) err = TRUE; + break; + case 2: + if(!vlcurput(villa, buf, len, VL_CPCURRENT) && dpecode != DP_ENOITEM) err = TRUE; + break; + default: + if(!vlcurout(villa)){ + if(dpecode != DP_ENOITEM) err = TRUE; + break; + } + break; + } + } + break; + case 12: + if(tran ? myrand() % 32 != 0 : myrand() % 1024 != 0){ + putchar('N'); + break; + } + putchar('T'); + if(tran){ + if(myrand() % 5 == 0){ + if(!vltranabort(villa)) err = TRUE; + } else { + if(!vltrancommit(villa)) err = TRUE; + } + tran = FALSE; + } else { + if(!vltranbegin(villa)) err = TRUE; + tran = TRUE; + } + break; + default: + putchar('P'); + if(!vlput(villa, buf, len, buf, len, myrand() % 3 == 0 ? VL_DDUPR : VL_DDUP)) err = TRUE; + break; + } + if(i % 50 == 0) printfflush(" (%08d)\n", i); + if(err){ + pdperror(name); + break; + } + } + if(tran){ + if(!vltranabort(villa)) err = TRUE; + } + if(!vloptimize(villa)){ + pdperror(name); + err = TRUE; + } + if((rnum = vlrnum(villa)) == -1){ + pdperror(name); + err = TRUE; + } + if(!vlcurfirst(villa)){ + pdperror(name); + err = TRUE; + } + i = 0; + do { + kbuf = NULL; + vbuf = NULL; + if(!(kbuf = vlcurkey(villa, &ksiz)) || !(vbuf = vlcurval(villa, &vsiz)) || + ksiz != 8 || vsiz % 8 != 0 || vlvnum(villa, kbuf, ksiz) < 1){ + pdperror(name); + free(kbuf); + free(vbuf); + err = TRUE; + break; + } + free(kbuf); + free(vbuf); + i++; + } while(vlcurnext(villa)); + if(i != rnum){ + fprintf(stderr, "%s: %s: invalid cursor\n", progname, name); + err = TRUE; + } + if(dpecode != DP_ENOITEM){ + pdperror(name); + err = TRUE; + } + if(!vlcurlast(villa)){ + pdperror(name); + err = TRUE; + } + i = 0; + do { + kbuf = NULL; + vbuf = NULL; + if(!(kbuf = vlcurkey(villa, &ksiz)) || !(vbuf = vlcurval(villa, &vsiz)) || + ksiz != 8 || vsiz % 8 != 0 || vlvnum(villa, kbuf, ksiz) < 1){ + pdperror(name); + free(kbuf); + free(vbuf); + err = TRUE; + break; + } + free(kbuf); + free(vbuf); + i++; + } while(vlcurprev(villa)); + if(i != rnum){ + fprintf(stderr, "%s: %s: invalid cursor\n", progname, name); + err = TRUE; + } + if(dpecode != DP_ENOITEM){ + pdperror(name); + err = TRUE; + } + if(map){ + printfflush("Matching records ... "); + cbmapiterinit(map); + while((mkbuf = cbmapiternext(map, &mksiz)) != NULL){ + mvbuf = cbmapget(map, mkbuf, mksiz, &mvsiz); + if(!(vbuf = vlget(villa, mkbuf, mksiz, &rsiz))){ + pdperror(name); + err = TRUE; + break; + } + if(rsiz != mvsiz || memcmp(vbuf, mvbuf, rsiz)){ + fprintf(stderr, "%s: %s: unmatched record\n", progname, name); + free(vbuf); + err = TRUE; + break; + } + free(vbuf); + } + cbmapclose(map); + if(!err) printfflush("ok\n"); + } + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + if(!err) printfflush("ok\n\n"); + return err ? 1 : 0; +} + + + +/* END OF FILE */ diff --git a/qdbm/vltsv.c b/qdbm/vltsv.c new file mode 100644 index 00000000..acca6070 --- /dev/null +++ b/qdbm/vltsv.c @@ -0,0 +1,261 @@ +/************************************************************************************************* + * Mutual converter between a database of Villa and a TSV text + * Copyright (C) 2000-2007 Mikio Hirabayashi + * This file is part of QDBM, Quick Database Manager. + * QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation; either version + * 2.1 of the License or any later version. QDBM is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * You should have received a copy of the GNU Lesser General Public License along with QDBM; if + * not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + *************************************************************************************************/ + + +#include +#include +#include +#include +#include +#include + +#undef TRUE +#define TRUE 1 /* boolean true */ +#undef FALSE +#define FALSE 0 /* boolean false */ + + +/* for RISC OS */ +#if defined(__riscos__) || defined(__riscos) +#include +int __riscosify_control = __RISCOSIFY_NO_PROCESS; +#endif + + +/* global variables */ +const char *progname; /* program name */ + + +/* function prototypes */ +int main(int argc, char **argv); +void usage(void); +int runimport(int argc, char **argv); +int runexport(int argc, char **argv); +void pdperror(const char *name); +char *getl(void); +int doimport(const char *name, int bin); +int doexport(const char *name, int bin); + + +/* main routine */ +int main(int argc, char **argv){ + int rv; + cbstdiobin(); + progname = argv[0]; + if(argc < 2) usage(); + rv = 0; + if(!strcmp(argv[1], "import")){ + rv = runimport(argc, argv); + } else if(!strcmp(argv[1], "export")){ + rv = runexport(argc, argv); + } else { + usage(); + } + return rv; +} + + +/* print the usage and exit */ +void usage(void){ + fprintf(stderr, "%s: mutual converter between TSV and Villa database\n", progname); + fprintf(stderr, "\n"); + fprintf(stderr, "usage:\n"); + fprintf(stderr, " %s import [-bin] name\n", progname); + fprintf(stderr, " %s export [-bin] name\n", progname); + fprintf(stderr, "\n"); + exit(1); +} + + +/* parse arguments of import command */ +int runimport(int argc, char **argv){ + char *name; + int i, bin, rv; + name = NULL; + bin = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-bin")){ + bin = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doimport(name, bin); + return rv; +} + + +/* parse arguments of export command */ +int runexport(int argc, char **argv){ + char *name; + int i, bin, rv; + name = NULL; + bin = FALSE; + for(i = 2; i < argc; i++){ + if(!name && argv[i][0] == '-'){ + if(!strcmp(argv[i], "-bin")){ + bin = TRUE; + } else { + usage(); + } + } else if(!name){ + name = argv[i]; + } else { + usage(); + } + } + if(!name) usage(); + rv = doexport(name, bin); + return rv; +} + + +/* print an error message */ +void pdperror(const char *name){ + fprintf(stderr, "%s: %s: %s\n", progname, name, dperrmsg(dpecode)); +} + + +/* read a line */ +char *getl(void){ + char *buf; + int c, len, blen; + buf = NULL; + len = 0; + blen = 256; + while((c = getchar()) != EOF){ + if(blen <= len) blen *= 2; + buf = cbrealloc(buf, blen + 1); + if(c == '\n') c = '\0'; + buf[len++] = c; + if(c == '\0') break; + } + if(!buf) return NULL; + buf[len] = '\0'; + return buf; +} + + +/* perform import command */ +int doimport(const char *name, int bin){ + VILLA *villa; + char *buf, *kbuf, *vbuf, *ktmp, *vtmp; + int i, err, ktsiz, vtsiz; + /* open a database */ + if(!(villa = vlopen(name, VL_OWRITER | VL_OCREAT, VL_CMPLEX))){ + pdperror(name); + return 1; + } + /* loop for each line */ + err = FALSE; + for(i = 1; (buf = getl()) != NULL; i++){ + kbuf = buf; + if((vbuf = strchr(buf, '\t')) != NULL){ + *vbuf = '\0'; + vbuf++; + /* store a record */ + if(bin){ + ktmp = cbbasedecode(kbuf, &ktsiz); + vtmp = cbbasedecode(vbuf, &vtsiz); + if(!vlput(villa, ktmp, ktsiz, vtmp, vtsiz, VL_DDUP)){ + pdperror(name); + err = TRUE; + } + free(vtmp); + free(ktmp); + } else { + if(!vlput(villa, kbuf, -1, vbuf, -1, VL_DDUP)){ + pdperror(name); + err = TRUE; + break; + } + } + } else { + fprintf(stderr, "%s: %s: invalid format in line %d\n", progname, name, i); + } + free(buf); + if(err) break; + } + /* close the database */ + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return err ? 1 : 0; +} + + +/* perform export command */ +int doexport(const char *name, int bin){ + VILLA *villa; + char *kbuf, *vbuf, *tmp; + int err, ksiz, vsiz; + /* open a database */ + if(!(villa = vlopen(name, VL_OREADER, VL_CMPLEX))){ + pdperror(name); + return 1; + } + /* initialize the cursor */ + vlcurfirst(villa); + /* loop for each key */ + err = FALSE; + while((kbuf = vlcurkey(villa, &ksiz)) != NULL){ + /* retrieve a value with a key */ + if(!(vbuf = vlcurval(villa, &vsiz))){ + pdperror(name); + free(kbuf); + err = TRUE; + break; + } + /* output data */ + if(bin){ + tmp = cbbaseencode(kbuf, ksiz); + printf("%s\t", tmp); + free(tmp); + tmp = cbbaseencode(vbuf, vsiz); + printf("%s\n", tmp); + free(tmp); + } else { + printf("%s\t%s\n", kbuf, vbuf); + } + /* free resources */ + free(vbuf); + free(kbuf); + /* step the cursor */ + vlcurnext(villa); + } + /* check whether all records were retrieved */ + if(dpecode != DP_ENOITEM){ + pdperror(name); + err = TRUE; + } + /* close the database */ + if(!vlclose(villa)){ + pdperror(name); + return 1; + } + return 0; +} + + + +/* END OF FILE */ -- cgit v1.2.3