tokyocabinet_all.o : myconf.h tcutil.h tchdb.h tcbdb.h tcfdb.h tctdb.h tcadb.h
-platform.o : basedefs.h platform.c win32/platform.c
+platform.o : basedefs.h platform.c win32/platform.c nix/platform.c
# END OF FILE
if (i >= 0 && i < 1000)
memcpy(str, bson_numstrs[i], 4);
else
- sprintf(str, "%" PRIdMAX "", (long long int) i);
+ sprintf(str, "%" PRIdMAX "", (int64_t) i);
}
#pragma GCC diagnostic push
memcpy(str, bson_numstrs[i], 4);
return strlen(bson_numstrs[i]);
} else {
- return snprintf(str, maxbuf, "%" PRIdMAX "", (long long int) i);
+ return snprintf(str, maxbuf, "%" PRIdMAX "", (int64_t) i);
}
}
#pragma GCC diagnostic pop
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
+#include <time.h>
#define BSON_IS_NUM_TYPE(atype) (atype == BSON_INT || atype == BSON_LONG || atype == BSON_DOUBLE)
MYCFLAGS="$MYCFLAGS -std=gnu99 -Wall -fsigned-char -O2 -Wfatal-errors"
MYCPPFLAGS="-I. -I$HOME/include -I\$(INCLUDEDIR) -I/usr/local/include"
MYCPPFLAGS="$MYCPPFLAGS -D_UNICODE -DNDEBUG -D_GNU_SOURCE=1 -D_REENTRANT -D__EXTENSIONS__"
-MYLDFLAGS="-L. -L\$(LIBDIR) -L$HOME/lib -L/usr/local/lib -L/usr/lib -Wl,-Bstatic"
+MYLDFLAGS="-L. -L\$(LIBDIR) -L$HOME/lib -L/usr/local/lib -L/usr/lib"
MYCMDLDFLAGS=""
MYRUNPATH="\$(LIBDIR)"
MYLDLIBPATHENV="LD_LIBRARY_PATH"
AC_CHECK_LIB(pcre, pcre_compile, [], AC_MSG_ERROR([pcre lib is required]))
AC_CHECK_LIB(pcreposix, regcomp, [], AC_MSG_ERROR([pcreposix lib is required]))
AC_CHECK_LIB(pthreadGC2, main, [], AC_MSG_ERROR([pthreadGC2 lubrary is required]))
- MYLDFLAGS="-static-libgcc -static-libstdc++ $MYLDFLAGS"
+ MYLDFLAGS="-static-libgcc -static-libstdc++ $MYLDFLAGS -Wl,-Bstatic"
MYHEADERFILES="$MYHEADERFILES win32/platform.h"
MYCPPFLAGS="$MYCPPFLAGS -DPCRE_STATIC -DPTW32_STATIC_LIB"
;;
*)
+ MYHEADERFILES="$MYHEADERFILES nix/platform.h"
AC_CHECK_HEADER(regex.h, true, AC_MSG_ERROR([regex.h is required]))
- AC_CHECK_LIB(regex, regcomp, [], AC_MSG_ERROR([regex lib is required]))
AC_CHECK_LIB(pthread, main, [], AC_MSG_ERROR([pthread lubrary is required]))
MYCFLAGS="$MYCFLAGS -fPIC"
;;
static bool _metasetopts(EJDB *jb, const char *colname, EJCOLLOPTS *opts);
static bool _metagetopts(EJDB *jb, const char *colname, EJCOLLOPTS *opts);
static bson* _metagetbson(EJDB *jb, const char *colname, int colnamesz, const char *mkey);
-static bson* _metagetbson2(EJCOLL *jcoll, const char *mkey) __attribute__ ((unused));
+static bson* _metagetbson2(EJCOLL *jcoll, const char *mkey) __attribute__((unused));
static bool _metasetbson(EJDB *jb, const char *colname, int colnamesz,
const char *mkey, bson *val, bool merge, bool mergeoverwrt);
static bool _metasetbson2(EJCOLL *jcoll, const char *mkey, bson *val, bool merge, bool mergeoverwrt);
static const bool yes = true;
static const bool no = false;
- const char* ejdberrmsg(int ecode) {
+const char* ejdberrmsg(int ecode) {
if (ecode > -6 && ecode < 0) { //Hook for negative error codes of utf8proc library
return utf8proc_errmsg(ecode);
}
}
}
- bool ejdbisvalidoidstr(const char *oid) {
+bool ejdbisvalidoidstr(const char *oid) {
if (!oid) {
return false;
}
}
/* Get the last happened error code of a database object. */
- int ejdbecode(EJDB *jb) {
+int ejdbecode(EJDB *jb) {
assert(jb && jb->metadb);
return tctdbecode(jb->metadb);
}
- EJDB* ejdbnew(void) {
+EJDB* ejdbnew(void) {
EJDB *jb;
TCCALLOC(jb, 1, sizeof (*jb));
jb->metadb = tctdbnew();
return jb;
}
- void ejdbdel(EJDB *jb) {
+void ejdbdel(EJDB *jb) {
assert(jb && jb->metadb);
if (JBISOPEN(jb)) ejdbclose(jb);
for (int i = 0; i < jb->cdbsnum; ++i) {
TCFREE(jb);
}
- bool ejdbclose(EJDB *jb) {
+bool ejdbclose(EJDB *jb) {
JBENSUREOPENLOCK(jb, true, false);
bool rv = true;
for (int i = 0; i < jb->cdbsnum; ++i) {
return rv;
}
- bool ejdbisopen(EJDB *jb) {
+bool ejdbisopen(EJDB *jb) {
return JBISOPEN(jb);
}
- bool ejdbopen(EJDB *jb, const char *path, int mode) {
+bool ejdbopen(EJDB *jb, const char *path, int mode) {
assert(jb && path);
assert(jb->metadb);
if (!JBLOCKMETHOD(jb, true)) return false;
return rv;
}
- EJCOLL* ejdbgetcoll(EJDB *jb, const char *colname) {
+EJCOLL* ejdbgetcoll(EJDB *jb, const char *colname) {
assert(colname);
EJCOLL *coll = NULL;
JBENSUREOPENLOCK(jb, false, NULL);
return coll;
}
- TCLIST* ejdbgetcolls(EJDB *jb) {
+TCLIST* ejdbgetcolls(EJDB *jb) {
assert(jb);
EJCOLL *coll = NULL;
JBENSUREOPENLOCK(jb, false, NULL);
return ret;
}
- EJCOLL* ejdbcreatecoll(EJDB *jb, const char *colname, EJCOLLOPTS *opts) {
+EJCOLL* ejdbcreatecoll(EJDB *jb, const char *colname, EJCOLLOPTS *opts) {
assert(colname);
EJCOLL *coll = ejdbgetcoll(jb, colname);
if (coll) {
return coll;
}
- bool ejdbrmcoll(EJDB *jb, const char *colname, bool unlinkfile) {
+bool ejdbrmcoll(EJDB *jb, const char *colname, bool unlinkfile) {
assert(colname);
JBENSUREOPENLOCK(jb, true, false);
bool rv = true;
}
/* Save/Update BSON */
- bool ejdbsavebson(EJCOLL *jcoll, bson *bs, bson_oid_t *oid) {
+bool ejdbsavebson(EJCOLL *jcoll, bson *bs, bson_oid_t *oid) {
return ejdbsavebson2(jcoll, bs, oid, false);
}
- bool ejdbsavebson2(EJCOLL *jcoll, bson *bs, bson_oid_t *oid, bool merge) {
+bool ejdbsavebson2(EJCOLL *jcoll, bson *bs, bson_oid_t *oid, bool merge) {
assert(jcoll);
if (!bs || bs->err || !bs->finished) {
_ejdbsetecode(jcoll->jb, JBEINVALIDBSON, __FILE__, __LINE__, __func__);
return rv;
}
- bool ejdbrmbson(EJCOLL *jcoll, bson_oid_t *oid) {
+bool ejdbrmbson(EJCOLL *jcoll, bson_oid_t *oid) {
assert(jcoll && oid);
if (!JBISOPEN(jcoll->jb)) {
_ejdbsetecode(jcoll->jb, TCEINVALID, __FILE__, __LINE__, __func__);
return rv;
}
- bson* ejdbloadbson(EJCOLL *jcoll, const bson_oid_t *oid) {
+bson* ejdbloadbson(EJCOLL *jcoll, const bson_oid_t *oid) {
assert(jcoll && oid);
if (!JBISOPEN(jcoll->jb)) {
_ejdbsetecode(jcoll->jb, TCEINVALID, __FILE__, __LINE__, __func__);
return ret;
}
- EJQ* ejdbcreatequery(EJDB *jb, bson *qobj, bson *orqobjs, int orqobjsnum, bson *hints) {
+EJQ* ejdbcreatequery(EJDB *jb, bson *qobj, bson *orqobjs, int orqobjsnum, bson *hints) {
assert(jb);
if (!qobj || qobj->err || !qobj->finished) {
_ejdbsetecode(jb, JBEINVALIDBSON, __FILE__, __LINE__, __func__);
return NULL;
}
- void ejdbquerydel(EJQ *q) {
+void ejdbquerydel(EJQ *q) {
_qrydel(q, true);
}
/** Set index */
- bool ejdbsetindex(EJCOLL *jcoll, const char *fpath, int flags) {
+bool ejdbsetindex(EJCOLL *jcoll, const char *fpath, int flags) {
assert(jcoll && fpath);
bool rv = true;
bson *imeta = NULL;
return rv;
}
- uint32_t ejdbupdate(EJCOLL *jcoll, bson *qobj, bson *orqobjs, int orqobjsnum, bson *hints, TCXSTR *log) {
+uint32_t ejdbupdate(EJCOLL *jcoll, bson *qobj, bson *orqobjs, int orqobjsnum, bson *hints, TCXSTR *log) {
assert(jcoll);
uint32_t count = 0;
EJQ *q = ejdbcreatequery(jcoll->jb, qobj, orqobjs, orqobjsnum, hints);
return count;
}
- TCLIST* ejdbqryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *count, int qflags, TCXSTR *log) {
+TCLIST* ejdbqryexecute(EJCOLL *jcoll, const EJQ *q, uint32_t *count, int qflags, TCXSTR *log) {
assert(jcoll && q && q->qobjlist);
if (!JBISOPEN(jcoll->jb)) {
_ejdbsetecode(jcoll->jb, TCEINVALID, __FILE__, __LINE__, __func__);
return res;
}
- bool ejdbsyncoll(EJCOLL *jcoll) {
+bool ejdbsyncoll(EJCOLL *jcoll) {
assert(jcoll);
if (!JBISOPEN(jcoll->jb)) {
_ejdbsetecode(jcoll->jb, TCEINVALID, __FILE__, __LINE__, __func__);
return rv;
}
- bool ejdbsyncdb(EJDB *jb) {
+bool ejdbsyncdb(EJDB *jb) {
assert(jb);
JBENSUREOPENLOCK(jb, true, false);
bool rv = true;
return rv;
}
- bool ejdbtranbegin(EJCOLL *jcoll) {
+bool ejdbtranbegin(EJCOLL *jcoll) {
assert(jcoll);
if (!JBISOPEN(jcoll->jb)) {
_ejdbsetecode(jcoll->jb, TCEINVALID, __FILE__, __LINE__, __func__);
return true;
}
- bool ejdbtrancommit(EJCOLL *jcoll) {
+bool ejdbtrancommit(EJCOLL *jcoll) {
assert(jcoll);
if (!JBISOPEN(jcoll->jb)) {
_ejdbsetecode(jcoll->jb, TCEINVALID, __FILE__, __LINE__, __func__);
return !err;
}
- bool ejdbtranabort(EJCOLL *jcoll) {
+bool ejdbtranabort(EJCOLL *jcoll) {
assert(jcoll);
if (!JBISOPEN(jcoll->jb)) {
_ejdbsetecode(jcoll->jb, TCEINVALID, __FILE__, __LINE__, __func__);
return !err;
}
- bool ejdbtranstatus(EJCOLL *jcoll, bool *txactive) {
+bool ejdbtranstatus(EJCOLL *jcoll, bool *txactive) {
assert(jcoll && txactive);
if (!JBISOPEN(jcoll->jb)) {
_ejdbsetecode(jcoll->jb, TCEINVALID, __FILE__, __LINE__, __func__);
#define GET_STDIN_HANDLE() GetStdHandle(STD_INPUT_HANDLE)
#define CLOSEFH(_fd) (CloseHandle(_fd))
#else
+#ifdef __unix
+#include "nix/platform.h"
+#endif
#include <regex.h>
#include <glob.h>
#include <sys/mman.h>
#define GET_STDOUT_HANDLE() (1)
#define GET_STDERR_HANDLE() (2)
#define GET_STDIN_HANDLE() (0)
-#define CLOSEFH(_fd) (close(_fd) != -1)
+#define CLOSEFH(_fd) (closefd(_fd))
#define sysconf_SC_CLK_TCK sysconf(_SC_CLK_TCK)
#endif
--- /dev/null
+#include "platform.h"
+#include "../tcutil.h"
+#include "../myconf.h"
+
+#include <unistd.h>
+
+bool closefd(int fd) {
+ return (close(fd) != -1);
+}
+
--- /dev/null
+/*
+ * File: platform.h
+ * Author: adam
+ *
+ * Created on April 21, 2013, 10:27 PM
+ */
+
+#ifndef PLATFORM_H
+#define PLATFORM_H
+
+#include "basedefs.h"
+#include <stdbool.h>
+
+EJDB_EXTERN_C_START
+
+bool closefd(int fd);
+
+EJDB_EXTERN_C_END
+
+#endif /* PLATFORM_H */
+
#ifdef _WIN32
#include "win32/platform.c"
#endif
+
+#ifdef __unix
+#include "nix/platform.c"
+#endif
+
+
+
+
break;
case ADBOTDB:
if (ksiz < 1) {
- ksiz = sprintf(numbuf, "%" PRIdMAX "", (long long) tctdbgenuid(adb->tdb));
+ ksiz = sprintf(numbuf, "%" PRIdMAX "", (int64_t) tctdbgenuid(adb->tdb));
kbuf = numbuf;
}
if (!tctdbput2(adb->tdb, kbuf, ksiz, vbuf, vsiz)) err = true;
break;
case ADBOTDB:
if (ksiz < 1) {
- ksiz = sprintf(numbuf, "%" PRIdMAX "", (long long) tctdbgenuid(adb->tdb));
+ ksiz = sprintf(numbuf, "%" PRIdMAX "", (int64_t) tctdbgenuid(adb->tdb));
kbuf = numbuf;
}
if (!tctdbputkeep2(adb->tdb, kbuf, ksiz, vbuf, vsiz)) err = true;
break;
case ADBOTDB:
if (ksiz < 1) {
- ksiz = sprintf(numbuf, "%" PRIdMAX "", (long long) tctdbgenuid(adb->tdb));
+ ksiz = sprintf(numbuf, "%" PRIdMAX "", (int64_t) tctdbgenuid(adb->tdb));
kbuf = numbuf;
}
if (!tctdbputcat2(adb->tdb, kbuf, ksiz, vbuf, vsiz)) err = true;
break;
case ADBOTDB:
if (ksiz < 1) {
- ksiz = sprintf(numbuf, "%" PRIdMAX "", (long long) tctdbgenuid(adb->tdb));
+ ksiz = sprintf(numbuf, "%" PRIdMAX "", (int64_t) tctdbgenuid(adb->tdb));
kbuf = numbuf;
}
rv = tctdbaddint(adb->tdb, kbuf, ksiz, num);
break;
case ADBOTDB:
if (ksiz < 1) {
- ksiz = sprintf(numbuf, "%" PRIdMAX "", (long long) tctdbgenuid(adb->tdb));
+ ksiz = sprintf(numbuf, "%" PRIdMAX "", (int64_t) tctdbgenuid(adb->tdb));
kbuf = numbuf;
}
rv = tctdbadddouble(adb->tdb, kbuf, ksiz, num);
case ADBONDB:
if (*path == '@') {
char tsbuf[TCNUMBUFSIZ];
- sprintf(tsbuf, "%" PRIuMAX "", (unsigned long long) (tctime() * 1000000));
+ sprintf(tsbuf, "%" PRIuMAX "", (uint64_t) (tctime() * 1000000));
const char *args[2];
args[0] = path + 1;
args[1] = tsbuf;
} else if (!strcmp(name, "genuid")) {
rv = tclistnew2(1);
char numbuf[TCNUMBUFSIZ];
- int nsiz = sprintf(numbuf, "%" PRIdMAX "", (long long) tctdbgenuid(adb->tdb));
+ int nsiz = sprintf(numbuf, "%" PRIdMAX "", (int64_t) tctdbgenuid(adb->tdb));
TCLISTPUSH(rv, numbuf, nsiz);
} else {
rv = NULL;
/* global variables */
-const char *g_progname; // program name
+const char *g_progname; // program name
/* function prototypes */
static int printdata(const char *ptr, int size, bool px, int sep);
static void setskeltran(ADBSKEL *skel);
static bool mapbdbproc(void *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- void *op);
+ void *op);
static int runcreate(int argc, char **argv);
static int runinform(int argc, char **argv);
static int runput(int argc, char **argv);
static int proccreate(const char *name);
static int procinform(const char *name);
static int procput(const char *name, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- int dmode);
+ int dmode);
static int procout(const char *name, const char *kbuf, int ksiz);
static int procget(const char *name, const char *kbuf, int ksiz, int sep, bool px, bool pz);
static int proclist(const char *name, int sep, int max, bool pv, bool px, const char *fmstr);
static int procmap(const char *name, const char *dest, const char *fmstr);
static int procversion(void);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "create")){
- rv = runcreate(argc, argv);
- } else if(!strcmp(argv[1], "inform")){
- rv = runinform(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], "misc")){
- rv = runmisc(argc, argv);
- } else if(!strcmp(argv[1], "map")){
- rv = runmap(argc, argv);
- } else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){
- rv = runversion(argc, argv);
- } else {
- usage();
- }
- return rv;
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "create")) {
+ rv = runcreate(argc, argv);
+ } else if (!strcmp(argv[1], "inform")) {
+ rv = runinform(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], "misc")) {
+ rv = runmisc(argc, argv);
+ } else if (!strcmp(argv[1], "map")) {
+ rv = runmap(argc, argv);
+ } else if (!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")) {
+ rv = runversion(argc, argv);
+ } else {
+ usage();
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: the command line utility of the abstract database API\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s create name\n", g_progname);
- fprintf(stderr, " %s inform name\n", g_progname);
- fprintf(stderr, " %s put [-sx] [-sep chr] [-dk|-dc|-dai|-dad] name key value\n", g_progname);
- fprintf(stderr, " %s out [-sx] [-sep chr] name key\n", g_progname);
- fprintf(stderr, " %s get [-sx] [-sep chr] [-px] [-pz] name key\n", g_progname);
- fprintf(stderr, " %s list [-sep chr] [-m num] [-pv] [-px] [-fm str] name\n", g_progname);
- fprintf(stderr, " %s optimize name [params]\n", g_progname);
- fprintf(stderr, " %s misc [-sx] [-sep chr] [-px] name func [arg...]\n", g_progname);
- fprintf(stderr, " %s map [-fm str] name dest\n", g_progname);
- fprintf(stderr, " %s version\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: the command line utility of the abstract database API\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s create name\n", g_progname);
+ fprintf(stderr, " %s inform name\n", g_progname);
+ fprintf(stderr, " %s put [-sx] [-sep chr] [-dk|-dc|-dai|-dad] name key value\n", g_progname);
+ fprintf(stderr, " %s out [-sx] [-sep chr] name key\n", g_progname);
+ fprintf(stderr, " %s get [-sx] [-sep chr] [-px] [-pz] name key\n", g_progname);
+ fprintf(stderr, " %s list [-sep chr] [-m num] [-pv] [-px] [-fm str] name\n", g_progname);
+ fprintf(stderr, " %s optimize name [params]\n", g_progname);
+ fprintf(stderr, " %s misc [-sx] [-sep chr] [-px] name func [arg...]\n", g_progname);
+ fprintf(stderr, " %s map [-fm str] name dest\n", g_progname);
+ fprintf(stderr, " %s version\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* get the character of separation string */
-static int sepstrtochr(const char *str){
- if(!strcmp(str, "\\t")) return '\t';
- if(!strcmp(str, "\\r")) return '\r';
- if(!strcmp(str, "\\n")) return '\n';
- return *(unsigned char *)str;
+static int sepstrtochr(const char *str) {
+ if (!strcmp(str, "\\t")) return '\t';
+ if (!strcmp(str, "\\r")) return '\r';
+ if (!strcmp(str, "\\n")) return '\n';
+ return *(unsigned char *) str;
}
-
/* encode a string as a zero separaterd string */
-static char *strtozsv(const char *str, int sep, int *sp){
- int size = strlen(str);
- char *buf = tcmemdup(str, size);
- for(int i = 0; i < size; i++){
- if(buf[i] == sep) buf[i] = '\0';
- }
- *sp = size;
- return buf;
+static char *strtozsv(const char *str, int sep, int *sp) {
+ int size = strlen(str);
+ char *buf = tcmemdup(str, size);
+ for (int i = 0; i < size; i++) {
+ if (buf[i] == sep) buf[i] = '\0';
+ }
+ *sp = size;
+ return buf;
}
-
/* print error information */
-static void printerr(TCADB *adb){
- const char *path = tcadbpath(adb);
- fprintf(stderr, "%s: %s: error\n", g_progname, path ? path : "-");
+static void printerr(TCADB *adb) {
+ const char *path = tcadbpath(adb);
+ fprintf(stderr, "%s: %s: error\n", g_progname, path ? path : "-");
}
-
/* print record data */
-static int printdata(const char *ptr, int size, bool px, int sep){
- int len = 0;
- while(size-- > 0){
- if(px){
- if(len > 0) putchar(' ');
- len += printf("%02X", *(unsigned char *)ptr);
- } else if(sep > 0){
- if(*ptr == '\0'){
- putchar(sep);
- } else {
- putchar(*ptr);
- }
- len++;
- } else {
- putchar(*ptr);
- len++;
+static int printdata(const char *ptr, int size, bool px, int sep) {
+ int len = 0;
+ while (size-- > 0) {
+ if (px) {
+ if (len > 0) putchar(' ');
+ len += printf("%02X", *(unsigned char *) ptr);
+ } else if (sep > 0) {
+ if (*ptr == '\0') {
+ putchar(sep);
+ } else {
+ putchar(*ptr);
+ }
+ len++;
+ } else {
+ putchar(*ptr);
+ len++;
+ }
+ ptr++;
}
- ptr++;
- }
- return len;
+ return len;
}
-
/* set the transparent skeleton database */
-static void setskeltran(ADBSKEL *skel){
- memset(skel, 0, sizeof(*skel));
- skel->opq = tcadbnew();
- skel->del = (void (*)(void *))tcadbdel;
- skel->open = (bool (*)(void *, const char *))tcadbopen;
- skel->close = (bool (*)(void *))tcadbclose;
- skel->put = (bool (*)(void *, const void *, int, const void *, int))tcadbput;
- skel->putkeep = (bool (*)(void *, const void *, int, const void *, int))tcadbputkeep;
- skel->putcat = (bool (*)(void *, const void *, int, const void *, int))tcadbputcat;
- skel->out = (bool (*)(void *, const void *, int))tcadbout;
- skel->get = (void *(*)(void *, const void *, int, int *))tcadbget;
- skel->vsiz = (int (*)(void *, const void *, int))tcadbvsiz;
- skel->iterinit = (bool (*)(void *))tcadbiterinit;
- skel->iternext = (void *(*)(void *, int *))tcadbiternext;
- skel->fwmkeys = (TCLIST *(*)(void *, const void *, int, int))tcadbfwmkeys;
- skel->addint = (int (*)(void *, const void *, int, int))tcadbaddint;
- skel->adddouble = (double (*)(void *, const void *, int, double))tcadbadddouble;
- skel->sync = (bool (*)(void *))tcadbsync;
- skel->optimize = (bool (*)(void *, const char *))tcadboptimize;
- skel->vanish = (bool (*)(void *))tcadbvanish;
- skel->copy = (bool (*)(void *, const char *))tcadbcopy;
- skel->tranbegin = (bool (*)(void *))tcadbtranbegin;
- skel->trancommit = (bool (*)(void *))tcadbtrancommit;
- skel->tranabort = (bool (*)(void *))tcadbtranabort;
- skel->path = (const char *(*)(void *))tcadbpath;
- skel->rnum = (uint64_t (*)(void *))tcadbrnum;
- skel->size = (uint64_t (*)(void *))tcadbsize;
- skel->misc = (TCLIST *(*)(void *, const char *, const TCLIST *))tcadbmisc;
- skel->putproc =
- (bool (*)(void *, const void *, int, const void *, int, TCPDPROC, void *))tcadbputproc;
- skel->foreach = (bool (*)(void *, TCITER, void *))tcadbforeach;
+static void setskeltran(ADBSKEL *skel) {
+ memset(skel, 0, sizeof (*skel));
+ skel->opq = tcadbnew();
+ skel->del = (void (*)(void *))tcadbdel;
+ skel->open = (bool(*)(void *, const char *))tcadbopen;
+ skel->close = (bool(*)(void *))tcadbclose;
+ skel->put = (bool(*)(void *, const void *, int, const void *, int))tcadbput;
+ skel->putkeep = (bool(*)(void *, const void *, int, const void *, int))tcadbputkeep;
+ skel->putcat = (bool(*)(void *, const void *, int, const void *, int))tcadbputcat;
+ skel->out = (bool(*)(void *, const void *, int))tcadbout;
+ skel->get = (void *(*)(void *, const void *, int, int *))tcadbget;
+ skel->vsiz = (int (*)(void *, const void *, int))tcadbvsiz;
+ skel->iterinit = (bool(*)(void *))tcadbiterinit;
+ skel->iternext = (void *(*)(void *, int *))tcadbiternext;
+ skel->fwmkeys = (TCLIST * (*)(void *, const void *, int, int))tcadbfwmkeys;
+ skel->addint = (int (*)(void *, const void *, int, int))tcadbaddint;
+ skel->adddouble = (double (*)(void *, const void *, int, double))tcadbadddouble;
+ skel->sync = (bool(*)(void *))tcadbsync;
+ skel->optimize = (bool(*)(void *, const char *))tcadboptimize;
+ skel->vanish = (bool(*)(void *))tcadbvanish;
+ skel->copy = (bool(*)(void *, const char *))tcadbcopy;
+ skel->tranbegin = (bool(*)(void *))tcadbtranbegin;
+ skel->trancommit = (bool(*)(void *))tcadbtrancommit;
+ skel->tranabort = (bool(*)(void *))tcadbtranabort;
+ skel->path = (const char *(*)(void *))tcadbpath;
+ skel->rnum = (uint64_t(*)(void *))tcadbrnum;
+ skel->size = (uint64_t(*)(void *))tcadbsize;
+ skel->misc = (TCLIST * (*)(void *, const char *, const TCLIST *))tcadbmisc;
+ skel->putproc =
+ (bool(*)(void *, const void *, int, const void *, int, TCPDPROC, void *))tcadbputproc;
+ skel->foreach = (bool(*)(void *, TCITER, void *))tcadbforeach;
}
-
/* mapping function */
static bool mapbdbproc(void *map, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- void *op){
- bool err = false;
- if(!tcadbmapbdbemit(map, kbuf, ksiz, vbuf, vsiz)) err = true;
- return !err;
+ void *op) {
+ bool err = false;
+ if (!tcadbmapbdbemit(map, kbuf, ksiz, vbuf, vsiz)) err = true;
+ return !err;
}
-
/* parse arguments of create command */
-static int runcreate(int argc, char **argv){
- char *name = NULL;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else {
- usage();
+static int runcreate(int argc, char **argv) {
+ char *name = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ usage();
+ } else if (!name) {
+ name = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!name) usage();
- int rv = proccreate(name);
- return rv;
+ if (!name) usage();
+ int rv = proccreate(name);
+ return rv;
}
-
/* parse arguments of inform command */
-static int runinform(int argc, char **argv){
- char *name = NULL;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else {
- usage();
+static int runinform(int argc, char **argv) {
+ char *name = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ usage();
+ } else if (!name) {
+ name = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!name) usage();
- name = tcsprintf("%s#mode=r", name);
- int rv = procinform(name);
- tcfree(name);
- return rv;
+ if (!name) usage();
+ name = tcsprintf("%s#mode=r", name);
+ int rv = procinform(name);
+ tcfree(name);
+ return rv;
}
-
/* parse arguments of put command */
-static int runput(int argc, char **argv){
- char *name = NULL;
- char *key = NULL;
- char *value = NULL;
- int dmode = 0;
- bool sx = false;
- int sep = -1;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-dk")){
- dmode = -1;
- } else if(!strcmp(argv[i], "-dc")){
- dmode = 1;
- } else if(!strcmp(argv[i], "-dai")){
- dmode = 10;
- } else if(!strcmp(argv[i], "-dad")){
- dmode = 11;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else if(!strcmp(argv[i], "-sep")){
- if(++i >= argc) usage();
- sep = sepstrtochr(argv[i]);
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!key){
- key = argv[i];
- } else if(!value){
- value = argv[i];
+static int runput(int argc, char **argv) {
+ char *name = NULL;
+ char *key = NULL;
+ char *value = NULL;
+ int dmode = 0;
+ bool sx = false;
+ int sep = -1;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-dk")) {
+ dmode = -1;
+ } else if (!strcmp(argv[i], "-dc")) {
+ dmode = 1;
+ } else if (!strcmp(argv[i], "-dai")) {
+ dmode = 10;
+ } else if (!strcmp(argv[i], "-dad")) {
+ dmode = 11;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else if (!strcmp(argv[i], "-sep")) {
+ if (++i >= argc) usage();
+ sep = sepstrtochr(argv[i]);
+ } else {
+ usage();
+ }
+ } else if (!name) {
+ name = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else if (!value) {
+ value = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!name || !key || !value) usage();
+ char *kbuf, *vbuf;
+ int ksiz, vsiz;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
+ vbuf = tchexdecode(value, &vsiz);
+ } else if (sep > 0) {
+ kbuf = strtozsv(key, sep, &ksiz);
+ vbuf = strtozsv(value, sep, &vsiz);
} else {
- usage();
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
+ vsiz = strlen(value);
+ vbuf = tcmemdup(value, vsiz);
}
- }
- if(!name || !key || !value) usage();
- char *kbuf, *vbuf;
- int ksiz, vsiz;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- vbuf = tchexdecode(value, &vsiz);
- } else if(sep > 0){
- kbuf = strtozsv(key, sep, &ksiz);
- vbuf = strtozsv(value, sep, &vsiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- vsiz = strlen(value);
- vbuf = tcmemdup(value, vsiz);
- }
- int rv = procput(name, kbuf, ksiz, vbuf, vsiz, dmode);
- tcfree(vbuf);
- tcfree(kbuf);
- return rv;
+ int rv = procput(name, kbuf, ksiz, vbuf, vsiz, dmode);
+ tcfree(vbuf);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of out command */
-static int runout(int argc, char **argv){
- char *name = NULL;
- char *key = NULL;
- bool sx = false;
- int sep = -1;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else if(!strcmp(argv[i], "-sep")){
- if(++i >= argc) usage();
- sep = sepstrtochr(argv[i]);
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!key){
- key = argv[i];
+static int runout(int argc, char **argv) {
+ char *name = NULL;
+ char *key = NULL;
+ bool sx = false;
+ int sep = -1;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else if (!strcmp(argv[i], "-sep")) {
+ if (++i >= argc) usage();
+ sep = sepstrtochr(argv[i]);
+ } else {
+ usage();
+ }
+ } else if (!name) {
+ name = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!name || !key) usage();
+ int ksiz;
+ char *kbuf;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
+ } else if (sep > 0) {
+ kbuf = strtozsv(key, sep, &ksiz);
} else {
- usage();
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
}
- }
- if(!name || !key) usage();
- int ksiz;
- char *kbuf;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- } else if(sep > 0){
- kbuf = strtozsv(key, sep, &ksiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- }
- int rv = procout(name, kbuf, ksiz);
- tcfree(kbuf);
- return rv;
+ int rv = procout(name, kbuf, ksiz);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of get command */
-static int runget(int argc, char **argv){
- char *name = NULL;
- char *key = NULL;
- bool sx = false;
- int sep = -1;
- bool px = false;
- bool pz = false;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else if(!strcmp(argv[i], "-sep")){
- if(++i >= argc) usage();
- sep = sepstrtochr(argv[i]);
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-pz")){
- pz = true;
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!key){
- key = argv[i];
- } else {
- usage();
+static int runget(int argc, char **argv) {
+ char *name = NULL;
+ char *key = NULL;
+ bool sx = false;
+ int sep = -1;
+ bool px = false;
+ bool pz = false;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else if (!strcmp(argv[i], "-sep")) {
+ if (++i >= argc) usage();
+ sep = sepstrtochr(argv[i]);
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-pz")) {
+ pz = true;
+ } else {
+ usage();
+ }
+ } else if (!name) {
+ name = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!name || !key) usage();
- int ksiz;
- char *kbuf;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- } else if(sep > 0){
- kbuf = strtozsv(key, sep, &ksiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- }
- name = tcsprintf("%s#mode=r", name);
- int rv = procget(name, kbuf, ksiz, sep, px, pz);
- tcfree(name);
- tcfree(kbuf);
- return rv;
+ if (!name || !key) usage();
+ int ksiz;
+ char *kbuf;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
+ } else if (sep > 0) {
+ kbuf = strtozsv(key, sep, &ksiz);
+ } else {
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
+ }
+ name = tcsprintf("%s#mode=r", name);
+ int rv = procget(name, kbuf, ksiz, sep, px, pz);
+ tcfree(name);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of list command */
-static int runlist(int argc, char **argv){
- char *name = NULL;
- int sep = -1;
- int max = -1;
- bool pv = false;
- bool px = false;
- char *fmstr = NULL;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-sep")){
- if(++i >= argc) usage();
- sep = sepstrtochr(argv[i]);
- } else if(!strcmp(argv[i], "-m")){
- if(++i >= argc) usage();
- max = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-pv")){
- pv = true;
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-fm")){
- if(++i >= argc) usage();
- fmstr = argv[i];
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else {
- usage();
+static int runlist(int argc, char **argv) {
+ char *name = NULL;
+ int sep = -1;
+ int max = -1;
+ bool pv = false;
+ bool px = false;
+ char *fmstr = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-sep")) {
+ if (++i >= argc) usage();
+ sep = sepstrtochr(argv[i]);
+ } else if (!strcmp(argv[i], "-m")) {
+ if (++i >= argc) usage();
+ max = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-pv")) {
+ pv = true;
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-fm")) {
+ if (++i >= argc) usage();
+ fmstr = argv[i];
+ } else {
+ usage();
+ }
+ } else if (!name) {
+ name = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!name) usage();
- name = tcsprintf("%s#mode=r", name);
- int rv = proclist(name, sep, max, pv, px, fmstr);
- tcfree(name);
- return rv;
+ if (!name) usage();
+ name = tcsprintf("%s#mode=r", name);
+ int rv = proclist(name, sep, max, pv, px, fmstr);
+ tcfree(name);
+ return rv;
}
-
/* parse arguments of optimize command */
-static int runoptimize(int argc, char **argv){
- char *name = NULL;
- char *params = NULL;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!params){
- params = argv[i];
- } else {
- usage();
+static int runoptimize(int argc, char **argv) {
+ char *name = NULL;
+ char *params = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ usage();
+ } else if (!name) {
+ name = argv[i];
+ } else if (!params) {
+ params = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!name) usage();
- int rv = procoptimize(name, params);
- return rv;
+ if (!name) usage();
+ int rv = procoptimize(name, params);
+ return rv;
}
-
/* parse arguments of misc command */
-static int runmisc(int argc, char **argv){
- char *name = NULL;
- char *func = NULL;
- TCLIST *args = tcmpoollistnew(tcmpoolglobal());
- bool sx = false;
- int sep = -1;
- bool px = false;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else if(!strcmp(argv[i], "-sep")){
- if(++i >= argc) usage();
- sep = sepstrtochr(argv[i]);
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!func){
- func = argv[i];
- } else {
- if(sx){
- int size;
- char *buf = tchexdecode(argv[i], &size);
- tclistpush(args, buf, size);
- tcfree(buf);
- } else if(sep > 0){
- int size;
- char *buf = strtozsv(argv[i], sep, &size);
- tclistpush(args, buf, size);
- tcfree(buf);
- } else {
- tclistpush2(args, argv[i]);
- }
+static int runmisc(int argc, char **argv) {
+ char *name = NULL;
+ char *func = NULL;
+ TCLIST *args = tcmpoollistnew(tcmpoolglobal());
+ bool sx = false;
+ int sep = -1;
+ bool px = false;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else if (!strcmp(argv[i], "-sep")) {
+ if (++i >= argc) usage();
+ sep = sepstrtochr(argv[i]);
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else {
+ usage();
+ }
+ } else if (!name) {
+ name = argv[i];
+ } else if (!func) {
+ func = argv[i];
+ } else {
+ if (sx) {
+ int size;
+ char *buf = tchexdecode(argv[i], &size);
+ tclistpush(args, buf, size);
+ tcfree(buf);
+ } else if (sep > 0) {
+ int size;
+ char *buf = strtozsv(argv[i], sep, &size);
+ tclistpush(args, buf, size);
+ tcfree(buf);
+ } else {
+ tclistpush2(args, argv[i]);
+ }
+ }
}
- }
- if(!name || !func) usage();
- int rv = procmisc(name, func, args, sep, px);
- return rv;
+ if (!name || !func) usage();
+ int rv = procmisc(name, func, args, sep, px);
+ return rv;
}
-
/* parse arguments of map command */
-static int runmap(int argc, char **argv){
- char *name = NULL;
- char *dest = NULL;
- char *fmstr = NULL;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-fm")){
- if(++i >= argc) usage();
- fmstr = argv[i];
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!dest){
- dest = argv[i];
- } else {
- usage();
+static int runmap(int argc, char **argv) {
+ char *name = NULL;
+ char *dest = NULL;
+ char *fmstr = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-fm")) {
+ if (++i >= argc) usage();
+ fmstr = argv[i];
+ } else {
+ usage();
+ }
+ } else if (!name) {
+ name = argv[i];
+ } else if (!dest) {
+ dest = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!name || !dest) usage();
- name = tcsprintf("%s#mode=r", name);
- int rv = procmap(name, dest, fmstr);
- tcfree(name);
- return rv;
+ if (!name || !dest) usage();
+ name = tcsprintf("%s#mode=r", name);
+ int rv = procmap(name, dest, fmstr);
+ tcfree(name);
+ return rv;
}
-
/* parse arguments of version command */
-static int runversion(int argc, char **argv){
- int rv = procversion();
- return rv;
+static int runversion(int argc, char **argv) {
+ int rv = procversion();
+ return rv;
}
-
/* perform create command */
-static int proccreate(const char *name){
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- printerr(adb);
- skel.del(skel.opq);
- tcadbdel(adb);
- return 1;
+static int proccreate(const char *name) {
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ printerr(adb);
+ skel.del(skel.opq);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, 8)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ }
+ if (!tcadbopen(adb, name)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
}
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, 8)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
+ bool err = false;
+ if (!tcadbclose(adb)) {
+ printerr(adb);
+ err = true;
}
- name++;
- }
- if(!tcadbopen(adb, name)){
- printerr(adb);
tcadbdel(adb);
- return 1;
- }
- bool err = false;
- if(!tcadbclose(adb)){
- printerr(adb);
- err = true;
- }
- tcadbdel(adb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform inform command */
-static int procinform(const char *name){
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- printerr(adb);
- skel.del(skel.opq);
- tcadbdel(adb);
- return 1;
+static int procinform(const char *name) {
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ printerr(adb);
+ skel.del(skel.opq);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, 8)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
}
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, 8)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
+ if (!tcadbopen(adb, name)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ bool err = false;
+ const char *path = tcadbpath(adb);
+ if (!path) path = "(unknown)";
+ printf("path: %s\n", path);
+ const char *type = "(unknown)";
+ switch (tcadbomode(adb)) {
+ case ADBOVOID: type = "not opened";
+ break;
+ case ADBOMDB: type = "on-memory hash database";
+ break;
+ case ADBONDB: type = "on-memory tree database";
+ break;
+ case ADBOHDB: type = "hash database";
+ break;
+ case ADBOBDB: type = "B+ tree database";
+ break;
+ case ADBOFDB: type = "fixed-length database";
+ break;
+ case ADBOTDB: type = "table database";
+ break;
+ case ADBOSKEL: type = "skeleton database";
+ break;
+ }
+ printf("database type: %s\n", type);
+ printf("record number: %" PRIuMAX "\n", tcadbrnum(adb));
+ printf("size: %" PRIuMAX "\n", tcadbsize(adb));
+ if (!tcadbclose(adb)) {
+ printerr(adb);
+ err = true;
}
- name++;
- }
- if(!tcadbopen(adb, name)){
- printerr(adb);
tcadbdel(adb);
- return 1;
- }
- bool err = false;
- const char *path = tcadbpath(adb);
- if(!path) path = "(unknown)";
- printf("path: %s\n", path);
- const char *type = "(unknown)";
- switch(tcadbomode(adb)){
- case ADBOVOID: type = "not opened"; break;
- case ADBOMDB: type = "on-memory hash database"; break;
- case ADBONDB: type = "on-memory tree database"; break;
- case ADBOHDB: type = "hash database"; break;
- case ADBOBDB: type = "B+ tree database"; break;
- case ADBOFDB: type = "fixed-length database"; break;
- case ADBOTDB: type = "table database"; break;
- case ADBOSKEL: type = "skeleton database"; break;
- }
- printf("database type: %s\n", type);
- printf("record number: %" PRIuMAX "\n", (unsigned long long)tcadbrnum(adb));
- printf("size: %" PRIuMAX "\n", (unsigned long long)tcadbsize(adb));
- if(!tcadbclose(adb)){
- printerr(adb);
- err = true;
- }
- tcadbdel(adb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform put command */
static int procput(const char *name, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- int dmode){
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- printerr(adb);
- skel.del(skel.opq);
- tcadbdel(adb);
- return 1;
- }
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, 8)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
+ int dmode) {
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ printerr(adb);
+ skel.del(skel.opq);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, 8)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
}
- name++;
- }
- if(!tcadbopen(adb, name)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
- }
- bool err = false;
- int inum;
- double dnum;
- switch(dmode){
- case -1:
- if(!tcadbputkeep(adb, kbuf, ksiz, vbuf, vsiz)){
- printerr(adb);
- err = true;
- }
- break;
- case 1:
- if(!tcadbputcat(adb, kbuf, ksiz, vbuf, vsiz)){
- printerr(adb);
- err = true;
- }
- break;
- case 10:
- inum = tcadbaddint(adb, kbuf, ksiz, tcatoi(vbuf));
- if(inum == INT_MIN){
- printerr(adb);
- err = true;
- } else {
- printf("%d\n", inum);
- }
- break;
- case 11:
- dnum = tcadbadddouble(adb, kbuf, ksiz, tcatof(vbuf));
- if(isnan(dnum)){
+ if (!tcadbopen(adb, name)) {
printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ bool err = false;
+ int inum;
+ double dnum;
+ switch (dmode) {
+ case -1:
+ if (!tcadbputkeep(adb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(adb);
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcadbputcat(adb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(adb);
+ err = true;
+ }
+ break;
+ case 10:
+ inum = tcadbaddint(adb, kbuf, ksiz, tcatoi(vbuf));
+ if (inum == INT_MIN) {
+ printerr(adb);
+ err = true;
+ } else {
+ printf("%d\n", inum);
+ }
+ break;
+ case 11:
+ dnum = tcadbadddouble(adb, kbuf, ksiz, tcatof(vbuf));
+ if (isnan(dnum)) {
+ printerr(adb);
+ err = true;
+ } else {
+ printf("%.6f\n", dnum);
+ }
+ break;
+ default:
+ if (!tcadbput(adb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(adb);
+ err = true;
+ }
+ break;
+ }
+ if (!tcadbclose(adb)) {
+ if (!err) printerr(adb);
err = true;
- } else {
- printf("%.6f\n", dnum);
- }
- break;
- default:
- if(!tcadbput(adb, kbuf, ksiz, vbuf, vsiz)){
- printerr(adb);
- err = true;
- }
- break;
- }
- if(!tcadbclose(adb)){
- if(!err) printerr(adb);
- err = true;
- }
- tcadbdel(adb);
- return err ? 1 : 0;
+ }
+ tcadbdel(adb);
+ return err ? 1 : 0;
}
-
/* perform out command */
-static int procout(const char *name, const char *kbuf, int ksiz){
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- printerr(adb);
- skel.del(skel.opq);
- tcadbdel(adb);
- return 1;
+static int procout(const char *name, const char *kbuf, int ksiz) {
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ printerr(adb);
+ skel.del(skel.opq);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, 8)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ }
+ if (!tcadbopen(adb, name)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ bool err = false;
+ if (!tcadbout(adb, kbuf, ksiz)) {
+ printerr(adb);
+ err = true;
}
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, 8)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
+ if (!tcadbclose(adb)) {
+ if (!err) printerr(adb);
+ err = true;
}
- name++;
- }
- if(!tcadbopen(adb, name)){
- printerr(adb);
tcadbdel(adb);
- return 1;
- }
- bool err = false;
- if(!tcadbout(adb, kbuf, ksiz)){
- printerr(adb);
- err = true;
- }
- if(!tcadbclose(adb)){
- if(!err) printerr(adb);
- err = true;
- }
- tcadbdel(adb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform get command */
-static int procget(const char *name, const char *kbuf, int ksiz, int sep, bool px, bool pz){
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- printerr(adb);
- skel.del(skel.opq);
- tcadbdel(adb);
- return 1;
+static int procget(const char *name, const char *kbuf, int ksiz, int sep, bool px, bool pz) {
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ printerr(adb);
+ skel.del(skel.opq);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, 8)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
}
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, 8)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
+ if (!tcadbopen(adb, name)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ bool err = false;
+ int vsiz;
+ char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ printdata(vbuf, vsiz, px, sep);
+ if (!pz) putchar('\n');
+ tcfree(vbuf);
+ } else {
+ printerr(adb);
+ err = true;
+ }
+ if (!tcadbclose(adb)) {
+ if (!err) printerr(adb);
+ err = true;
}
- name++;
- }
- if(!tcadbopen(adb, name)){
- printerr(adb);
tcadbdel(adb);
- return 1;
- }
- bool err = false;
- int vsiz;
- char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
- if(vbuf){
- printdata(vbuf, vsiz, px, sep);
- if(!pz) putchar('\n');
- tcfree(vbuf);
- } else {
- printerr(adb);
- err = true;
- }
- if(!tcadbclose(adb)){
- if(!err) printerr(adb);
- err = true;
- }
- tcadbdel(adb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform list command */
-static int proclist(const char *name, int sep, int max, bool pv, bool px, const char *fmstr){
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- printerr(adb);
- skel.del(skel.opq);
- tcadbdel(adb);
- return 1;
- }
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, 8)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
- }
- name++;
- }
- if(!tcadbopen(adb, name)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
- }
- bool err = false;
- if(fmstr){
- TCLIST *keys = tcadbfwmkeys2(adb, fmstr, max);
- for(int i = 0; i < tclistnum(keys); i++){
- int ksiz;
- const char *kbuf = tclistval(keys, i, &ksiz);
- printdata(kbuf, ksiz, px, sep);
- if(pv){
- int vsiz;
- char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
- if(vbuf){
- putchar('\t');
- printdata(vbuf, vsiz, px, sep);
- tcfree(vbuf);
+static int proclist(const char *name, int sep, int max, bool pv, bool px, const char *fmstr) {
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ printerr(adb);
+ skel.del(skel.opq);
+ tcadbdel(adb);
+ return 1;
}
- }
- putchar('\n');
- }
- tclistdel(keys);
- } else {
- if(!tcadbiterinit(adb)){
- printerr(adb);
- err = true;
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, 8)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
}
- int ksiz;
- char *kbuf;
- int cnt = 0;
- while((kbuf = tcadbiternext(adb, &ksiz)) != NULL){
- printdata(kbuf, ksiz, px, sep);
- if(pv){
- int vsiz;
- char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
- if(vbuf){
- putchar('\t');
- printdata(vbuf, vsiz, px, sep);
- tcfree(vbuf);
+ if (!tcadbopen(adb, name)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ bool err = false;
+ if (fmstr) {
+ TCLIST *keys = tcadbfwmkeys2(adb, fmstr, max);
+ for (int i = 0; i < tclistnum(keys); i++) {
+ int ksiz;
+ const char *kbuf = tclistval(keys, i, &ksiz);
+ printdata(kbuf, ksiz, px, sep);
+ if (pv) {
+ int vsiz;
+ char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ putchar('\t');
+ printdata(vbuf, vsiz, px, sep);
+ tcfree(vbuf);
+ }
+ }
+ putchar('\n');
+ }
+ tclistdel(keys);
+ } else {
+ if (!tcadbiterinit(adb)) {
+ printerr(adb);
+ err = true;
+ }
+ int ksiz;
+ char *kbuf;
+ int cnt = 0;
+ while ((kbuf = tcadbiternext(adb, &ksiz)) != NULL) {
+ printdata(kbuf, ksiz, px, sep);
+ if (pv) {
+ int vsiz;
+ char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ putchar('\t');
+ printdata(vbuf, vsiz, px, sep);
+ tcfree(vbuf);
+ }
+ }
+ putchar('\n');
+ tcfree(kbuf);
+ if (max >= 0 && ++cnt >= max) break;
}
- }
- putchar('\n');
- tcfree(kbuf);
- if(max >= 0 && ++cnt >= max) break;
}
- }
- if(!tcadbclose(adb)){
- if(!err) printerr(adb);
- err = true;
- }
- tcadbdel(adb);
- return err ? 1 : 0;
+ if (!tcadbclose(adb)) {
+ if (!err) printerr(adb);
+ err = true;
+ }
+ tcadbdel(adb);
+ return err ? 1 : 0;
}
-
/* perform optimize command */
-static int procoptimize(const char *name, const char *params){
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- printerr(adb);
- skel.del(skel.opq);
- tcadbdel(adb);
- return 1;
+static int procoptimize(const char *name, const char *params) {
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ printerr(adb);
+ skel.del(skel.opq);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, 8)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ }
+ if (!tcadbopen(adb, name)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ bool err = false;
+ if (!tcadboptimize(adb, params)) {
+ printerr(adb);
+ err = true;
}
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, 8)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
+ if (!tcadbclose(adb)) {
+ if (!err) printerr(adb);
+ err = true;
}
- name++;
- }
- if(!tcadbopen(adb, name)){
- printerr(adb);
tcadbdel(adb);
- return 1;
- }
- bool err = false;
- if(!tcadboptimize(adb, params)){
- printerr(adb);
- err = true;
- }
- if(!tcadbclose(adb)){
- if(!err) printerr(adb);
- err = true;
- }
- tcadbdel(adb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform misc command */
-static int procmisc(const char *name, const char *func, const TCLIST *args, int sep, bool px){
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- printerr(adb);
- skel.del(skel.opq);
- tcadbdel(adb);
- return 1;
+static int procmisc(const char *name, const char *func, const TCLIST *args, int sep, bool px) {
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ printerr(adb);
+ skel.del(skel.opq);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, 8)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
}
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, 8)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
+ if (!tcadbopen(adb, name)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ bool err = false;
+ TCLIST *res = tcadbmisc(adb, func, args);
+ if (res) {
+ for (int i = 0; i < tclistnum(res); i++) {
+ int rsiz;
+ const char *rbuf = tclistval(res, i, &rsiz);
+ printdata(rbuf, rsiz, px, sep);
+ printf("\n");
+ }
+ tclistdel(res);
+ } else {
+ printerr(adb);
+ err = true;
}
- name++;
- }
- if(!tcadbopen(adb, name)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
- }
- bool err = false;
- TCLIST *res = tcadbmisc(adb, func, args);
- if(res){
- for(int i = 0; i < tclistnum(res); i++){
- int rsiz;
- const char *rbuf = tclistval(res, i, &rsiz);
- printdata(rbuf, rsiz, px, sep);
- printf("\n");
+ if (!tcadbclose(adb)) {
+ if (!err) printerr(adb);
+ err = true;
}
- tclistdel(res);
- } else {
- printerr(adb);
- err = true;
- }
- if(!tcadbclose(adb)){
- if(!err) printerr(adb);
- err = true;
- }
- tcadbdel(adb);
- return err ? 1 : 0;
+ tcadbdel(adb);
+ return err ? 1 : 0;
}
-
/* perform map command */
-static int procmap(const char *name, const char *dest, const char *fmstr){
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- printerr(adb);
- skel.del(skel.opq);
- tcadbdel(adb);
- return 1;
+static int procmap(const char *name, const char *dest, const char *fmstr) {
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ printerr(adb);
+ skel.del(skel.opq);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, 8)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
+ }
+ name++;
}
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, 8)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
+ if (!tcadbopen(adb, name)) {
+ printerr(adb);
+ tcadbdel(adb);
+ return 1;
}
- name++;
- }
- if(!tcadbopen(adb, name)){
- printerr(adb);
- tcadbdel(adb);
- return 1;
- }
- bool err = false;
- TCBDB *bdb = tcbdbnew();
- if(!tcbdbopen(bdb, dest, BDBOWRITER | BDBOCREAT | BDBOTRUNC)){
- printerr(adb);
- tcbdbdel(bdb);
- tcadbdel(adb);
- return 1;
- }
- if(fmstr){
- TCLIST *keys = tcadbfwmkeys2(adb, fmstr, -1);
- if(!tcadbmapbdb(adb, keys, bdb, mapbdbproc, NULL, -1)){
- printerr(adb);
- err = true;
+ bool err = false;
+ TCBDB *bdb = tcbdbnew();
+ if (!tcbdbopen(bdb, dest, BDBOWRITER | BDBOCREAT | BDBOTRUNC)) {
+ printerr(adb);
+ tcbdbdel(bdb);
+ tcadbdel(adb);
+ return 1;
+ }
+ if (fmstr) {
+ TCLIST *keys = tcadbfwmkeys2(adb, fmstr, -1);
+ if (!tcadbmapbdb(adb, keys, bdb, mapbdbproc, NULL, -1)) {
+ printerr(adb);
+ err = true;
+ }
+ tclistdel(keys);
+ } else {
+ if (!tcadbmapbdb(adb, NULL, bdb, mapbdbproc, NULL, -1)) {
+ printerr(adb);
+ err = true;
+ }
}
- tclistdel(keys);
- } else {
- if(!tcadbmapbdb(adb, NULL, bdb, mapbdbproc, NULL, -1)){
- printerr(adb);
- err = true;
+ if (!tcbdbclose(bdb)) {
+ printerr(adb);
+ err = true;
}
- }
- if(!tcbdbclose(bdb)){
- printerr(adb);
- err = true;
- }
- tcbdbdel(bdb);
- if(!tcadbclose(adb)){
- printerr(adb);
- err = true;
- }
- tcadbdel(adb);
- return err ? 1 : 0;
+ tcbdbdel(bdb);
+ if (!tcadbclose(adb)) {
+ printerr(adb);
+ err = true;
+ }
+ tcadbdel(adb);
+ return err ? 1 : 0;
}
-
/* perform version command */
-static int procversion(void){
- printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
- tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
- printf("Copyright (C) 2006-2012 FAL Labs\n");
- return 0;
+static int procversion(void) {
+ printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
+ tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
+ printf("Copyright (C) 2006-2012 FAL Labs\n");
+ return 0;
}
#define MULDIVNUM 8 // division number of multiple database
#define RECBUFSIZ 48 // buffer for records
-typedef struct { // type of structure for write thread
- TCADB *adb;
- int rnum;
- int id;
+typedef struct { // type of structure for write thread
+ TCADB *adb;
+ int rnum;
+ int id;
} TARGWRITE;
-typedef struct { // type of structure for read thread
- TCADB *adb;
- int rnum;
- int id;
+typedef struct { // type of structure for read thread
+ TCADB *adb;
+ int rnum;
+ int id;
} TARGREAD;
-typedef struct { // type of structure for remove thread
- TCADB *adb;
- int rnum;
- int id;
+typedef struct { // type of structure for remove thread
+ TCADB *adb;
+ int rnum;
+ int id;
} TARGREMOVE;
/* global variables */
-const char *g_progname; // program name
-unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+unsigned int g_randseed; // random seed
+HANDLE g_dbgfd; // debugging output
/* function prototypes */
static void *threadread(void *targ);
static void *threadremove(void *targ);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- const char *ebuf = getenv("TCRNDSEED");
- g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
- srand(g_randseed);
- ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ const char *ebuf = getenv("TCRNDSEED");
+ g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
+ srand(g_randseed);
+ ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int 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], "remove")){
- rv = runremove(argc, argv);
- } else {
- usage();
- }
- if(rv != 0){
- printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
- for(int i = 0; i < argc; i++){
- printf(" %s", argv[i]);
}
- printf("\n\n");
- }
- return rv;
+ if (argc < 2) usage();
+ int 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], "remove")) {
+ rv = runremove(argc, argv);
+ } else {
+ usage();
+ }
+ if (rv != 0) {
+ printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int) getpid());
+ for (int i = 0; i < argc; i++) {
+ printf(" %s", argv[i]);
+ }
+ printf("\n\n");
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: test cases of the abstract database API of Tokyo Cabinet\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write name tnum rnum\n", g_progname);
- fprintf(stderr, " %s read name tnum\n", g_progname);
- fprintf(stderr, " %s remove name tnum\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: test cases of the abstract database API of Tokyo Cabinet\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s write name tnum rnum\n", g_progname);
+ fprintf(stderr, " %s read name tnum\n", g_progname);
+ fprintf(stderr, " %s remove name tnum\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print formatted information string and flush the buffer */
-static void iprintf(const char *format, ...){
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- fflush(stdout);
- va_end(ap);
+static void iprintf(const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vprintf(format, ap);
+ fflush(stdout);
+ va_end(ap);
}
-
/* print a character and flush the buffer */
-static void iputchar(int c){
- putchar(c);
- fflush(stdout);
+static void iputchar(int c) {
+ putchar(c);
+ fflush(stdout);
}
-
/* print error message of abstract database */
-static void eprint(TCADB *adb, int line, const char *func){
- const char *path = adb ? tcadbpath(adb) : NULL;
- fprintf(stderr, "%s: %s: %d: %s: error\n", g_progname, path ? path : "-", line, func);
+static void eprint(TCADB *adb, int line, const char *func) {
+ const char *path = adb ? tcadbpath(adb) : NULL;
+ fprintf(stderr, "%s: %s: %d: %s: error\n", g_progname, path ? path : "-", line, func);
}
-
/* print system information */
-static void sysprint(void){
- TCMAP *info = tcsysinfo();
- if(info){
- tcmapiterinit(info);
- const char *kbuf;
- while((kbuf = tcmapiternext2(info)) != NULL){
- iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+static void sysprint(void) {
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ tcmapiterinit(info);
+ const char *kbuf;
+ while ((kbuf = tcmapiternext2(info)) != NULL) {
+ iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+ }
+ tcmapdel(info);
}
- tcmapdel(info);
- }
}
-
/* set the transparent skeleton database */
-static void setskeltran(ADBSKEL *skel){
- memset(skel, 0, sizeof(*skel));
- skel->opq = tcadbnew();
- skel->del = (void (*)(void *))tcadbdel;
- skel->open = (bool (*)(void *, const char *))tcadbopen;
- skel->close = (bool (*)(void *))tcadbclose;
- skel->put = (bool (*)(void *, const void *, int, const void *, int))tcadbput;
- skel->putkeep = (bool (*)(void *, const void *, int, const void *, int))tcadbputkeep;
- skel->putcat = (bool (*)(void *, const void *, int, const void *, int))tcadbputcat;
- skel->out = (bool (*)(void *, const void *, int))tcadbout;
- skel->get = (void *(*)(void *, const void *, int, int *))tcadbget;
- skel->vsiz = (int (*)(void *, const void *, int))tcadbvsiz;
- skel->iterinit = (bool (*)(void *))tcadbiterinit;
- skel->iternext = (void *(*)(void *, int *))tcadbiternext;
- skel->fwmkeys = (TCLIST *(*)(void *, const void *, int, int))tcadbfwmkeys;
- skel->addint = (int (*)(void *, const void *, int, int))tcadbaddint;
- skel->adddouble = (double (*)(void *, const void *, int, double))tcadbadddouble;
- skel->sync = (bool (*)(void *))tcadbsync;
- skel->optimize = (bool (*)(void *, const char *))tcadboptimize;
- skel->vanish = (bool (*)(void *))tcadbvanish;
- skel->copy = (bool (*)(void *, const char *))tcadbcopy;
- skel->tranbegin = (bool (*)(void *))tcadbtranbegin;
- skel->trancommit = (bool (*)(void *))tcadbtrancommit;
- skel->tranabort = (bool (*)(void *))tcadbtranabort;
- skel->path = (const char *(*)(void *))tcadbpath;
- skel->rnum = (uint64_t (*)(void *))tcadbrnum;
- skel->size = (uint64_t (*)(void *))tcadbsize;
- skel->misc = (TCLIST *(*)(void *, const char *, const TCLIST *))tcadbmisc;
- skel->putproc =
- (bool (*)(void *, const void *, int, const void *, int, TCPDPROC, void *))tcadbputproc;
- skel->foreach = (bool (*)(void *, TCITER, void *))tcadbforeach;
+static void setskeltran(ADBSKEL *skel) {
+ memset(skel, 0, sizeof (*skel));
+ skel->opq = tcadbnew();
+ skel->del = (void (*)(void *))tcadbdel;
+ skel->open = (bool(*)(void *, const char *))tcadbopen;
+ skel->close = (bool(*)(void *))tcadbclose;
+ skel->put = (bool(*)(void *, const void *, int, const void *, int))tcadbput;
+ skel->putkeep = (bool(*)(void *, const void *, int, const void *, int))tcadbputkeep;
+ skel->putcat = (bool(*)(void *, const void *, int, const void *, int))tcadbputcat;
+ skel->out = (bool(*)(void *, const void *, int))tcadbout;
+ skel->get = (void *(*)(void *, const void *, int, int *))tcadbget;
+ skel->vsiz = (int (*)(void *, const void *, int))tcadbvsiz;
+ skel->iterinit = (bool(*)(void *))tcadbiterinit;
+ skel->iternext = (void *(*)(void *, int *))tcadbiternext;
+ skel->fwmkeys = (TCLIST * (*)(void *, const void *, int, int))tcadbfwmkeys;
+ skel->addint = (int (*)(void *, const void *, int, int))tcadbaddint;
+ skel->adddouble = (double (*)(void *, const void *, int, double))tcadbadddouble;
+ skel->sync = (bool(*)(void *))tcadbsync;
+ skel->optimize = (bool(*)(void *, const char *))tcadboptimize;
+ skel->vanish = (bool(*)(void *))tcadbvanish;
+ skel->copy = (bool(*)(void *, const char *))tcadbcopy;
+ skel->tranbegin = (bool(*)(void *))tcadbtranbegin;
+ skel->trancommit = (bool(*)(void *))tcadbtrancommit;
+ skel->tranabort = (bool(*)(void *))tcadbtranabort;
+ skel->path = (const char *(*)(void *))tcadbpath;
+ skel->rnum = (uint64_t(*)(void *))tcadbrnum;
+ skel->size = (uint64_t(*)(void *))tcadbsize;
+ skel->misc = (TCLIST * (*)(void *, const char *, const TCLIST *))tcadbmisc;
+ skel->putproc =
+ (bool(*)(void *, const void *, int, const void *, int, TCPDPROC, void *))tcadbputproc;
+ skel->foreach = (bool(*)(void *, TCITER, void *))tcadbforeach;
}
-
/* parse arguments of write command */
-static int runwrite(int argc, char **argv){
- char *name = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
+static int runwrite(int argc, char **argv) {
+ char *name = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ usage();
+ } else if (!name) {
+ name = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!name || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int rv = procwrite(name, tnum, rnum);
- return rv;
+ if (!name || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int rv = procwrite(name, tnum, rnum);
+ return rv;
}
-
/* parse arguments of read command */
-static int runread(int argc, char **argv){
- char *name = NULL;
- char *tstr = NULL;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else {
- usage();
+static int runread(int argc, char **argv) {
+ char *name = NULL;
+ char *tstr = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ usage();
+ } else if (!name) {
+ name = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!name || !tstr) usage();
- int tnum = tcatoix(tstr);
- if(tnum < 1) usage();
- int rv = procread(name, tnum);
- return rv;
+ if (!name || !tstr) usage();
+ int tnum = tcatoix(tstr);
+ if (tnum < 1) usage();
+ int rv = procread(name, tnum);
+ return rv;
}
-
/* parse arguments of remove command */
-static int runremove(int argc, char **argv){
- char *name = NULL;
- char *tstr = NULL;
- for(int i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else {
- usage();
+static int runremove(int argc, char **argv) {
+ char *name = NULL;
+ char *tstr = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!name && argv[i][0] == '-') {
+ usage();
+ } else if (!name) {
+ name = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!name || !tstr) usage();
- int tnum = tcatoix(tstr);
- if(tnum < 1) usage();
- int rv = procremove(name, tnum);
- return rv;
+ if (!name || !tstr) usage();
+ int tnum = tcatoix(tstr);
+ if (tnum < 1) usage();
+ int rv = procremove(name, tnum);
+ return rv;
}
-
/* perform write command */
-static int procwrite(const char *name, int tnum, int rnum){
- iprintf("<Writing Test>\n seed=%u name=%s tnum=%d rnum=%d\n\n",
- g_randseed, name, tnum, rnum);
- bool err = false;
- double stime = tctime();
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- eprint(adb, __LINE__, "tcadbsetskel");
- err = true;
- skel.del(skel.opq);
+static int procwrite(const char *name, int tnum, int rnum) {
+ iprintf("<Writing Test>\n seed=%u name=%s tnum=%d rnum=%d\n\n",
+ g_randseed, name, tnum, rnum);
+ bool err = false;
+ double stime = tctime();
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ eprint(adb, __LINE__, "tcadbsetskel");
+ err = true;
+ skel.del(skel.opq);
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, MULDIVNUM)) {
+ eprint(adb, __LINE__, "tcadbsetskelmulti");
+ err = true;
+ }
+ name++;
}
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, MULDIVNUM)){
- eprint(adb, __LINE__, "tcadbsetskelmulti");
- err = true;
- }
- name++;
- }
- if(!tcadbopen(adb, name)){
- eprint(adb, __LINE__, "tcadbopen");
- err = true;
- }
- TARGWRITE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].adb = adb;
- targs[0].rnum = rnum;
- targs[0].id = 0;
- if(threadwrite(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].adb = adb;
- targs[i].rnum = rnum;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadwrite, targs + i) != 0){
- eprint(adb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ if (!tcadbopen(adb, name)) {
+ eprint(adb, __LINE__, "tcadbopen");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(adb, __LINE__, "pthread_join");
- err = true;
- } else if(rv){
+ TARGWRITE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].adb = adb;
+ targs[0].rnum = rnum;
+ targs[0].id = 0;
+ if (threadwrite(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].adb = adb;
+ targs[i].rnum = rnum;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadwrite, targs + i) != 0) {
+ eprint(adb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(adb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcadbrnum(adb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcadbsize(adb));
+ sysprint();
+ if (!tcadbclose(adb)) {
+ eprint(adb, __LINE__, "tcadbclose");
err = true;
- }
}
- }
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcadbrnum(adb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcadbsize(adb));
- sysprint();
- if(!tcadbclose(adb)){
- eprint(adb, __LINE__, "tcadbclose");
- err = true;
- }
- tcadbdel(adb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ tcadbdel(adb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform read command */
-static int procread(const char *name, int tnum){
- iprintf("<Reading Test>\n seed=%u name=%s tnum=%d\n\n", g_randseed, name, tnum);
- bool err = false;
- double stime = tctime();
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- eprint(adb, __LINE__, "tcadbsetskel");
- err = true;
- skel.del(skel.opq);
+static int procread(const char *name, int tnum) {
+ iprintf("<Reading Test>\n seed=%u name=%s tnum=%d\n\n", g_randseed, name, tnum);
+ bool err = false;
+ double stime = tctime();
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ eprint(adb, __LINE__, "tcadbsetskel");
+ err = true;
+ skel.del(skel.opq);
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, MULDIVNUM)) {
+ eprint(adb, __LINE__, "tcadbsetskelmulti");
+ err = true;
+ }
+ name++;
}
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, MULDIVNUM)){
- eprint(adb, __LINE__, "tcadbsetskelmulti");
- err = true;
- }
- name++;
- }
- if(!tcadbopen(adb, name)){
- eprint(adb, __LINE__, "tcadbopen");
- err = true;
- }
- int rnum = tcadbrnum(adb) / tnum;
- TARGREAD targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].adb = adb;
- targs[0].rnum = rnum;
- targs[0].id = 0;
- if(threadread(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].adb = adb;
- targs[i].rnum = rnum;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadread, targs + i) != 0){
- eprint(adb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ if (!tcadbopen(adb, name)) {
+ eprint(adb, __LINE__, "tcadbopen");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(adb, __LINE__, "pthread_join");
- err = true;
- } else if(rv){
+ int rnum = tcadbrnum(adb) / tnum;
+ TARGREAD targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].adb = adb;
+ targs[0].rnum = rnum;
+ targs[0].id = 0;
+ if (threadread(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].adb = adb;
+ targs[i].rnum = rnum;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadread, targs + i) != 0) {
+ eprint(adb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(adb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcadbrnum(adb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcadbsize(adb));
+ sysprint();
+ if (!tcadbclose(adb)) {
+ eprint(adb, __LINE__, "tcadbclose");
err = true;
- }
}
- }
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcadbrnum(adb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcadbsize(adb));
- sysprint();
- if(!tcadbclose(adb)){
- eprint(adb, __LINE__, "tcadbclose");
- err = true;
- }
- tcadbdel(adb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ tcadbdel(adb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform remove command */
-static int procremove(const char *name, int tnum){
- iprintf("<Removing Test>\n seed=%u name=%s tnum=%d\n\n", g_randseed, name, tnum);
- bool err = false;
- double stime = tctime();
- TCADB *adb = tcadbnew();
- ADBSKEL skel;
- if(*name == '@'){
- setskeltran(&skel);
- if(!tcadbsetskel(adb, &skel)){
- eprint(adb, __LINE__, "tcadbsetskel");
- err = true;
- skel.del(skel.opq);
- }
- name++;
- } else if(*name == '%'){
- if(!tcadbsetskelmulti(adb, MULDIVNUM)){
- eprint(adb, __LINE__, "tcadbsetskelmulti");
- err = true;
+static int procremove(const char *name, int tnum) {
+ iprintf("<Removing Test>\n seed=%u name=%s tnum=%d\n\n", g_randseed, name, tnum);
+ bool err = false;
+ double stime = tctime();
+ TCADB *adb = tcadbnew();
+ ADBSKEL skel;
+ if (*name == '@') {
+ setskeltran(&skel);
+ if (!tcadbsetskel(adb, &skel)) {
+ eprint(adb, __LINE__, "tcadbsetskel");
+ err = true;
+ skel.del(skel.opq);
+ }
+ name++;
+ } else if (*name == '%') {
+ if (!tcadbsetskelmulti(adb, MULDIVNUM)) {
+ eprint(adb, __LINE__, "tcadbsetskelmulti");
+ err = true;
+ }
+ name++;
}
- name++;
- }
- if(!tcadbopen(adb, name)){
- eprint(adb, __LINE__, "tcadbopen");
- err = true;
- }
- int rnum = tcadbrnum(adb) / tnum;
- TARGREMOVE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].adb = adb;
- targs[0].rnum = rnum;
- targs[0].id = 0;
- if(threadremove(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].adb = adb;
- targs[i].rnum = rnum;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadremove, targs + i) != 0){
- eprint(adb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ if (!tcadbopen(adb, name)) {
+ eprint(adb, __LINE__, "tcadbopen");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(adb, __LINE__, "pthread_join");
- err = true;
- } else if(rv){
+ int rnum = tcadbrnum(adb) / tnum;
+ TARGREMOVE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].adb = adb;
+ targs[0].rnum = rnum;
+ targs[0].id = 0;
+ if (threadremove(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].adb = adb;
+ targs[i].rnum = rnum;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadremove, targs + i) != 0) {
+ eprint(adb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(adb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcadbrnum(adb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcadbsize(adb));
+ sysprint();
+ if (!tcadbclose(adb)) {
+ eprint(adb, __LINE__, "tcadbclose");
err = true;
- }
}
- }
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcadbrnum(adb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcadbsize(adb));
- sysprint();
- if(!tcadbclose(adb)){
- eprint(adb, __LINE__, "tcadbclose");
- err = true;
- }
- tcadbdel(adb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ tcadbdel(adb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* thread the write function */
-static void *threadwrite(void *targ){
- TCADB *adb = ((TARGWRITE *)targ)->adb;
- int rnum = ((TARGWRITE *)targ)->rnum;
- int id = ((TARGWRITE *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", base + i + 1);
- if(!tcadbput(adb, buf, len, buf, len)){
- eprint(adb, __LINE__, "tcadbput");
- err = true;
- break;
- }
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+static void *threadwrite(void *targ) {
+ TCADB *adb = ((TARGWRITE *) targ)->adb;
+ int rnum = ((TARGWRITE *) targ)->rnum;
+ int id = ((TARGWRITE *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", base + i + 1);
+ if (!tcadbput(adb, buf, len, buf, len)) {
+ eprint(adb, __LINE__, "tcadbput");
+ err = true;
+ break;
+ }
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
}
- }
- return err ? "error" : NULL;
+ return err ? "error" : NULL;
}
-
/* thread the read function */
-static void *threadread(void *targ){
- TCADB *adb = ((TARGREAD *)targ)->adb;
- int rnum = ((TARGREAD *)targ)->rnum;
- int id = ((TARGREAD *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", base + i + 1);
- int vsiz;
- char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
- if(!vbuf){
- eprint(adb, __LINE__, "tcadbget");
- err = true;
- }
- tcfree(vbuf);
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+static void *threadread(void *targ) {
+ TCADB *adb = ((TARGREAD *) targ)->adb;
+ int rnum = ((TARGREAD *) targ)->rnum;
+ int id = ((TARGREAD *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", base + i + 1);
+ int vsiz;
+ char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
+ if (!vbuf) {
+ eprint(adb, __LINE__, "tcadbget");
+ err = true;
+ }
+ tcfree(vbuf);
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
}
- }
- return err ? "error" : NULL;
+ return err ? "error" : NULL;
}
-
/* thread the remove function */
-static void *threadremove(void *targ){
- TCADB *adb = ((TARGREMOVE *)targ)->adb;
- int rnum = ((TARGREMOVE *)targ)->rnum;
- int id = ((TARGREMOVE *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", base + i + 1);
- if(!tcadbout(adb, kbuf, ksiz)){
- eprint(adb, __LINE__, "tcadbout");
- err = true;
- break;
- }
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+static void *threadremove(void *targ) {
+ TCADB *adb = ((TARGREMOVE *) targ)->adb;
+ int rnum = ((TARGREMOVE *) targ)->rnum;
+ int id = ((TARGREMOVE *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", base + i + 1);
+ if (!tcadbout(adb, kbuf, ksiz)) {
+ eprint(adb, __LINE__, "tcadbout");
+ err = true;
+ break;
+ }
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
}
- }
- return err ? "error" : NULL;
+ return err ? "error" : NULL;
}
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcadbrnum(adb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcadbsize(adb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcadbrnum(adb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcadbsize(adb));
sysprint();
if(!tcadbclose(adb)){
eprint(adb, __LINE__, "tcadbclose");
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcadbrnum(adb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcadbsize(adb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcadbrnum(adb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcadbsize(adb));
sysprint();
if(!tcadbclose(adb)){
eprint(adb, __LINE__, "tcadbclose");
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcadbrnum(adb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcadbsize(adb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcadbrnum(adb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcadbsize(adb));
sysprint();
if(!tcadbclose(adb)){
eprint(adb, __LINE__, "tcadbclose");
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcadbrnum(adb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcadbsize(adb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcadbrnum(adb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcadbsize(adb));
sysprint();
if(!tcadbclose(adb)){
eprint(adb, __LINE__, "tcadbclose");
eprint(adb, __LINE__, "tcadbforeach");
err = true;
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcadbrnum(adb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcadbsize(adb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcadbrnum(adb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcadbsize(adb));
sysprint();
if(!tcadbclose(adb)){
eprint(adb, __LINE__, "tcadbclose");
eprint(adb, __LINE__, "(validation)");
err = true;
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcadbrnum(adb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcadbsize(adb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcadbrnum(adb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcadbsize(adb));
sysprint();
tcmapdel(map);
if(!tcadbclose(adb)){
/* set the footer of HTML */
static void sethtmlfooter(PARAMS *params, TCXSTR *obuf, TCADB *db){
XP("<hr />\n");
- XP("<div>record number: %" PRIdMAX "</div>\n", (long long)tcadbrnum(db));
- XP("<div>size: %" PRIdMAX "</div>\n", (long long)tcadbsize(db));
+ XP("<div>record number: %" PRIdMAX "</div>\n", (int64_t)tcadbrnum(db));
+ XP("<div>size: %" PRIdMAX "</div>\n", (int64_t)tcadbsize(db));
XP("</body>\n");
XP("\n");
XP("</html>\n");
}
}
bool err = false;
- step = sprintf(hbuf, "%" PRIxMAX "", (unsigned long long) leaf->id);
+ step = sprintf(hbuf, "%" PRIxMAX "", (uint64_t) leaf->id);
if (ln < 1 && !tchdbout(bdb->hdb, hbuf, step) && tchdbecode(bdb->hdb) != TCENOREC)
err = true;
if (!leaf->dead && !tchdbput(bdb->hdb, hbuf, step, TCXSTRPTR(rbuf), TCXSTRSIZE(rbuf)))
TCDODEBUG(bdb->cnt_loadleaf++);
char hbuf[(sizeof (uint64_t) + 1)*3];
int step;
- step = sprintf(hbuf, "%" PRIxMAX "", (unsigned long long) id);
+ step = sprintf(hbuf, "%" PRIxMAX "", (uint64_t) id);
char *rbuf = NULL;
char wbuf[BDBPAGEBUFSIZ];
const char *rp = NULL;
if (clk) BDBUNLOCKCACHE(bdb);
if (leaf) return true;
char hbuf[(sizeof (uint64_t) + 1)*3];
- int step = sprintf(hbuf, "%" PRIxMAX "", (unsigned long long) id);
+ int step = sprintf(hbuf, "%" PRIxMAX "", (uint64_t) id);
return tchdbvsiz(bdb->hdb, hbuf, step) > 0;
}
TCXSTRCAT(rbuf, ebuf, idx->ksiz);
}
bool err = false;
- step = sprintf(hbuf, "#%" PRIxMAX "", (unsigned long long) (node->id - BDBNODEIDBASE));
+ step = sprintf(hbuf, "#%" PRIxMAX "", (uint64_t) (node->id - BDBNODEIDBASE));
if (ln < 1 && !tchdbout(bdb->hdb, hbuf, step) && tchdbecode(bdb->hdb) != TCENOREC)
err = true;
if (!node->dead && !tchdbput(bdb->hdb, hbuf, step, TCXSTRPTR(rbuf), TCXSTRSIZE(rbuf)))
TCDODEBUG(bdb->cnt_loadnode++);
char hbuf[(sizeof (uint64_t) + 1)*2];
int step;
- step = sprintf(hbuf, "#%" PRIxMAX "", (unsigned long long) (id - BDBNODEIDBASE));
+ step = sprintf(hbuf, "#%" PRIxMAX "", (uint64_t) (id - BDBNODEIDBASE));
char *rbuf = NULL;
char wbuf[BDBPAGEBUFSIZ];
const char *rp = NULL;
wp += sprintf(wp, " lmemb=%u", bdb->lmemb);
wp += sprintf(wp, " nmemb=%u", bdb->nmemb);
wp += sprintf(wp, " opts=%u", bdb->opts);
- wp += sprintf(wp, " root=%" PRIxMAX "", (unsigned long long) bdb->root);
- wp += sprintf(wp, " first=%" PRIxMAX "", (unsigned long long) bdb->first);
- wp += sprintf(wp, " last=%" PRIxMAX "", (unsigned long long) bdb->last);
- wp += sprintf(wp, " lnum=%" PRIuMAX "", (unsigned long long) bdb->lnum);
- wp += sprintf(wp, " nnum=%" PRIuMAX "", (unsigned long long) bdb->nnum);
- wp += sprintf(wp, " rnum=%" PRIuMAX "", (unsigned long long) bdb->rnum);
+ wp += sprintf(wp, " root=%" PRIxMAX "", (uint64_t) bdb->root);
+ wp += sprintf(wp, " first=%" PRIxMAX "", (uint64_t) bdb->first);
+ wp += sprintf(wp, " last=%" PRIxMAX "", (uint64_t) bdb->last);
+ wp += sprintf(wp, " lnum=%" PRIuMAX "", (uint64_t) bdb->lnum);
+ wp += sprintf(wp, " nnum=%" PRIuMAX "", (uint64_t) bdb->nnum);
+ wp += sprintf(wp, " rnum=%" PRIuMAX "", (uint64_t) bdb->rnum);
wp += sprintf(wp, " leafc=%p", (void *) bdb->leafc);
wp += sprintf(wp, " nodec=%p", (void *) bdb->nodec);
wp += sprintf(wp, " cmp=%p", (void *) (intptr_t) bdb->cmp);
wp += sprintf(wp, " ncnum=%u", bdb->ncnum);
wp += sprintf(wp, " lsmax=%u", bdb->lsmax);
wp += sprintf(wp, " lschk=%u", bdb->lschk);
- wp += sprintf(wp, " capnum=%" PRIuMAX "", (unsigned long long) bdb->capnum);
+ wp += sprintf(wp, " capnum=%" PRIuMAX "", (uint64_t) bdb->capnum);
wp += sprintf(wp, " hist=%p", (void *) bdb->hist);
wp += sprintf(wp, " hnum=%d", bdb->hnum);
- wp += sprintf(wp, " hleaf=%" PRIuMAX "", (unsigned long long) bdb->hleaf);
- wp += sprintf(wp, " lleaf=%" PRIuMAX "", (unsigned long long) bdb->lleaf);
+ wp += sprintf(wp, " hleaf=%" PRIuMAX "", (uint64_t) bdb->hleaf);
+ wp += sprintf(wp, " lleaf=%" PRIuMAX "", (uint64_t) bdb->lleaf);
wp += sprintf(wp, " tran=%d", bdb->tran);
//wp += sprintf(wp, " rbopaque=%p", (void *)bdb->rbopaque);
- wp += sprintf(wp, " clock=%" PRIuMAX "", (unsigned long long) bdb->clock);
- wp += sprintf(wp, " cnt_saveleaf=%" PRIdMAX "", (long long) bdb->cnt_saveleaf);
- wp += sprintf(wp, " cnt_loadleaf=%" PRIdMAX "", (long long) bdb->cnt_loadleaf);
- wp += sprintf(wp, " cnt_killleaf=%" PRIdMAX "", (long long) bdb->cnt_killleaf);
- wp += sprintf(wp, " cnt_adjleafc=%" PRIdMAX "", (long long) bdb->cnt_adjleafc);
- wp += sprintf(wp, " cnt_savenode=%" PRIdMAX "", (long long) bdb->cnt_savenode);
- wp += sprintf(wp, " cnt_loadnode=%" PRIdMAX "", (long long) bdb->cnt_loadnode);
- wp += sprintf(wp, " cnt_adjnodec=%" PRIdMAX "", (long long) bdb->cnt_adjnodec);
+ wp += sprintf(wp, " clock=%" PRIuMAX "", (uint64_t) bdb->clock);
+ wp += sprintf(wp, " cnt_saveleaf=%" PRIdMAX "", (int64_t) bdb->cnt_saveleaf);
+ wp += sprintf(wp, " cnt_loadleaf=%" PRIdMAX "", (int64_t) bdb->cnt_loadleaf);
+ wp += sprintf(wp, " cnt_killleaf=%" PRIdMAX "", (int64_t) bdb->cnt_killleaf);
+ wp += sprintf(wp, " cnt_adjleafc=%" PRIdMAX "", (int64_t) bdb->cnt_adjleafc);
+ wp += sprintf(wp, " cnt_savenode=%" PRIdMAX "", (int64_t) bdb->cnt_savenode);
+ wp += sprintf(wp, " cnt_loadnode=%" PRIdMAX "", (int64_t) bdb->cnt_loadnode);
+ wp += sprintf(wp, " cnt_adjnodec=%" PRIdMAX "", (int64_t) bdb->cnt_adjnodec);
*(wp++) = '\n';
tcwrite(dbgfd, buf, wp - buf);
}
char buf[BDBPAGEBUFSIZ];
char *wp = buf;
wp += sprintf(wp, "LEAF:");
- wp += sprintf(wp, " id:%" PRIxMAX "", (unsigned long long) leaf->id);
+ wp += sprintf(wp, " id:%" PRIxMAX "", (uint64_t) leaf->id);
wp += sprintf(wp, " size:%u", leaf->size);
- wp += sprintf(wp, " prev:%" PRIxMAX "", (unsigned long long) leaf->prev);
- wp += sprintf(wp, " next:%" PRIxMAX "", (unsigned long long) leaf->next);
+ wp += sprintf(wp, " prev:%" PRIxMAX "", (uint64_t) leaf->prev);
+ wp += sprintf(wp, " next:%" PRIxMAX "", (uint64_t) leaf->next);
wp += sprintf(wp, " dirty:%d", leaf->dirty);
wp += sprintf(wp, " dead:%d", leaf->dead);
wp += sprintf(wp, " rnum:%d", TCPTRLISTNUM(recs));
char buf[BDBPAGEBUFSIZ];
char *wp = buf;
wp += sprintf(wp, "NODE:");
- wp += sprintf(wp, " id:%" PRIxMAX "", (unsigned long long) node->id);
- wp += sprintf(wp, " heir:%" PRIxMAX "", (unsigned long long) node->heir);
+ wp += sprintf(wp, " id:%" PRIxMAX "", (uint64_t) node->id);
+ wp += sprintf(wp, " heir:%" PRIxMAX "", (uint64_t) node->heir);
wp += sprintf(wp, " dirty:%d", node->dirty);
wp += sprintf(wp, " dead:%d", node->dead);
wp += sprintf(wp, " rnum:%d", TCPTRLISTNUM(idxs));
wp = buf;
BDBIDX *idx = TCPTRLISTVAL(idxs, i);
char *ebuf = (char *) idx + sizeof (*idx);
- wp += sprintf(wp, " [%" PRIxMAX ":%s]", (unsigned long long) idx->pid, ebuf);
+ wp += sprintf(wp, " [%" PRIxMAX ":%s]", (uint64_t) idx->pid, ebuf);
}
*(wp++) = '\n';
tcwrite(dbgfd, buf, wp - buf);
printf("\n");
printf("max leaf member: %d\n", tcbdblmemb(bdb));
printf("max node member: %d\n", tcbdbnmemb(bdb));
- printf("leaf number: %" PRIuMAX "\n", (unsigned long long)tcbdblnum(bdb));
- printf("node number: %" PRIuMAX "\n", (unsigned long long)tcbdbnnum(bdb));
- printf("bucket number: %" PRIuMAX "\n", (unsigned long long)tcbdbbnum(bdb));
+ printf("leaf number: %" PRIuMAX "\n", (uint64_t)tcbdblnum(bdb));
+ printf("node number: %" PRIuMAX "\n", (uint64_t)tcbdbnnum(bdb));
+ printf("bucket number: %" PRIuMAX "\n", (uint64_t)tcbdbbnum(bdb));
#ifndef NDEBUG
if(bdb->hdb->cnt_writerec >= 0)
- printf("used bucket number: %" PRIdMAX "\n", (long long)tcbdbbnumused(bdb));
-#endif
+ printf("used bucket number: %" PRIdMAX "\n", (int64_t) tcbdbbnumused(bdb));
+#endif
printf("alignment: %u\n", tcbdbalign(bdb));
printf("free block pool: %u\n", tcbdbfbpmax(bdb));
- printf("inode number: %" PRIdMAX "\n", (long long)tcbdbinode(bdb));
+ printf("inode number: %" PRIdMAX "\n", (int64_t) tcbdbinode(bdb));
char date[48];
tcdatestrwww(tcbdbmtime(bdb), INT_MAX, date);
printf("modified time: %s\n", date);
if(opts & BDBTTCBS) printf(" tcbs");
if(opts & BDBTEXCODEC) printf(" excodec");
printf("\n");
- printf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- printf("file size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ printf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ printf("file size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
if(!tcbdbclose(bdb)){
if(!err) printerr(bdb);
err = true;
if(bdb->hdb->cnt_writerec < 0) return;
iprintf("max leaf member: %d\n", tcbdblmemb(bdb));
iprintf("max node member: %d\n", tcbdbnmemb(bdb));
- iprintf("leaf number: %" PRIdMAX "\n", (long long)tcbdblnum(bdb));
- iprintf("node number: %" PRIdMAX "\n", (long long)tcbdbnnum(bdb));
- iprintf("bucket number: %" PRIdMAX "\n", (long long)tcbdbbnum(bdb));
- iprintf("used bucket number: %" PRIdMAX "\n", (long long)tcbdbbnumused(bdb));
- iprintf("cnt_saveleaf: %" PRIdMAX "\n", (long long)bdb->cnt_saveleaf);
- iprintf("cnt_loadleaf: %" PRIdMAX "\n", (long long)bdb->cnt_loadleaf);
- iprintf("cnt_killleaf: %" PRIdMAX "\n", (long long)bdb->cnt_killleaf);
- iprintf("cnt_adjleafc: %" PRIdMAX "\n", (long long)bdb->cnt_adjleafc);
- iprintf("cnt_savenode: %" PRIdMAX "\n", (long long)bdb->cnt_savenode);
- iprintf("cnt_loadnode: %" PRIdMAX "\n", (long long)bdb->cnt_loadnode);
- iprintf("cnt_adjnodec: %" PRIdMAX "\n", (long long)bdb->cnt_adjnodec);
- iprintf("cnt_writerec: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_writerec);
- iprintf("cnt_reuserec: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_reuserec);
- iprintf("cnt_moverec: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_moverec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_readrec);
- iprintf("cnt_searchfbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_searchfbp);
- iprintf("cnt_insertfbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_insertfbp);
- iprintf("cnt_splicefbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_splicefbp);
- iprintf("cnt_dividefbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_dividefbp);
- iprintf("cnt_mergefbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_mergefbp);
- iprintf("cnt_reducefbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_reducefbp);
- iprintf("cnt_appenddrp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_appenddrp);
- iprintf("cnt_deferdrp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_deferdrp);
- iprintf("cnt_flushdrp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_flushdrp);
- iprintf("cnt_adjrecc: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_adjrecc);
- iprintf("cnt_defrag: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_defrag);
- iprintf("cnt_shiftrec: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_shiftrec);
- iprintf("cnt_trunc: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_trunc);
+ iprintf("leaf number: %" PRIdMAX "\n", (int64_t)tcbdblnum(bdb));
+ iprintf("node number: %" PRIdMAX "\n", (int64_t)tcbdbnnum(bdb));
+ iprintf("bucket number: %" PRIdMAX "\n", (int64_t)tcbdbbnum(bdb));
+ iprintf("used bucket number: %" PRIdMAX "\n", (int64_t)tcbdbbnumused(bdb));
+ iprintf("cnt_saveleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_saveleaf);
+ iprintf("cnt_loadleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_loadleaf);
+ iprintf("cnt_killleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_killleaf);
+ iprintf("cnt_adjleafc: %" PRIdMAX "\n", (int64_t)bdb->cnt_adjleafc);
+ iprintf("cnt_savenode: %" PRIdMAX "\n", (int64_t)bdb->cnt_savenode);
+ iprintf("cnt_loadnode: %" PRIdMAX "\n", (int64_t)bdb->cnt_loadnode);
+ iprintf("cnt_adjnodec: %" PRIdMAX "\n", (int64_t)bdb->cnt_adjnodec);
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_writerec);
+ iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_reuserec);
+ iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_moverec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_readrec);
+ iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_searchfbp);
+ iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_insertfbp);
+ iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_splicefbp);
+ iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_dividefbp);
+ iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_mergefbp);
+ iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_reducefbp);
+ iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_appenddrp);
+ iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_deferdrp);
+ iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_flushdrp);
+ iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_adjrecc);
+ iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_defrag);
+ iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_shiftrec);
+ iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_trunc);
}
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
}
tcmapdel(map);
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
if(bdb->hdb->cnt_writerec < 0) return;
iprintf("max leaf member: %d\n", tcbdblmemb(bdb));
iprintf("max node member: %d\n", tcbdbnmemb(bdb));
- iprintf("leaf number: %" PRIdMAX "\n", (long long)tcbdblnum(bdb));
- iprintf("node number: %" PRIdMAX "\n", (long long)tcbdbnnum(bdb));
- iprintf("bucket number: %" PRIdMAX "\n", (long long)tcbdbbnum(bdb));
- iprintf("used bucket number: %" PRIdMAX "\n", (long long)tcbdbbnumused(bdb));
- iprintf("cnt_saveleaf: %" PRIdMAX "\n", (long long)bdb->cnt_saveleaf);
- iprintf("cnt_loadleaf: %" PRIdMAX "\n", (long long)bdb->cnt_loadleaf);
- iprintf("cnt_killleaf: %" PRIdMAX "\n", (long long)bdb->cnt_killleaf);
- iprintf("cnt_adjleafc: %" PRIdMAX "\n", (long long)bdb->cnt_adjleafc);
- iprintf("cnt_savenode: %" PRIdMAX "\n", (long long)bdb->cnt_savenode);
- iprintf("cnt_loadnode: %" PRIdMAX "\n", (long long)bdb->cnt_loadnode);
- iprintf("cnt_adjnodec: %" PRIdMAX "\n", (long long)bdb->cnt_adjnodec);
- iprintf("cnt_writerec: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_writerec);
- iprintf("cnt_reuserec: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_reuserec);
- iprintf("cnt_moverec: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_moverec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_readrec);
- iprintf("cnt_searchfbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_searchfbp);
- iprintf("cnt_insertfbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_insertfbp);
- iprintf("cnt_splicefbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_splicefbp);
- iprintf("cnt_dividefbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_dividefbp);
- iprintf("cnt_mergefbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_mergefbp);
- iprintf("cnt_reducefbp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_reducefbp);
- iprintf("cnt_appenddrp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_appenddrp);
- iprintf("cnt_deferdrp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_deferdrp);
- iprintf("cnt_flushdrp: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_flushdrp);
- iprintf("cnt_adjrecc: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_adjrecc);
- iprintf("cnt_defrag: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_defrag);
- iprintf("cnt_shiftrec: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_shiftrec);
- iprintf("cnt_trunc: %" PRIdMAX "\n", (long long)bdb->hdb->cnt_trunc);
+ iprintf("leaf number: %" PRIdMAX "\n", (int64_t)tcbdblnum(bdb));
+ iprintf("node number: %" PRIdMAX "\n", (int64_t)tcbdbnnum(bdb));
+ iprintf("bucket number: %" PRIdMAX "\n", (int64_t)tcbdbbnum(bdb));
+ iprintf("used bucket number: %" PRIdMAX "\n", (int64_t)tcbdbbnumused(bdb));
+ iprintf("cnt_saveleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_saveleaf);
+ iprintf("cnt_loadleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_loadleaf);
+ iprintf("cnt_killleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_killleaf);
+ iprintf("cnt_adjleafc: %" PRIdMAX "\n", (int64_t)bdb->cnt_adjleafc);
+ iprintf("cnt_savenode: %" PRIdMAX "\n", (int64_t)bdb->cnt_savenode);
+ iprintf("cnt_loadnode: %" PRIdMAX "\n", (int64_t)bdb->cnt_loadnode);
+ iprintf("cnt_adjnodec: %" PRIdMAX "\n", (int64_t)bdb->cnt_adjnodec);
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_writerec);
+ iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_reuserec);
+ iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_moverec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_readrec);
+ iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_searchfbp);
+ iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_insertfbp);
+ iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_splicefbp);
+ iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_dividefbp);
+ iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_mergefbp);
+ iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_reducefbp);
+ iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_appenddrp);
+ iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_deferdrp);
+ iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_flushdrp);
+ iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_adjrecc);
+ iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_defrag);
+ iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_shiftrec);
+ iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_trunc);
}
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
break;
}
tcbdbcurdel(cur);
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
err = true;
}
tcbdbcurdel(cur);
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
if(!tcbdbclose(bdb)){
err = true;
}
tcbdbcurdel(cur);
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcbdbfsiz(bdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
mprint(bdb);
sysprint();
tcmapdel(map);
static bool tcfdbcopyimpl(TCFDB *fdb, const char *path);
static bool tcfdbiterjumpimpl(TCFDB *fdb, int64_t id);
static bool tcfdbforeachimpl(TCFDB *fdb, TCITER iter, void *op);
-static bool tcfdbftruncate(TCFDB *fdb, off_t length);
+static bool tcfdbftruncate(TCFDB *fdb, off_t length) __attribute__ ((unused));
static bool tcfdbftruncate2(TCFDB *fdb, off_t length, int opts);
EJDB_INLINE bool tcfdblockmethod(TCFDB *fdb, bool wr);
uint64_t id = tcfdbiternext(fdb);
if (id < 1) return NULL;
char kbuf[TCNUMBUFSIZ];
- int ksiz = sprintf(kbuf, "%" PRIuMAX "", (unsigned long long) id);
+ int ksiz = sprintf(kbuf, "%" PRIuMAX "", (uint64_t) id);
*sp = ksiz;
return tcmemdup(kbuf, ksiz);
}
TCLIST *keys = tclistnew2(num);
for (int i = 0; i < num; i++) {
char kbuf[TCNUMBUFSIZ];
- int ksiz = sprintf(kbuf, "%" PRIuMAX "", (unsigned long long) ids[i]);
+ int ksiz = sprintf(kbuf, "%" PRIuMAX "", (uint64_t) ids[i]);
TCLISTPUSH(keys, kbuf, ksiz);
}
TCFREE(ids);
TCLIST *keys = tclistnew2(num);
for (int i = 0; i < num; i++) {
char kbuf[TCNUMBUFSIZ];
- int ksiz = sprintf(kbuf, "%" PRIuMAX "", (unsigned long long) ids[i]);
+ int ksiz = sprintf(kbuf, "%" PRIuMAX "", (uint64_t) ids[i]);
TCLISTPUSH(keys, kbuf, ksiz);
}
TCFREE(ids);
fdb->max = 0;
fdb->iter = 0;
fdb->map = NULL;
+#ifdef _WIN32
fdb->w32hmap = NULL;
+#endif
fdb->ecode = TCESUCCESS;
fdb->fatal = false;
fdb->inode = 0;
}
if (*path == '@') {
char tsbuf[TCNUMBUFSIZ];
- sprintf(tsbuf, "%" PRIuMAX "", (unsigned long long) (tctime() * 1000000));
+ sprintf(tsbuf, "%" PRIuMAX "", (uint64_t) (tctime() * 1000000));
const char *args[3];
args[0] = path + 1;
args[1] = fdb->path;
FDBUNLOCKSMEM(fdb);
if (vbuf) {
char kbuf[TCNUMBUFSIZ];
- int ksiz = sprintf(kbuf, "%" PRIuMAX "", (unsigned long long) id);
+ int ksiz = sprintf(kbuf, "%" PRIuMAX "", (uint64_t) id);
if (!iter(kbuf, ksiz, vbuf, vsiz, op)) {
break;
}
wp += sprintf(wp, " type=%02X", fdb->type);
wp += sprintf(wp, " flags=%02X", fdb->flags);
wp += sprintf(wp, " width=%u", fdb->width);
- wp += sprintf(wp, " limsiz=%" PRIuMAX "", (unsigned long long) fdb->limsiz);
+ wp += sprintf(wp, " limsiz=%" PRIuMAX "", (uint64_t) fdb->limsiz);
wp += sprintf(wp, " wsiz=%u", fdb->wsiz);
wp += sprintf(wp, " rsiz=%u", fdb->rsiz);
- wp += sprintf(wp, " limid=%" PRIuMAX "", (unsigned long long) fdb->limid);
+ wp += sprintf(wp, " limid=%" PRIuMAX "", (uint64_t) fdb->limid);
wp += sprintf(wp, " path=%s", fdb->path ? fdb->path : "-");
wp += sprintf(wp, " fd=%d", fdb->fd);
wp += sprintf(wp, " omode=%u", fdb->omode);
- wp += sprintf(wp, " rnum=%" PRIuMAX "", (unsigned long long) fdb->rnum);
- wp += sprintf(wp, " fsiz=%" PRIuMAX "", (unsigned long long) fdb->fsiz);
- wp += sprintf(wp, " min=%" PRIuMAX "", (unsigned long long) fdb->min);
- wp += sprintf(wp, " max=%" PRIuMAX "", (unsigned long long) fdb->max);
- wp += sprintf(wp, " iter=%" PRIuMAX "", (unsigned long long) fdb->iter);
+ wp += sprintf(wp, " rnum=%" PRIuMAX "", (uint64_t) fdb->rnum);
+ wp += sprintf(wp, " fsiz=%" PRIuMAX "", (uint64_t) fdb->fsiz);
+ wp += sprintf(wp, " min=%" PRIuMAX "", (uint64_t) fdb->min);
+ wp += sprintf(wp, " max=%" PRIuMAX "", (uint64_t) fdb->max);
+ wp += sprintf(wp, " iter=%" PRIuMAX "", (uint64_t) fdb->iter);
wp += sprintf(wp, " map=%p", (void *) fdb->map);
wp += sprintf(wp, " ecode=%d", fdb->ecode);
wp += sprintf(wp, " fatal=%u", fdb->fatal);
- wp += sprintf(wp, " inode=%" PRIuMAX "", (unsigned long long) fdb->inode);
- wp += sprintf(wp, " mtime=%" PRIuMAX "", (unsigned long long) fdb->mtime);
+ wp += sprintf(wp, " inode=%" PRIuMAX "", (uint64_t) fdb->inode);
+ wp += sprintf(wp, " mtime=%" PRIuMAX "", (uint64_t) fdb->mtime);
wp += sprintf(wp, " tran=%d", fdb->tran);
wp += sprintf(wp, " walfd=%d", fdb->walfd);
- wp += sprintf(wp, " walend=%" PRIuMAX "", (unsigned long long) fdb->walend);
+ wp += sprintf(wp, " walend=%" PRIuMAX "", (uint64_t) fdb->walend);
wp += sprintf(wp, " dbgfd=%d", fdb->dbgfd);
#ifndef NDEBUG
- wp += sprintf(wp, " cnt_writerec=%" PRIdMAX "", (long long) fdb->cnt_writerec);
- wp += sprintf(wp, " cnt_readrec=%" PRIdMAX "", (long long) fdb->cnt_readrec);
- wp += sprintf(wp, " cnt_truncfile=%" PRIdMAX "", (long long) fdb->cnt_truncfile);
+ wp += sprintf(wp, " cnt_writerec=%" PRIdMAX "", (int64_t) fdb->cnt_writerec);
+ wp += sprintf(wp, " cnt_readrec=%" PRIdMAX "", (int64_t) fdb->cnt_readrec);
+ wp += sprintf(wp, " cnt_truncfile=%" PRIdMAX "", (int64_t) fdb->cnt_truncfile);
#endif
*(wp++) = '\n';
tcwrite(dbgfd, buf, wp - buf);
void *eckey; /* key for thread specific error code */
char *path; /* path of the database file */
char *rpath; /* real path for locking */
- volatile char *map; /* pointer to the mapped memory */
+ char *map; /* pointer to the mapped memory */
volatile int ecode; /* last happened error code */
int wsiz; /* size of the width region */
int rsiz; /* size of each record */
/* global variables */
-const char *g_progname; // program name
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+HANDLE g_dbgfd; // debugging output
/* function prototypes */
static int proccreate(const char *path, int width, int64_t limsiz);
static int procinform(const char *path, int omode);
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- int omode, int dmode);
+ int omode, int dmode);
static int procout(const char *path, const char *kbuf, int ksiz, int omode);
static int procget(const char *path, const char *kbuf, int ksiz, int omode, bool px, bool pz);
static int proclist(const char *path, int omode, int max, bool pv, bool px,
- const char *rlstr, const char *rustr, const char *ristr);
+ const char *rlstr, const char *rustr, const char *ristr);
static int procoptimize(const char *path, int width, int64_t limsiz, int omode);
static int procimporttsv(const char *path, const char *file, int omode, bool sc);
static int procversion(void);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- g_dbgfd = INVALID_HANDLE_VALUE;
- const char *ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ g_dbgfd = INVALID_HANDLE_VALUE;
+ const char *ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "create")){
- rv = runcreate(argc, argv);
- } else if(!strcmp(argv[1], "inform")){
- rv = runinform(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], "importtsv")){
- rv = runimporttsv(argc, argv);
- } else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){
- rv = runversion(argc, argv);
- } else {
- usage();
- }
- return rv;
+ }
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "create")) {
+ rv = runcreate(argc, argv);
+ } else if (!strcmp(argv[1], "inform")) {
+ rv = runinform(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], "importtsv")) {
+ rv = runimporttsv(argc, argv);
+ } else if (!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")) {
+ rv = runversion(argc, argv);
+ } else {
+ usage();
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: the command line utility of the fixed-length database API\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s create path [width [limsiz]]\n", g_progname);
- fprintf(stderr, " %s inform [-nl|-nb] path\n", g_progname);
- fprintf(stderr, " %s put [-nl|-nb] [-sx] [-dk|-dc|-dai|-dad] path key value\n", g_progname);
- fprintf(stderr, " %s out [-nl|-nb] [-sx] path key\n", g_progname);
- fprintf(stderr, " %s get [-nl|-nb] [-sx] [-px] [-pz] path key\n", g_progname);
- fprintf(stderr, " %s list [-nl|-nb] [-m num] [-pv] [-px] [-rb lkey ukey] [-ri str] path\n",
- g_progname);
- fprintf(stderr, " %s optimize [-nl|-nb] path [width [limsiz]]\n", g_progname);
- fprintf(stderr, " %s importtsv [-nl|-nb] [-sc] path [file]\n", g_progname);
- fprintf(stderr, " %s version\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: the command line utility of the fixed-length database API\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s create path [width [limsiz]]\n", g_progname);
+ fprintf(stderr, " %s inform [-nl|-nb] path\n", g_progname);
+ fprintf(stderr, " %s put [-nl|-nb] [-sx] [-dk|-dc|-dai|-dad] path key value\n", g_progname);
+ fprintf(stderr, " %s out [-nl|-nb] [-sx] path key\n", g_progname);
+ fprintf(stderr, " %s get [-nl|-nb] [-sx] [-px] [-pz] path key\n", g_progname);
+ fprintf(stderr, " %s list [-nl|-nb] [-m num] [-pv] [-px] [-rb lkey ukey] [-ri str] path\n",
+ g_progname);
+ fprintf(stderr, " %s optimize [-nl|-nb] path [width [limsiz]]\n", g_progname);
+ fprintf(stderr, " %s importtsv [-nl|-nb] [-sc] path [file]\n", g_progname);
+ fprintf(stderr, " %s version\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print error information */
-static void printerr(TCFDB *fdb){
- const char *path = tcfdbpath(fdb);
- int ecode = tcfdbecode(fdb);
- fprintf(stderr, "%s: %s: %d: %s\n", g_progname, path ? path : "-", ecode, tcfdberrmsg(ecode));
+static void printerr(TCFDB *fdb) {
+ const char *path = tcfdbpath(fdb);
+ int ecode = tcfdbecode(fdb);
+ fprintf(stderr, "%s: %s: %d: %s\n", g_progname, path ? path : "-", ecode, tcfdberrmsg(ecode));
}
-
/* print record data */
-static int printdata(const char *ptr, int size, bool px){
- int len = 0;
- while(size-- > 0){
- if(px){
- if(len > 0) putchar(' ');
- len += printf("%02X", *(unsigned char *)ptr);
- } else {
- putchar(*ptr);
- len++;
+static int printdata(const char *ptr, int size, bool px) {
+ int len = 0;
+ while (size-- > 0) {
+ if (px) {
+ if (len > 0) putchar(' ');
+ len += printf("%02X", *(unsigned char *) ptr);
+ } else {
+ putchar(*ptr);
+ len++;
+ }
+ ptr++;
}
- ptr++;
- }
- return len;
+ return len;
}
-
/* read a line from a file descriptor */
-static char *mygetline(FILE *ifp){
- int len = 0;
- int blen = 1024;
- char *buf = tcmalloc(blen + 1);
- bool end = true;
- int c;
- while((c = fgetc(ifp)) != EOF){
- end = false;
- if(c == '\0') continue;
- if(blen <= len){
- blen *= 2;
- buf = tcrealloc(buf, blen + 1);
- }
- if(c == '\n' || c == '\r') c = '\0';
- buf[len++] = c;
- if(c == '\0') break;
- }
- if(end){
- tcfree(buf);
- return NULL;
- }
- buf[len] = '\0';
- return buf;
+static char *mygetline(FILE *ifp) {
+ int len = 0;
+ int blen = 1024;
+ char *buf = tcmalloc(blen + 1);
+ bool end = true;
+ int c;
+ while ((c = fgetc(ifp)) != EOF) {
+ end = false;
+ if (c == '\0') continue;
+ if (blen <= len) {
+ blen *= 2;
+ buf = tcrealloc(buf, blen + 1);
+ }
+ if (c == '\n' || c == '\r') c = '\0';
+ buf[len++] = c;
+ if (c == '\0') break;
+ }
+ if (end) {
+ tcfree(buf);
+ return NULL;
+ }
+ buf[len] = '\0';
+ return buf;
}
-
/* parse arguments of create command */
-static int runcreate(int argc, char **argv){
- char *path = NULL;
- char *wstr = NULL;
- char *lstr = NULL;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- usage();
- } else if(!path){
- path = argv[i];
- } else if(!wstr){
- wstr = argv[i];
- } else if(!lstr){
- lstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path) usage();
- int width = wstr ? tcatoix(wstr) : -1;
- int64_t limsiz = lstr ? tcatoix(lstr) : -1;
- int rv = proccreate(path, width, limsiz);
- return rv;
+static int runcreate(int argc, char **argv) {
+ char *path = NULL;
+ char *wstr = NULL;
+ char *lstr = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ usage();
+ } else if (!path) {
+ path = argv[i];
+ } else if (!wstr) {
+ wstr = argv[i];
+ } else if (!lstr) {
+ lstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path) usage();
+ int width = wstr ? tcatoix(wstr) : -1;
+ int64_t limsiz = lstr ? tcatoix(lstr) : -1;
+ int rv = proccreate(path, width, limsiz);
+ return rv;
}
-
/* parse arguments of inform command */
-static int runinform(int argc, char **argv){
- char *path = NULL;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runinform(int argc, char **argv) {
+ char *path = NULL;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procinform(path, omode);
- return rv;
+ if (!path) usage();
+ int rv = procinform(path, omode);
+ return rv;
}
-
/* parse arguments of put command */
-static int runput(int argc, char **argv){
- char *path = NULL;
- char *key = NULL;
- char *value = NULL;
- int omode = 0;
- int dmode = 0;
- bool sx = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-dk")){
- dmode = -1;
- } else if(!strcmp(argv[i], "-dc")){
- dmode = 1;
- } else if(!strcmp(argv[i], "-dai")){
- dmode = 10;
- } else if(!strcmp(argv[i], "-dad")){
- dmode = 11;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!key){
- key = argv[i];
- } else if(!value){
- value = argv[i];
+static int runput(int argc, char **argv) {
+ char *path = NULL;
+ char *key = NULL;
+ char *value = NULL;
+ int omode = 0;
+ int dmode = 0;
+ bool sx = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-dk")) {
+ dmode = -1;
+ } else if (!strcmp(argv[i], "-dc")) {
+ dmode = 1;
+ } else if (!strcmp(argv[i], "-dai")) {
+ dmode = 10;
+ } else if (!strcmp(argv[i], "-dad")) {
+ dmode = 11;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else if (!value) {
+ value = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !key || !value) usage();
+ char *kbuf, *vbuf;
+ int ksiz, vsiz;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
+ vbuf = tchexdecode(value, &vsiz);
} else {
- usage();
- }
- }
- if(!path || !key || !value) usage();
- char *kbuf, *vbuf;
- int ksiz, vsiz;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- vbuf = tchexdecode(value, &vsiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- vsiz = strlen(value);
- vbuf = tcmemdup(value, vsiz);
- }
- int rv = procput(path, kbuf, ksiz, vbuf, vsiz, omode, dmode);
- tcfree(vbuf);
- tcfree(kbuf);
- return rv;
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
+ vsiz = strlen(value);
+ vbuf = tcmemdup(value, vsiz);
+ }
+ int rv = procput(path, kbuf, ksiz, vbuf, vsiz, omode, dmode);
+ tcfree(vbuf);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of out command */
-static int runout(int argc, char **argv){
- char *path = NULL;
- char *key = NULL;
- int omode = 0;
- bool sx = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!key){
- key = argv[i];
+static int runout(int argc, char **argv) {
+ char *path = NULL;
+ char *key = NULL;
+ int omode = 0;
+ bool sx = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !key) usage();
+ int ksiz;
+ char *kbuf;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
} else {
- usage();
- }
- }
- if(!path || !key) usage();
- int ksiz;
- char *kbuf;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- }
- int rv = procout(path, kbuf, ksiz, omode);
- tcfree(kbuf);
- return rv;
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
+ }
+ int rv = procout(path, kbuf, ksiz, omode);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of get command */
-static int runget(int argc, char **argv){
- char *path = NULL;
- char *key = NULL;
- int omode = 0;
- bool sx = false;
- bool px = false;
- bool pz = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-pz")){
- pz = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!key){
- key = argv[i];
+static int runget(int argc, char **argv) {
+ char *path = NULL;
+ char *key = NULL;
+ int omode = 0;
+ bool sx = false;
+ bool px = false;
+ bool pz = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-pz")) {
+ pz = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !key) usage();
+ int ksiz;
+ char *kbuf;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
} else {
- usage();
- }
- }
- if(!path || !key) usage();
- int ksiz;
- char *kbuf;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- }
- int rv = procget(path, kbuf, ksiz, omode, px, pz);
- tcfree(kbuf);
- return rv;
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
+ }
+ int rv = procget(path, kbuf, ksiz, omode, px, pz);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of list command */
-static int runlist(int argc, char **argv){
- char *path = NULL;
- int omode = 0;
- int max = -1;
- bool pv = false;
- bool px = false;
- char *rlstr = NULL;
- char *rustr = NULL;
- char *ristr = NULL;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-m")){
- if(++i >= argc) usage();
- max = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-pv")){
- pv = true;
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-rb")){
- if(++i >= argc) usage();
- rlstr = argv[i];
- if(++i >= argc) usage();
- rustr = argv[i];
- } else if(!strcmp(argv[i], "-ri")){
- if(++i >= argc) usage();
- ristr = argv[i];
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runlist(int argc, char **argv) {
+ char *path = NULL;
+ int omode = 0;
+ int max = -1;
+ bool pv = false;
+ bool px = false;
+ char *rlstr = NULL;
+ char *rustr = NULL;
+ char *ristr = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-m")) {
+ if (++i >= argc) usage();
+ max = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-pv")) {
+ pv = true;
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-rb")) {
+ if (++i >= argc) usage();
+ rlstr = argv[i];
+ if (++i >= argc) usage();
+ rustr = argv[i];
+ } else if (!strcmp(argv[i], "-ri")) {
+ if (++i >= argc) usage();
+ ristr = argv[i];
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = proclist(path, omode, max, pv, px, rlstr, rustr, ristr);
- return rv;
+ if (!path) usage();
+ int rv = proclist(path, omode, max, pv, px, rlstr, rustr, ristr);
+ return rv;
}
-
/* parse arguments of optimize command */
-static int runoptimize(int argc, char **argv){
- char *path = NULL;
- char *wstr = NULL;
- char *lstr = NULL;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!wstr){
- wstr = argv[i];
- } else if(!lstr){
- lstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path) usage();
- int width = wstr ? tcatoix(wstr) : -1;
- int64_t limsiz = lstr ? tcatoix(lstr) : -1;
- int rv = procoptimize(path, width, limsiz, omode);
- return rv;
+static int runoptimize(int argc, char **argv) {
+ char *path = NULL;
+ char *wstr = NULL;
+ char *lstr = NULL;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!wstr) {
+ wstr = argv[i];
+ } else if (!lstr) {
+ lstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path) usage();
+ int width = wstr ? tcatoix(wstr) : -1;
+ int64_t limsiz = lstr ? tcatoix(lstr) : -1;
+ int rv = procoptimize(path, width, limsiz, omode);
+ return rv;
}
-
/* parse arguments of importtsv command */
-static int runimporttsv(int argc, char **argv){
- char *path = NULL;
- char *file = NULL;
- int omode = 0;
- bool sc = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-sc")){
- sc = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!file){
- file = argv[i];
- } else {
- usage();
+static int runimporttsv(int argc, char **argv) {
+ char *path = NULL;
+ char *file = NULL;
+ int omode = 0;
+ bool sc = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sc")) {
+ sc = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!file) {
+ file = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procimporttsv(path, file, omode, sc);
- return rv;
+ if (!path) usage();
+ int rv = procimporttsv(path, file, omode, sc);
+ return rv;
}
-
/* parse arguments of version command */
-static int runversion(int argc, char **argv){
- int rv = procversion();
- return rv;
+static int runversion(int argc, char **argv) {
+ int rv = procversion();
+ return rv;
}
-
/* perform create command */
-static int proccreate(const char *path, int width, int64_t limsiz){
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbtune(fdb, width, limsiz)){
- printerr(fdb);
- tcfdbdel(fdb);
- return 1;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC)){
- printerr(fdb);
+static int proccreate(const char *path, int width, int64_t limsiz) {
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbtune(fdb, width, limsiz)) {
+ printerr(fdb);
+ tcfdbdel(fdb);
+ return 1;
+ }
+ if (!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC)) {
+ printerr(fdb);
+ tcfdbdel(fdb);
+ return 1;
+ }
+ bool err = false;
+ if (!tcfdbclose(fdb)) {
+ printerr(fdb);
+ err = true;
+ }
tcfdbdel(fdb);
- return 1;
- }
- bool err = false;
- if(!tcfdbclose(fdb)){
- printerr(fdb);
- err = true;
- }
- tcfdbdel(fdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform inform command */
-static int procinform(const char *path, int omode){
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbopen(fdb, path, FDBOREADER | omode)){
- printerr(fdb);
+static int procinform(const char *path, int omode) {
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbopen(fdb, path, FDBOREADER | omode)) {
+ printerr(fdb);
+ tcfdbdel(fdb);
+ return 1;
+ }
+ bool err = false;
+ const char *npath = tcfdbpath(fdb);
+ if (!npath) npath = "(unknown)";
+ printf("path: %s\n", npath);
+ const char *type = "(unknown)";
+ switch (tcfdbtype(fdb)) {
+ case TCDBTHASH: type = "hash";
+ break;
+ case TCDBTBTREE: type = "btree";
+ break;
+ case TCDBTFIXED: type = "fixed";
+ break;
+ case TCDBTTABLE: type = "table";
+ break;
+ }
+ printf("database type: %s\n", type);
+ uint8_t flags = tcfdbflags(fdb);
+ printf("additional flags:");
+ if (flags & FDBFOPEN) printf(" open");
+ if (flags & FDBFFATAL) printf(" fatal");
+ printf("\n");
+ printf("minimum ID number: %" PRIuMAX "\n", (uint64_t) tcfdbmin(fdb));
+ printf("maximum ID number: %" PRIuMAX "\n", (uint64_t) tcfdbmax(fdb));
+ printf("width of the value: %u\n", (unsigned int) tcfdbwidth(fdb));
+ printf("limit file size: %" PRIuMAX "\n", (uint64_t) tcfdblimsiz(fdb));
+ printf("limit ID number: %" PRIuMAX "\n", (uint64_t) tcfdblimid(fdb));
+ printf("inode number: %" PRIdMAX "\n", (int64_t) tcfdbinode(fdb));
+ char date[48];
+ tcdatestrwww(tcfdbmtime(fdb), INT_MAX, date);
+ printf("modified time: %s\n", date);
+ printf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ printf("file size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ if (!tcfdbclose(fdb)) {
+ if (!err) printerr(fdb);
+ err = true;
+ }
tcfdbdel(fdb);
- return 1;
- }
- bool err = false;
- const char *npath = tcfdbpath(fdb);
- if(!npath) npath = "(unknown)";
- printf("path: %s\n", npath);
- const char *type = "(unknown)";
- switch(tcfdbtype(fdb)){
- case TCDBTHASH: type = "hash"; break;
- case TCDBTBTREE: type = "btree"; break;
- case TCDBTFIXED: type = "fixed"; break;
- case TCDBTTABLE: type = "table"; break;
- }
- printf("database type: %s\n", type);
- uint8_t flags = tcfdbflags(fdb);
- printf("additional flags:");
- if(flags & FDBFOPEN) printf(" open");
- if(flags & FDBFFATAL) printf(" fatal");
- printf("\n");
- printf("minimum ID number: %" PRIuMAX "\n", (unsigned long long)tcfdbmin(fdb));
- printf("maximum ID number: %" PRIuMAX "\n", (unsigned long long)tcfdbmax(fdb));
- printf("width of the value: %u\n", (unsigned int)tcfdbwidth(fdb));
- printf("limit file size: %" PRIuMAX "\n", (unsigned long long)tcfdblimsiz(fdb));
- printf("limit ID number: %" PRIuMAX "\n", (unsigned long long)tcfdblimid(fdb));
- printf("inode number: %" PRIdMAX "\n", (long long)tcfdbinode(fdb));
- char date[48];
- tcdatestrwww(tcfdbmtime(fdb), INT_MAX, date);
- printf("modified time: %s\n", date);
- printf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- printf("file size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
- if(!tcfdbclose(fdb)){
- if(!err) printerr(fdb);
- err = true;
- }
- tcfdbdel(fdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform put command */
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- int omode, int dmode){
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbopen(fdb, path, FDBOWRITER | omode)){
- printerr(fdb);
- tcfdbdel(fdb);
- return 1;
- }
- bool err = false;
- int inum;
- double dnum;
- switch(dmode){
- case -1:
- if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz)){
- printerr(fdb);
- err = true;
- }
- break;
- case 1:
- if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
+ int omode, int dmode) {
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbopen(fdb, path, FDBOWRITER | omode)) {
printerr(fdb);
+ tcfdbdel(fdb);
+ return 1;
+ }
+ bool err = false;
+ int inum;
+ double dnum;
+ switch (dmode) {
+ case -1:
+ if (!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(fdb);
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(fdb);
+ err = true;
+ }
+ break;
+ case 10:
+ inum = tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), tcatoi(vbuf));
+ if (inum == INT_MIN) {
+ printerr(fdb);
+ err = true;
+ } else {
+ printf("%d\n", inum);
+ }
+ break;
+ case 11:
+ dnum = tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), tcatof(vbuf));
+ if (isnan(dnum)) {
+ printerr(fdb);
+ err = true;
+ } else {
+ printf("%.6f\n", dnum);
+ }
+ break;
+ default:
+ if (!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(fdb);
+ err = true;
+ }
+ break;
+ }
+ if (!tcfdbclose(fdb)) {
+ if (!err) printerr(fdb);
err = true;
- }
- break;
- case 10:
- inum = tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), tcatoi(vbuf));
- if(inum == INT_MIN){
+ }
+ tcfdbdel(fdb);
+ return err ? 1 : 0;
+}
+
+/* perform out command */
+static int procout(const char *path, const char *kbuf, int ksiz, int omode) {
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbopen(fdb, path, FDBOWRITER | omode)) {
printerr(fdb);
- err = true;
- } else {
- printf("%d\n", inum);
- }
- break;
- case 11:
- dnum = tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), tcatof(vbuf));
- if(isnan(dnum)){
+ tcfdbdel(fdb);
+ return 1;
+ }
+ bool err = false;
+ if (!tcfdbout2(fdb, kbuf, ksiz)) {
printerr(fdb);
err = true;
- } else {
- printf("%.6f\n", dnum);
- }
- break;
- default:
- if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
- printerr(fdb);
+ }
+ if (!tcfdbclose(fdb)) {
+ if (!err) printerr(fdb);
err = true;
- }
- break;
- }
- if(!tcfdbclose(fdb)){
- if(!err) printerr(fdb);
- err = true;
- }
- tcfdbdel(fdb);
- return err ? 1 : 0;
-}
-
-
-/* perform out command */
-static int procout(const char *path, const char *kbuf, int ksiz, int omode){
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbopen(fdb, path, FDBOWRITER | omode)){
- printerr(fdb);
+ }
tcfdbdel(fdb);
- return 1;
- }
- bool err = false;
- if(!tcfdbout2(fdb, kbuf, ksiz)){
- printerr(fdb);
- err = true;
- }
- if(!tcfdbclose(fdb)){
- if(!err) printerr(fdb);
- err = true;
- }
- tcfdbdel(fdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform get command */
-static int procget(const char *path, const char *kbuf, int ksiz, int omode, bool px, bool pz){
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbopen(fdb, path, FDBOREADER | omode)){
- printerr(fdb);
+static int procget(const char *path, const char *kbuf, int ksiz, int omode, bool px, bool pz) {
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbopen(fdb, path, FDBOREADER | omode)) {
+ printerr(fdb);
+ tcfdbdel(fdb);
+ return 1;
+ }
+ bool err = false;
+ int vsiz;
+ char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ printdata(vbuf, vsiz, px);
+ if (!pz) putchar('\n');
+ tcfree(vbuf);
+ } else {
+ printerr(fdb);
+ err = true;
+ }
+ if (!tcfdbclose(fdb)) {
+ if (!err) printerr(fdb);
+ err = true;
+ }
tcfdbdel(fdb);
- return 1;
- }
- bool err = false;
- int vsiz;
- char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
- if(vbuf){
- printdata(vbuf, vsiz, px);
- if(!pz) putchar('\n');
- tcfree(vbuf);
- } else {
- printerr(fdb);
- err = true;
- }
- if(!tcfdbclose(fdb)){
- if(!err) printerr(fdb);
- err = true;
- }
- tcfdbdel(fdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform list command */
static int proclist(const char *path, int omode, int max, bool pv, bool px,
- const char *rlstr, const char *rustr, const char *ristr){
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbopen(fdb, path, FDBOREADER | omode)){
- printerr(fdb);
- tcfdbdel(fdb);
- return 1;
- }
- bool err = false;
- if(rlstr || ristr){
- TCLIST *keys = ristr ? tcfdbrange5(fdb, ristr, max) : tcfdbrange3(fdb, rlstr, rustr, max);
- for(int i = 0; i < tclistnum(keys); i++){
- int ksiz;
- const char *kbuf = tclistval(keys, i, &ksiz);
- printf("%s", kbuf);
- if(pv){
- int vsiz;
- char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
- if(vbuf){
- putchar('\t');
- printdata(vbuf, vsiz, px);
- tcfree(vbuf);
+ const char *rlstr, const char *rustr, const char *ristr) {
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbopen(fdb, path, FDBOREADER | omode)) {
+ printerr(fdb);
+ tcfdbdel(fdb);
+ return 1;
+ }
+ bool err = false;
+ if (rlstr || ristr) {
+ TCLIST *keys = ristr ? tcfdbrange5(fdb, ristr, max) : tcfdbrange3(fdb, rlstr, rustr, max);
+ for (int i = 0; i < tclistnum(keys); i++) {
+ int ksiz;
+ const char *kbuf = tclistval(keys, i, &ksiz);
+ printf("%s", kbuf);
+ if (pv) {
+ int vsiz;
+ char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ putchar('\t');
+ printdata(vbuf, vsiz, px);
+ tcfree(vbuf);
+ }
+ }
+ putchar('\n');
+ }
+ tclistdel(keys);
+ } else {
+ if (!tcfdbiterinit(fdb)) {
+ printerr(fdb);
+ err = true;
+ }
+ int cnt = 0;
+ uint64_t id;
+ while ((id = tcfdbiternext(fdb)) > 0) {
+ printf("%" PRIuMAX "", (uint64_t) id);
+ if (pv) {
+ int vsiz;
+ char *vbuf = tcfdbget(fdb, id, &vsiz);
+ if (vbuf) {
+ putchar('\t');
+ printdata(vbuf, vsiz, px);
+ tcfree(vbuf);
+ }
+ }
+ putchar('\n');
+ if (max >= 0 && ++cnt >= max) break;
}
- }
- putchar('\n');
}
- tclistdel(keys);
- } else {
- if(!tcfdbiterinit(fdb)){
- printerr(fdb);
- err = true;
+ if (!tcfdbclose(fdb)) {
+ if (!err) printerr(fdb);
+ err = true;
}
- int cnt = 0;
- uint64_t id;
- while((id = tcfdbiternext(fdb)) > 0){
- printf("%" PRIuMAX "", (unsigned long long)id);
- if(pv){
- int vsiz;
- char *vbuf = tcfdbget(fdb, id, &vsiz);
- if(vbuf){
- putchar('\t');
- printdata(vbuf, vsiz, px);
- tcfree(vbuf);
- }
- }
- putchar('\n');
- if(max >= 0 && ++cnt >= max) break;
- }
- }
- if(!tcfdbclose(fdb)){
- if(!err) printerr(fdb);
- err = true;
- }
- tcfdbdel(fdb);
- return err ? 1 : 0;
+ tcfdbdel(fdb);
+ return err ? 1 : 0;
}
-
/* perform optimize command */
-static int procoptimize(const char *path, int width, int64_t limsiz, int omode){
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbopen(fdb, path, FDBOWRITER | omode)){
- printerr(fdb);
+static int procoptimize(const char *path, int width, int64_t limsiz, int omode) {
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbopen(fdb, path, FDBOWRITER | omode)) {
+ printerr(fdb);
+ tcfdbdel(fdb);
+ return 1;
+ }
+ bool err = false;
+ if (!tcfdboptimize(fdb, width, limsiz)) {
+ printerr(fdb);
+ err = true;
+ }
+ if (!tcfdbclose(fdb)) {
+ if (!err) printerr(fdb);
+ err = true;
+ }
tcfdbdel(fdb);
- return 1;
- }
- bool err = false;
- if(!tcfdboptimize(fdb, width, limsiz)){
- printerr(fdb);
- err = true;
- }
- if(!tcfdbclose(fdb)){
- if(!err) printerr(fdb);
- err = true;
- }
- tcfdbdel(fdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform importtsv command */
-static int procimporttsv(const char *path, const char *file, int omode, bool sc){
- FILE *ifp = file ? fopen(file, "rb") : stdin;
- if(!ifp){
- fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
- return 1;
- }
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | omode)){
- printerr(fdb);
+static int procimporttsv(const char *path, const char *file, int omode, bool sc) {
+ FILE *ifp = file ? fopen(file, "rb") : stdin;
+ if (!ifp) {
+ fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
+ return 1;
+ }
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | omode)) {
+ printerr(fdb);
+ tcfdbdel(fdb);
+ if (ifp != stdin) fclose(ifp);
+ return 1;
+ }
+ bool err = false;
+ char *line;
+ int cnt = 0;
+ while (!err && (line = mygetline(ifp)) != NULL) {
+ char *pv = strchr(line, '\t');
+ if (!pv) {
+ tcfree(line);
+ continue;
+ }
+ *pv = '\0';
+ if (sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
+ if (!tcfdbput3(fdb, line, pv + 1)) {
+ printerr(fdb);
+ err = true;
+ }
+ tcfree(line);
+ if (cnt > 0 && cnt % 100 == 0) {
+ putchar('.');
+ fflush(stdout);
+ if (cnt % 5000 == 0) printf(" (%08d)\n", cnt);
+ }
+ cnt++;
+ }
+ printf(" (%08d)\n", cnt);
+ if (!tcfdbclose(fdb)) {
+ if (!err) printerr(fdb);
+ err = true;
+ }
tcfdbdel(fdb);
- if(ifp != stdin) fclose(ifp);
- return 1;
- }
- bool err = false;
- char *line;
- int cnt = 0;
- while(!err && (line = mygetline(ifp)) != NULL){
- char *pv = strchr(line, '\t');
- if(!pv){
- tcfree(line);
- continue;
- }
- *pv = '\0';
- if(sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
- if(!tcfdbput3(fdb, line, pv + 1)){
- printerr(fdb);
- err = true;
- }
- tcfree(line);
- if(cnt > 0 && cnt % 100 == 0){
- putchar('.');
- fflush(stdout);
- if(cnt % 5000 == 0) printf(" (%08d)\n", cnt);
- }
- cnt++;
- }
- printf(" (%08d)\n", cnt);
- if(!tcfdbclose(fdb)){
- if(!err) printerr(fdb);
- err = true;
- }
- tcfdbdel(fdb);
- if(ifp != stdin) fclose(ifp);
- return err ? 1 : 0;
+ if (ifp != stdin) fclose(ifp);
+ return err ? 1 : 0;
}
-
/* perform version command */
-static int procversion(void){
- printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
- tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
- printf("Copyright (C) 2006-2012 FAL Labs\n");
- return 0;
+static int procversion(void) {
+ printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
+ tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
+ printf("Copyright (C) 2006-2012 FAL Labs\n");
+ return 0;
}
#define RECBUFSIZ 48 // buffer for records
#define EXHEADSIZ 256 // expected header size
-typedef struct { // type of structure for write thread
- TCFDB *fdb;
- int rnum;
- bool rnd;
- int id;
+typedef struct { // type of structure for write thread
+ TCFDB *fdb;
+ int rnum;
+ bool rnd;
+ int id;
} TARGWRITE;
-typedef struct { // type of structure for read thread
- TCFDB *fdb;
- int rnum;
- bool wb;
- bool rnd;
- int id;
+typedef struct { // type of structure for read thread
+ TCFDB *fdb;
+ int rnum;
+ bool wb;
+ bool rnd;
+ int id;
} TARGREAD;
-typedef struct { // type of structure for remove thread
- TCFDB *fdb;
- int rnum;
- bool rnd;
- int id;
+typedef struct { // type of structure for remove thread
+ TCFDB *fdb;
+ int rnum;
+ bool rnd;
+ int id;
} TARGREMOVE;
-typedef struct { // type of structure for wicked thread
- TCFDB *fdb;
- int rnum;
- bool nc;
- int id;
- TCMAP *map;
+typedef struct { // type of structure for wicked thread
+ TCFDB *fdb;
+ int rnum;
+ bool nc;
+ int id;
+ TCMAP *map;
} TARGWICKED;
-typedef struct { // type of structure for typical thread
- TCFDB *fdb;
- int rnum;
- bool nc;
- int rratio;
- int id;
+typedef struct { // type of structure for typical thread
+ TCFDB *fdb;
+ int rnum;
+ bool nc;
+ int rratio;
+ int id;
} TARGTYPICAL;
/* global variables */
-const char *g_progname; // program name
-unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+unsigned int g_randseed; // random seed
+HANDLE g_dbgfd; // debugging output
/* function prototypes */
static int runwicked(int argc, char **argv);
static int runtypical(int argc, char **argv);
static int procwrite(const char *path, int tnum, int rnum, int width, int64_t limsiz,
- int omode, bool rnd);
+ int omode, bool rnd);
static int procread(const char *path, int tnum, int omode, bool wb, bool rnd);
static int procremove(const char *path, int tnum, int omode, bool rnd);
static int procwicked(const char *path, int tnum, int rnum, int omode, bool nc);
static int proctypical(const char *path, int tnum, int rnum, int width, int64_t limsiz,
- int omode, bool nc, int rratio);
+ int omode, bool nc, int rratio);
static void *threadwrite(void *targ);
static void *threadread(void *targ);
static void *threadremove(void *targ);
static void *threadwicked(void *targ);
static void *threadtypical(void *targ);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- const char *ebuf = getenv("TCRNDSEED");
- g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
- srand(g_randseed);
- ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ const char *ebuf = getenv("TCRNDSEED");
+ g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
+ srand(g_randseed);
+ ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int 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], "remove")){
- rv = runremove(argc, argv);
- } else if(!strcmp(argv[1], "wicked")){
- rv = runwicked(argc, argv);
- } else if(!strcmp(argv[1], "typical")){
- rv = runtypical(argc, argv);
- } else {
- usage();
- }
- if(rv != 0){
- printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
- for(int i = 0; i < argc; i++){
- printf(" %s", argv[i]);
}
- printf("\n\n");
- }
- return rv;
+ if (argc < 2) usage();
+ int 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], "remove")) {
+ rv = runremove(argc, argv);
+ } else if (!strcmp(argv[1], "wicked")) {
+ rv = runwicked(argc, argv);
+ } else if (!strcmp(argv[1], "typical")) {
+ rv = runtypical(argc, argv);
+ } else {
+ usage();
+ }
+ if (rv != 0) {
+ printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int) getpid());
+ for (int i = 0; i < argc; i++) {
+ printf(" %s", argv[i]);
+ }
+ printf("\n\n");
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: test cases of the fixed-length database API of Tokyo Cabinet\n",
- g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write [-nl|-nb] [-rnd] path tnum rnum [width [limsiz]]\n", g_progname);
- fprintf(stderr, " %s read [-nl|-nb] [-wb] [-rnd] path tnum\n", g_progname);
- fprintf(stderr, " %s remove [-nl|-nb] [-rnd] path tnum\n", g_progname);
- fprintf(stderr, " %s wicked [-nl|-nb] [-nc] path tnum rnum\n", g_progname);
- fprintf(stderr, " %s typical [-nl|-nb] [-nc] [-rr num] path tnum rnum [width [limsiz]]\n",
- g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: test cases of the fixed-length database API of Tokyo Cabinet\n",
+ g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s write [-nl|-nb] [-rnd] path tnum rnum [width [limsiz]]\n", g_progname);
+ fprintf(stderr, " %s read [-nl|-nb] [-wb] [-rnd] path tnum\n", g_progname);
+ fprintf(stderr, " %s remove [-nl|-nb] [-rnd] path tnum\n", g_progname);
+ fprintf(stderr, " %s wicked [-nl|-nb] [-nc] path tnum rnum\n", g_progname);
+ fprintf(stderr, " %s typical [-nl|-nb] [-nc] [-rr num] path tnum rnum [width [limsiz]]\n",
+ g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print formatted information string and flush the buffer */
-static void iprintf(const char *format, ...){
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- fflush(stdout);
- va_end(ap);
+static void iprintf(const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vprintf(format, ap);
+ fflush(stdout);
+ va_end(ap);
}
-
/* print a character and flush the buffer */
-static void iputchar(int c){
- putchar(c);
- fflush(stdout);
+static void iputchar(int c) {
+ putchar(c);
+ fflush(stdout);
}
-
/* print error message of fixed-length database */
-static void eprint(TCFDB *fdb, int line, const char *func){
- const char *path = tcfdbpath(fdb);
- int ecode = tcfdbecode(fdb);
- fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
- g_progname, path ? path : "-", line, func, ecode, tcfdberrmsg(ecode));
+static void eprint(TCFDB *fdb, int line, const char *func) {
+ const char *path = tcfdbpath(fdb);
+ int ecode = tcfdbecode(fdb);
+ fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
+ g_progname, path ? path : "-", line, func, ecode, tcfdberrmsg(ecode));
}
-
/* print members of fixed-length database */
-static void mprint(TCFDB *fdb){
- iprintf("minimum ID number: %" PRIuMAX "\n", (unsigned long long)tcfdbmin(fdb));
- iprintf("maximum ID number: %" PRIuMAX "\n", (unsigned long long)tcfdbmax(fdb));
- iprintf("width of the value: %u\n", (unsigned int)tcfdbwidth(fdb));
- iprintf("limit file size: %" PRIuMAX "\n", (unsigned long long)tcfdblimsiz(fdb));
- iprintf("limit ID number: %" PRIuMAX "\n", (unsigned long long)tcfdblimid(fdb));
+static void mprint(TCFDB *fdb) {
+ iprintf("minimum ID number: %" PRIuMAX "\n", (uint64_t) tcfdbmin(fdb));
+ iprintf("maximum ID number: %" PRIuMAX "\n", (uint64_t) tcfdbmax(fdb));
+ iprintf("width of the value: %u\n", (unsigned int) tcfdbwidth(fdb));
+ iprintf("limit file size: %" PRIuMAX "\n", (uint64_t) tcfdblimsiz(fdb));
+ iprintf("limit ID number: %" PRIuMAX "\n", (uint64_t) tcfdblimid(fdb));
#ifndef NDEBUG
- if(fdb->cnt_writerec < 0) return;
- iprintf("cnt_writerec: %" PRIdMAX "\n", (long long)fdb->cnt_writerec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (long long)fdb->cnt_readrec);
- iprintf("cnt_truncfile: %" PRIdMAX "\n", (long long)fdb->cnt_truncfile);
+ if (fdb->cnt_writerec < 0) return;
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t) fdb->cnt_writerec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t) fdb->cnt_readrec);
+ iprintf("cnt_truncfile: %" PRIdMAX "\n", (int64_t) fdb->cnt_truncfile);
#endif
}
-
/* print system information */
-static void sysprint(void){
- TCMAP *info = tcsysinfo();
- if(info){
- tcmapiterinit(info);
- const char *kbuf;
- while((kbuf = tcmapiternext2(info)) != NULL){
- iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+static void sysprint(void) {
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ tcmapiterinit(info);
+ const char *kbuf;
+ while ((kbuf = tcmapiternext2(info)) != NULL) {
+ iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+ }
+ tcmapdel(info);
}
- tcmapdel(info);
- }
}
-
/* get a random number */
-static int myrand(int range){
- if(range < 2) return 0;
- int high = (unsigned int)rand() >> 4;
- int low = range * (rand() / (RAND_MAX + 1.0));
- low &= (unsigned int)INT_MAX >> 4;
- return (high + low) % range;
+static int myrand(int range) {
+ if (range < 2) return 0;
+ int high = (unsigned int) rand() >> 4;
+ int low = range * (rand() / (RAND_MAX + 1.0));
+ low &= (unsigned int) INT_MAX >> 4;
+ return (high + low) % range;
}
-
/* get a random number based on normal distribution */
-static int myrandnd(int range){
- int num = (int)tcdrandnd(range >> 1, range / 10);
- return (num < 0 || num >= range) ? 0 : num;
+static int myrandnd(int range) {
+ int num = (int) tcdrandnd(range >> 1, range / 10);
+ return (num < 0 || num >= range) ? 0 : num;
}
-
/* iterator function */
-static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op){
- unsigned int sum = 0;
- while(--ksiz >= 0){
- sum += ((char *)kbuf)[ksiz];
- }
- while(--vsiz >= 0){
- sum += ((char *)vbuf)[vsiz];
- }
- return myrand(100 + (sum & 0xff)) > 0;
+static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op) {
+ unsigned int sum = 0;
+ while (--ksiz >= 0) {
+ sum += ((char *) kbuf)[ksiz];
+ }
+ while (--vsiz >= 0) {
+ sum += ((char *) vbuf)[vsiz];
+ }
+ return myrand(100 + (sum & 0xff)) > 0;
}
-
/* parse arguments of write command */
-static int runwrite(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- char *wstr = NULL;
- char *lstr = NULL;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!wstr){
- wstr = argv[i];
- } else if(!lstr){
- lstr = argv[i];
- } else {
- usage();
+static int runwrite(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ char *wstr = NULL;
+ char *lstr = NULL;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!wstr) {
+ wstr = argv[i];
+ } else if (!lstr) {
+ lstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int width = wstr ? tcatoix(wstr) : -1;
- int64_t limsiz = lstr ? tcatoix(lstr) : -1;
- int rv = procwrite(path, tnum, rnum, width, limsiz, omode, rnd);
- return rv;
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int width = wstr ? tcatoix(wstr) : -1;
+ int64_t limsiz = lstr ? tcatoix(lstr) : -1;
+ int rv = procwrite(path, tnum, rnum, width, limsiz, omode, rnd);
+ return rv;
}
-
/* parse arguments of read command */
-static int runread(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- int omode = 0;
- bool wb = false;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-wb")){
- wb = true;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else {
- usage();
+static int runread(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ int omode = 0;
+ bool wb = false;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-wb")) {
+ wb = true;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path || !tstr) usage();
- int tnum = tcatoix(tstr);
- if(tnum < 1) usage();
- int rv = procread(path, tnum, omode, wb, rnd);
- return rv;
+ if (!path || !tstr) usage();
+ int tnum = tcatoix(tstr);
+ if (tnum < 1) usage();
+ int rv = procread(path, tnum, omode, wb, rnd);
+ return rv;
}
-
/* parse arguments of remove command */
-static int runremove(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else {
- usage();
+static int runremove(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path || !tstr) usage();
- int tnum = tcatoix(tstr);
- if(tnum < 1) usage();
- int rv = procremove(path, tnum, omode, rnd);
- return rv;
+ if (!path || !tstr) usage();
+ int tnum = tcatoix(tstr);
+ if (tnum < 1) usage();
+ int rv = procremove(path, tnum, omode, rnd);
+ return rv;
}
-
/* parse arguments of wicked command */
-static int runwicked(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- int omode = 0;
- bool nc = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-nc")){
- nc = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
+static int runwicked(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ int omode = 0;
+ bool nc = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-nc")) {
+ nc = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int rv = procwicked(path, tnum, rnum, omode, nc);
- return rv;
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int rv = procwicked(path, tnum, rnum, omode, nc);
+ return rv;
}
-
/* parse arguments of typical command */
-static int runtypical(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- char *wstr = NULL;
- char *lstr = NULL;
- int omode = 0;
- int rratio = -1;
- bool nc = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-nc")){
- nc = true;
- } else if(!strcmp(argv[i], "-rr")){
- if(++i >= argc) usage();
- rratio = tcatoix(argv[i]);
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!wstr){
- wstr = argv[i];
- } else if(!lstr){
- lstr = argv[i];
- } else {
- usage();
+static int runtypical(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ char *wstr = NULL;
+ char *lstr = NULL;
+ int omode = 0;
+ int rratio = -1;
+ bool nc = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-nc")) {
+ nc = true;
+ } else if (!strcmp(argv[i], "-rr")) {
+ if (++i >= argc) usage();
+ rratio = tcatoix(argv[i]);
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!wstr) {
+ wstr = argv[i];
+ } else if (!lstr) {
+ lstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int width = wstr ? tcatoix(wstr) : -1;
- int64_t limsiz = lstr ? tcatoix(lstr) : -1;
- int rv = proctypical(path, tnum, rnum, width, limsiz, omode, nc, rratio);
- return rv;
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int width = wstr ? tcatoix(wstr) : -1;
+ int64_t limsiz = lstr ? tcatoix(lstr) : -1;
+ int rv = proctypical(path, tnum, rnum, width, limsiz, omode, nc, rratio);
+ return rv;
}
-
/* perform write command */
static int procwrite(const char *path, int tnum, int rnum, int width, int64_t limsiz,
- int omode, bool rnd){
- iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d width=%d limsiz=%" PRIdMAX " omode=%d rnd=%d\n\n",
- g_randseed, path, tnum, rnum, width, (long long)limsiz, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbtune(fdb, width, limsiz)){
- eprint(fdb, __LINE__, "tcfdbtune");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- TARGWRITE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].fdb = fdb;
- targs[0].rnum = rnum;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadwrite(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].fdb = fdb;
- targs[i].rnum = rnum;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadwrite, targs + i) != 0){
- eprint(fdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int omode, bool rnd) {
+ iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d width=%d limsiz=%" PRIdMAX " omode=%d rnd=%d\n\n",
+ g_randseed, path, tnum, rnum, width, (int64_t) limsiz, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(fdb, __LINE__, "pthread_join");
+ if (!tcfdbtune(fdb, width, limsiz)) {
+ eprint(fdb, __LINE__, "tcfdbtune");
err = true;
- } else if(rv){
+ }
+ if (!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
+ err = true;
+ }
+ TARGWRITE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].fdb = fdb;
+ targs[0].rnum = rnum;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadwrite(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].fdb = fdb;
+ targs[i].rnum = rnum;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadwrite, targs + i) != 0) {
+ eprint(fdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(fdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
err = true;
- }
}
- }
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform read command */
-static int procread(const char *path, int tnum, int omode, bool wb, bool rnd){
- iprintf("<Reading Test>\n seed=%u path=%s tnum=%d omode=%d wb=%d rnd=%d\n\n",
- g_randseed, path, tnum, omode, wb, rnd);
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOREADER | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- int rnum = tcfdbrnum(fdb) / tnum;
- TARGREAD targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].fdb = fdb;
- targs[0].rnum = rnum;
- targs[0].wb = wb;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadread(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].fdb = fdb;
- targs[i].rnum = rnum;
- targs[i].wb = wb;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadread, targs + i) != 0){
- eprint(fdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+static int procread(const char *path, int tnum, int omode, bool wb, bool rnd) {
+ iprintf("<Reading Test>\n seed=%u path=%s tnum=%d omode=%d wb=%d rnd=%d\n\n",
+ g_randseed, path, tnum, omode, wb, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(fdb, __LINE__, "pthread_join");
+ if (!tcfdbopen(fdb, path, FDBOREADER | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
err = true;
- } else if(rv){
+ }
+ int rnum = tcfdbrnum(fdb) / tnum;
+ TARGREAD targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].fdb = fdb;
+ targs[0].rnum = rnum;
+ targs[0].wb = wb;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadread(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].fdb = fdb;
+ targs[i].rnum = rnum;
+ targs[i].wb = wb;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadread, targs + i) != 0) {
+ eprint(fdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(fdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
err = true;
- }
}
- }
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform remove command */
-static int procremove(const char *path, int tnum, int omode, bool rnd){
- iprintf("<Removing Test>\n seed=%u path=%s tnum=%d omode=%d rnd=%d\n\n",
- g_randseed, path, tnum, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- int rnum = tcfdbrnum(fdb) / tnum;
- TARGREMOVE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].fdb = fdb;
- targs[0].rnum = rnum;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadremove(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].fdb = fdb;
- targs[i].rnum = rnum;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadremove, targs + i) != 0){
- eprint(fdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+static int procremove(const char *path, int tnum, int omode, bool rnd) {
+ iprintf("<Removing Test>\n seed=%u path=%s tnum=%d omode=%d rnd=%d\n\n",
+ g_randseed, path, tnum, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(fdb, __LINE__, "pthread_join");
+ if (!tcfdbopen(fdb, path, FDBOWRITER | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
err = true;
- } else if(rv){
+ }
+ int rnum = tcfdbrnum(fdb) / tnum;
+ TARGREMOVE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].fdb = fdb;
+ targs[0].rnum = rnum;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadremove(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].fdb = fdb;
+ targs[i].rnum = rnum;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadremove, targs + i) != 0) {
+ eprint(fdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(fdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
err = true;
- }
}
- }
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform wicked command */
-static int procwicked(const char *path, int tnum, int rnum, int omode, bool nc){
- iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d omode=%d nc=%d\n\n",
- g_randseed, path, tnum, rnum, omode, nc);
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbtune(fdb, RECBUFSIZ * 2, EXHEADSIZ + (RECBUFSIZ * 2 + sizeof(int)) * rnum * tnum)){
- eprint(fdb, __LINE__, "tcfdbtune");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- if(!tcfdbiterinit(fdb)){
- eprint(fdb, __LINE__, "tcfdbiterinit");
- err = true;
- }
- TARGWICKED targs[tnum];
- pthread_t threads[tnum];
- TCMAP *map = tcmapnew();
- if(tnum == 1){
- targs[0].fdb = fdb;
- targs[0].rnum = rnum;
- targs[0].nc = nc;
- targs[0].id = 0;
- targs[0].map = map;
- if(threadwicked(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].fdb = fdb;
- targs[i].rnum = rnum;
- targs[i].nc = nc;
- targs[i].id = i;
- targs[i].map = map;
- if(pthread_create(threads + i, NULL, threadwicked, targs + i) != 0){
- eprint(fdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+static int procwicked(const char *path, int tnum, int rnum, int omode, bool nc) {
+ iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d omode=%d nc=%d\n\n",
+ g_randseed, path, tnum, rnum, omode, nc);
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(fdb, __LINE__, "pthread_join");
+ if (!tcfdbtune(fdb, RECBUFSIZ * 2, EXHEADSIZ + (RECBUFSIZ * 2 + sizeof (int)) * rnum * tnum)) {
+ eprint(fdb, __LINE__, "tcfdbtune");
err = true;
- } else if(rv){
+ }
+ if (!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
err = true;
- }
}
- }
- if(!nc){
- if(!tcfdbsync(fdb)){
- eprint(fdb, __LINE__, "tcfdbsync");
- err = true;
+ if (!tcfdbiterinit(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbiterinit");
+ err = true;
}
- if(tcfdbrnum(fdb) != tcmaprnum(map)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
+ TARGWICKED targs[tnum];
+ pthread_t threads[tnum];
+ TCMAP *map = tcmapnew();
+ if (tnum == 1) {
+ targs[0].fdb = fdb;
+ targs[0].rnum = rnum;
+ targs[0].nc = nc;
+ targs[0].id = 0;
+ targs[0].map = map;
+ if (threadwicked(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].fdb = fdb;
+ targs[i].rnum = rnum;
+ targs[i].nc = nc;
+ targs[i].id = i;
+ targs[i].map = map;
+ if (pthread_create(threads + i, NULL, threadwicked, targs + i) != 0) {
+ eprint(fdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(fdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
}
- int end = rnum * tnum;
- for(int i = 1; i <= end && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", i);
- int vsiz;
- const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
- int rsiz;
- char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
- if(vbuf){
- iputchar('.');
- if(vsiz > tcfdbwidth(fdb)) vsiz = tcfdbwidth(fdb);
- if(!rbuf){
- eprint(fdb, __LINE__, "tcfdbget");
- err = true;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
+ if (!nc) {
+ if (!tcfdbsync(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsync");
+ err = true;
}
- } else {
- iputchar('*');
- if(rbuf || tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
+ if (tcfdbrnum(fdb) != tcmaprnum(map)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ int end = rnum * tnum;
+ for (int i = 1; i <= end && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", i);
+ int vsiz;
+ const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
+ int rsiz;
+ char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
+ if (vbuf) {
+ iputchar('.');
+ if (vsiz > tcfdbwidth(fdb)) vsiz = tcfdbwidth(fdb);
+ if (!rbuf) {
+ eprint(fdb, __LINE__, "tcfdbget");
+ err = true;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ } else {
+ iputchar('*');
+ if (rbuf || tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
+ tcfree(rbuf);
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
}
- }
- tcfree(rbuf);
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
+ if (rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
}
- if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
- }
- tcmapdel(map);
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ tcmapdel(map);
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
+ err = true;
+ }
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform typical command */
static int proctypical(const char *path, int tnum, int rnum, int width, int64_t limsiz,
- int omode, bool nc, int rratio){
- iprintf("<Typical Access Test>\n seed=%u path=%s tnum=%d rnum=%d width=%d limsiz=%" PRIdMAX " omode=%d nc=%d rratio=%d\n\n",
- g_randseed, path, tnum, rnum, width, (long long)limsiz, omode, nc, rratio);
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(!tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbtune(fdb, width, limsiz)){
- eprint(fdb, __LINE__, "tcfdbtune");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- TARGTYPICAL targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].fdb = fdb;
- targs[0].rnum = rnum;
- targs[0].nc = nc;
- targs[0].rratio = rratio;
- targs[0].id = 0;
- if(threadtypical(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].fdb = fdb;
- targs[i].rnum = rnum;
- targs[i].nc = nc;
- targs[i].rratio= rratio;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadtypical, targs + i) != 0){
- eprint(fdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int omode, bool nc, int rratio) {
+ iprintf("<Typical Access Test>\n seed=%u path=%s tnum=%d rnum=%d width=%d limsiz=%" PRIdMAX " omode=%d nc=%d rratio=%d\n\n",
+ g_randseed, path, tnum, rnum, width, (int64_t) limsiz, omode, nc, rratio);
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (!tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
+ err = true;
+ }
+ if (!tcfdbtune(fdb, width, limsiz)) {
+ eprint(fdb, __LINE__, "tcfdbtune");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(fdb, __LINE__, "pthread_join");
+ if (!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
err = true;
- } else if(rv){
+ }
+ TARGTYPICAL targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].fdb = fdb;
+ targs[0].rnum = rnum;
+ targs[0].nc = nc;
+ targs[0].rratio = rratio;
+ targs[0].id = 0;
+ if (threadtypical(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].fdb = fdb;
+ targs[i].rnum = rnum;
+ targs[i].nc = nc;
+ targs[i].rratio = rratio;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadtypical, targs + i) != 0) {
+ eprint(fdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(fdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
err = true;
- }
}
- }
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* thread the write function */
-static void *threadwrite(void *targ){
- TCFDB *fdb = ((TARGWRITE *)targ)->fdb;
- int rnum = ((TARGWRITE *)targ)->rnum;
- bool rnd = ((TARGWRITE *)targ)->rnd;
- int id = ((TARGWRITE *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) + 1 : i));
- if(!tcfdbput2(fdb, buf, len, buf, len)){
- eprint(fdb, __LINE__, "tcfdbput2");
- err = true;
- break;
- }
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+static void *threadwrite(void *targ) {
+ TCFDB *fdb = ((TARGWRITE *) targ)->fdb;
+ int rnum = ((TARGWRITE *) targ)->rnum;
+ bool rnd = ((TARGWRITE *) targ)->rnd;
+ int id = ((TARGWRITE *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) + 1 : i));
+ if (!tcfdbput2(fdb, buf, len, buf, len)) {
+ eprint(fdb, __LINE__, "tcfdbput2");
+ err = true;
+ break;
+ }
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
}
- }
- return err ? "error" : NULL;
+ return err ? "error" : NULL;
}
-
/* thread the read function */
-static void *threadread(void *targ){
- TCFDB *fdb = ((TARGREAD *)targ)->fdb;
- int rnum = ((TARGREAD *)targ)->rnum;
- bool wb = ((TARGREAD *)targ)->wb;
- bool rnd = ((TARGREAD *)targ)->rnd;
- int id = ((TARGREAD *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum && !err; i++){
- uint64_t kid = base + (rnd ? myrandnd(i) + 1 : i);
- int vsiz;
- if(wb){
- char vbuf[RECBUFSIZ];
- int vsiz = tcfdbget4(fdb, kid, vbuf, RECBUFSIZ);
- if(vsiz < 0 && (!rnd || tcfdbecode(fdb) != TCENOREC)){
- eprint(fdb, __LINE__, "tcfdbget4");
- err = true;
- }
- } else {
- char *vbuf = tcfdbget(fdb, kid, &vsiz);
- if(!vbuf && (!rnd || tcfdbecode(fdb) != TCENOREC)){
- eprint(fdb, __LINE__, "tcfdbget");
- err = true;
- }
- tcfree(vbuf);
- }
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+static void *threadread(void *targ) {
+ TCFDB *fdb = ((TARGREAD *) targ)->fdb;
+ int rnum = ((TARGREAD *) targ)->rnum;
+ bool wb = ((TARGREAD *) targ)->wb;
+ bool rnd = ((TARGREAD *) targ)->rnd;
+ int id = ((TARGREAD *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum && !err; i++) {
+ uint64_t kid = base + (rnd ? myrandnd(i) + 1 : i);
+ int vsiz;
+ if (wb) {
+ char vbuf[RECBUFSIZ];
+ int vsiz = tcfdbget4(fdb, kid, vbuf, RECBUFSIZ);
+ if (vsiz < 0 && (!rnd || tcfdbecode(fdb) != TCENOREC)) {
+ eprint(fdb, __LINE__, "tcfdbget4");
+ err = true;
+ }
+ } else {
+ char *vbuf = tcfdbget(fdb, kid, &vsiz);
+ if (!vbuf && (!rnd || tcfdbecode(fdb) != TCENOREC)) {
+ eprint(fdb, __LINE__, "tcfdbget");
+ err = true;
+ }
+ tcfree(vbuf);
+ }
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
}
- }
- return err ? "error" : NULL;
+ return err ? "error" : NULL;
}
-
/* thread the remove function */
-static void *threadremove(void *targ){
- TCFDB *fdb = ((TARGREMOVE *)targ)->fdb;
- int rnum = ((TARGREMOVE *)targ)->rnum;
- bool rnd = ((TARGREMOVE *)targ)->rnd;
- int id = ((TARGREMOVE *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrand(i + 1) + 1 : i));
- if(!tcfdbout2(fdb, kbuf, ksiz) && (!rnd || tcfdbecode(fdb) != TCENOREC)){
- eprint(fdb, __LINE__, "tcfdbout2");
- err = true;
- break;
- }
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- return err ? "error" : NULL;
-}
-
-
-/* thread the wicked function */
-static void *threadwicked(void *targ){
- TCFDB *fdb = ((TARGWICKED *)targ)->fdb;
- int rnum = ((TARGWICKED *)targ)->rnum;
- bool nc = ((TARGWICKED *)targ)->nc;
- int id = ((TARGWICKED *)targ)->id;
- TCMAP *map = ((TARGWICKED *)targ)->map;
- bool err = false;
- for(int i = 1; i <= rnum && !err; i++){
- uint64_t kid = myrand(rnum * (id + 1)) + 1;
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%" PRIuMAX "", (unsigned long long)kid);
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '*', vsiz);
- vbuf[vsiz] = '\0';
- char *rbuf;
- if(!nc) tcglobalmutexlock();
- switch(myrand(16)){
- case 0:
- if(id == 0) iputchar('0');
- if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbput2");
- err = true;
- }
- if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- if(id == 0) iputchar('1');
- if(!tcfdbput3(fdb, kbuf, vbuf)){
- eprint(fdb, __LINE__, "tcfdbput3");
- err = true;
- }
- if(!nc) tcmapput2(map, kbuf, vbuf);
- break;
- case 2:
- if(id == 0) iputchar('2');
- if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputkeep2");
- err = true;
- }
- if(!nc) tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- if(id == 0) iputchar('3');
- if(!tcfdbputkeep3(fdb, kbuf, vbuf) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputkeep3");
- err = true;
- }
- if(!nc) tcmapputkeep2(map, kbuf, vbuf);
- break;
- case 4:
- if(id == 0) iputchar('4');
- if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbputcat2");
- err = true;
- }
- if(!nc) tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 5:
- if(id == 0) iputchar('5');
- if(!tcfdbputcat3(fdb, kbuf, vbuf)){
- eprint(fdb, __LINE__, "tcfdbputcat3");
- err = true;
- }
- if(!nc) tcmapputcat2(map, kbuf, vbuf);
- break;
- case 6:
- if(id == 0) iputchar('6');
- if(myrand(2) == 0){
- if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
+static void *threadremove(void *targ) {
+ TCFDB *fdb = ((TARGREMOVE *) targ)->fdb;
+ int rnum = ((TARGREMOVE *) targ)->rnum;
+ bool rnd = ((TARGREMOVE *) targ)->rnd;
+ int id = ((TARGREMOVE *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrand(i + 1) + 1 : i));
+ if (!tcfdbout2(fdb, kbuf, ksiz) && (!rnd || tcfdbecode(fdb) != TCENOREC)) {
eprint(fdb, __LINE__, "tcfdbout2");
err = true;
- }
- if(!nc) tcmapout(map, kbuf, ksiz);
+ break;
}
- break;
- case 7:
- if(id == 0) iputchar('7');
- if(myrand(2) == 0){
- if(!tcfdbout3(fdb, kbuf) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout3");
- err = true;
- }
- if(!nc) tcmapout2(map, kbuf);
- }
- break;
- case 8:
- if(id == 0) iputchar('8');
- if(!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz))){
- if(tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbget2");
- err = true;
- }
- rbuf = tcsprintf("[%d]", myrand(i + 1));
- vsiz = strlen(rbuf);
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- vsiz += myrand(vsiz);
- if(myrand(3) == 0) vsiz += PATH_MAX;
- rbuf = tcrealloc(rbuf, vsiz + 1);
- for(int j = 0; j < vsiz; j++){
- rbuf[j] = myrand(0x100);
- }
- if(!tcfdbput2(fdb, kbuf, ksiz, rbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbput2");
- err = true;
- }
- if(!nc) tcmapput(map, kbuf, ksiz, rbuf, vsiz);
- tcfree(rbuf);
- break;
- case 9:
- if(id == 0) iputchar('9');
- if(!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz)) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbget2");
- err = true;
- }
- tcfree(rbuf);
- break;
- case 10:
- if(id == 0) iputchar('A');
- if(!(rbuf = tcfdbget3(fdb, kbuf)) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbge3");
- err = true;
- }
- tcfree(rbuf);
- break;
- case 11:
- if(id == 0) iputchar('B');
- if(myrand(1) == 0) vsiz = 1;
- if((vsiz = tcfdbget4(fdb, kid, vbuf, vsiz)) < 0 && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbget4");
- err = true;
- }
- break;
- case 14:
- if(id == 0) iputchar('E');
- if(myrand(rnum / 50) == 0){
- if(!tcfdbiterinit(fdb)){
- eprint(fdb, __LINE__, "tcfdbiterinit");
- err = true;
- }
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the wicked function */
+static void *threadwicked(void *targ) {
+ TCFDB *fdb = ((TARGWICKED *) targ)->fdb;
+ int rnum = ((TARGWICKED *) targ)->rnum;
+ bool nc = ((TARGWICKED *) targ)->nc;
+ int id = ((TARGWICKED *) targ)->id;
+ TCMAP *map = ((TARGWICKED *) targ)->map;
+ bool err = false;
+ for (int i = 1; i <= rnum && !err; i++) {
+ uint64_t kid = myrand(rnum * (id + 1)) + 1;
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%" PRIuMAX "", (uint64_t) kid);
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '*', vsiz);
+ vbuf[vsiz] = '\0';
+ char *rbuf;
+ if (!nc) tcglobalmutexlock();
+ switch (myrand(16)) {
+ case 0:
+ if (id == 0) iputchar('0');
+ if (!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbput2");
+ err = true;
+ }
+ if (!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ if (id == 0) iputchar('1');
+ if (!tcfdbput3(fdb, kbuf, vbuf)) {
+ eprint(fdb, __LINE__, "tcfdbput3");
+ err = true;
+ }
+ if (!nc) tcmapput2(map, kbuf, vbuf);
+ break;
+ case 2:
+ if (id == 0) iputchar('2');
+ if (!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputkeep2");
+ err = true;
+ }
+ if (!nc) tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ if (id == 0) iputchar('3');
+ if (!tcfdbputkeep3(fdb, kbuf, vbuf) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputkeep3");
+ err = true;
+ }
+ if (!nc) tcmapputkeep2(map, kbuf, vbuf);
+ break;
+ case 4:
+ if (id == 0) iputchar('4');
+ if (!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbputcat2");
+ err = true;
+ }
+ if (!nc) tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 5:
+ if (id == 0) iputchar('5');
+ if (!tcfdbputcat3(fdb, kbuf, vbuf)) {
+ eprint(fdb, __LINE__, "tcfdbputcat3");
+ err = true;
+ }
+ if (!nc) tcmapputcat2(map, kbuf, vbuf);
+ break;
+ case 6:
+ if (id == 0) iputchar('6');
+ if (myrand(2) == 0) {
+ if (!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout2");
+ err = true;
+ }
+ if (!nc) tcmapout(map, kbuf, ksiz);
+ }
+ break;
+ case 7:
+ if (id == 0) iputchar('7');
+ if (myrand(2) == 0) {
+ if (!tcfdbout3(fdb, kbuf) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout3");
+ err = true;
+ }
+ if (!nc) tcmapout2(map, kbuf);
+ }
+ break;
+ case 8:
+ if (id == 0) iputchar('8');
+ if (!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz))) {
+ if (tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbget2");
+ err = true;
+ }
+ rbuf = tcsprintf("[%d]", myrand(i + 1));
+ vsiz = strlen(rbuf);
+ }
+ vsiz += myrand(vsiz);
+ if (myrand(3) == 0) vsiz += PATH_MAX;
+ rbuf = tcrealloc(rbuf, vsiz + 1);
+ for (int j = 0; j < vsiz; j++) {
+ rbuf[j] = myrand(0x100);
+ }
+ if (!tcfdbput2(fdb, kbuf, ksiz, rbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbput2");
+ err = true;
+ }
+ if (!nc) tcmapput(map, kbuf, ksiz, rbuf, vsiz);
+ tcfree(rbuf);
+ break;
+ case 9:
+ if (id == 0) iputchar('9');
+ if (!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz)) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbget2");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 10:
+ if (id == 0) iputchar('A');
+ if (!(rbuf = tcfdbget3(fdb, kbuf)) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbge3");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 11:
+ if (id == 0) iputchar('B');
+ if (myrand(1) == 0) vsiz = 1;
+ if ((vsiz = tcfdbget4(fdb, kid, vbuf, vsiz)) < 0 && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbget4");
+ err = true;
+ }
+ break;
+ case 14:
+ if (id == 0) iputchar('E');
+ if (myrand(rnum / 50) == 0) {
+ if (!tcfdbiterinit(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbiterinit");
+ err = true;
+ }
+ }
+ for (int j = myrand(rnum) / 1000 + 1; j >= 0; j--) {
+ if (tcfdbiternext(fdb) < 1) {
+ int ecode = tcfdbecode(fdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbiternext");
+ err = true;
+ }
+ }
+ }
+ break;
+ default:
+ if (id == 0) iputchar('@');
+ if (tcfdbtranbegin(fdb)) {
+ if (myrand(2) == 0) {
+ if (!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbput");
+ err = true;
+ }
+ if (!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ } else {
+ if (!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout");
+ err = true;
+ }
+ if (!nc) tcmapout(map, kbuf, ksiz);
+ }
+ if (nc && myrand(2) == 0) {
+ if (!tcfdbtranabort(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbtranabort");
+ err = true;
+ }
+ } else {
+ if (!tcfdbtrancommit(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbtrancommit");
+ err = true;
+ }
+ }
+ } else {
+ eprint(fdb, __LINE__, "tcfdbtranbegin");
+ err = true;
+ }
+ if (myrand(1000) == 0) {
+ if (!tcfdbforeach(fdb, iterfunc, NULL)) {
+ eprint(fdb, __LINE__, "tcfdbforeach");
+ err = true;
+ }
+ }
+ if (myrand(10000) == 0) srand((unsigned int) (tctime() * 1000) % UINT_MAX);
+ break;
}
- for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
- if(tcfdbiternext(fdb) < 1){
- int ecode = tcfdbecode(fdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbiternext");
- err = true;
+ if (!nc) tcglobalmutexunlock();
+ if (id == 0) {
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ if (id == 0 && i == rnum / 4) {
+ if (!tcfdboptimize(fdb, RECBUFSIZ, -1) && tcfdbecode(fdb) != TCEINVALID) {
+ eprint(fdb, __LINE__, "tcfdboptimize");
+ err = true;
+ }
+ if (!tcfdbiterinit(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbiterinit");
+ err = true;
+ }
}
- }
}
- break;
- default:
- if(id == 0) iputchar('@');
- if(tcfdbtranbegin(fdb)){
- if(myrand(2) == 0){
- if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbput");
- err = true;
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the typical function */
+static void *threadtypical(void *targ) {
+ TCFDB *fdb = ((TARGTYPICAL *) targ)->fdb;
+ int rnum = ((TARGTYPICAL *) targ)->rnum;
+ bool nc = ((TARGTYPICAL *) targ)->nc;
+ int rratio = ((TARGTYPICAL *) targ)->rratio;
+ int id = ((TARGTYPICAL *) targ)->id;
+ bool err = false;
+ TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL;
+ int base = id * rnum;
+ int mrange = tclmax(50 + rratio, 100);
+ int width = tcfdbwidth(fdb);
+ for (int i = 1; !err && i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", base + myrandnd(i) + 1);
+ int rnd = myrand(mrange);
+ if (rnd < 10) {
+ if (!tcfdbput2(fdb, buf, len, buf, len)) {
+ eprint(fdb, __LINE__, "tcfdbput2");
+ err = true;
}
- if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- } else {
- if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout");
- err = true;
+ if (map) tcmapput(map, buf, len, buf, len);
+ } else if (rnd < 15) {
+ if (!tcfdbputkeep2(fdb, buf, len, buf, len) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputkeep2");
+ err = true;
}
- if(!nc) tcmapout(map, kbuf, ksiz);
- }
- if(nc && myrand(2) == 0){
- if(!tcfdbtranabort(fdb)){
- eprint(fdb, __LINE__, "tcfdbtranabort");
- err = true;
+ if (map) tcmapputkeep(map, buf, len, buf, len);
+ } else if (rnd < 20) {
+ if (!tcfdbputcat2(fdb, buf, len, buf, len)) {
+ eprint(fdb, __LINE__, "tcfdbputcat2");
+ err = true;
}
- } else {
- if(!tcfdbtrancommit(fdb)){
- eprint(fdb, __LINE__, "tcfdbtrancommit");
- err = true;
+ if (map) tcmapputcat(map, buf, len, buf, len);
+ } else if (rnd < 25) {
+ if (!tcfdbout2(fdb, buf, len) && tcfdbecode(fdb) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout");
+ err = true;
+ }
+ if (map) tcmapout(map, buf, len);
+ } else if (rnd < 26) {
+ if (myrand(10) == 0 && !tcfdbiterinit(fdb) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbiterinit");
+ err = true;
+ }
+ for (int j = 0; !err && j < 10; j++) {
+ if (tcfdbiternext(fdb) < 1 &&
+ tcfdbecode(fdb) != TCEINVALID && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbiternext");
+ err = true;
+ }
}
- }
} else {
- eprint(fdb, __LINE__, "tcfdbtranbegin");
- err = true;
- }
- if(myrand(1000) == 0){
- if(!tcfdbforeach(fdb, iterfunc, NULL)){
- eprint(fdb, __LINE__, "tcfdbforeach");
- err = true;
- }
- }
- if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
- break;
- }
- if(!nc) tcglobalmutexunlock();
- if(id == 0){
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- if(id == 0 && i == rnum / 4){
- if(!tcfdboptimize(fdb, RECBUFSIZ, -1) && tcfdbecode(fdb) != TCEINVALID){
- eprint(fdb, __LINE__, "tcfdboptimize");
- err = true;
- }
- if(!tcfdbiterinit(fdb)){
- eprint(fdb, __LINE__, "tcfdbiterinit");
- err = true;
- }
- }
- }
- }
- return err ? "error" : NULL;
-}
-
-
-/* thread the typical function */
-static void *threadtypical(void *targ){
- TCFDB *fdb = ((TARGTYPICAL *)targ)->fdb;
- int rnum = ((TARGTYPICAL *)targ)->rnum;
- bool nc = ((TARGTYPICAL *)targ)->nc;
- int rratio = ((TARGTYPICAL *)targ)->rratio;
- int id = ((TARGTYPICAL *)targ)->id;
- bool err = false;
- TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL;
- int base = id * rnum;
- int mrange = tclmax(50 + rratio, 100);
- int width = tcfdbwidth(fdb);
- for(int i = 1; !err && i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", base + myrandnd(i) + 1);
- int rnd = myrand(mrange);
- if(rnd < 10){
- if(!tcfdbput2(fdb, buf, len, buf, len)){
- eprint(fdb, __LINE__, "tcfdbput2");
- err = true;
- }
- if(map) tcmapput(map, buf, len, buf, len);
- } else if(rnd < 15){
- if(!tcfdbputkeep2(fdb, buf, len, buf, len) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputkeep2");
- err = true;
- }
- if(map) tcmapputkeep(map, buf, len, buf, len);
- } else if(rnd < 20){
- if(!tcfdbputcat2(fdb, buf, len, buf, len)){
- eprint(fdb, __LINE__, "tcfdbputcat2");
- err = true;
- }
- if(map) tcmapputcat(map, buf, len, buf, len);
- } else if(rnd < 25){
- if(!tcfdbout2(fdb, buf, len) && tcfdbecode(fdb) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout");
- err = true;
- }
- if(map) tcmapout(map, buf, len);
- } else if(rnd < 26){
- if(myrand(10) == 0 && !tcfdbiterinit(fdb) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbiterinit");
- err = true;
- }
- for(int j = 0; !err && j < 10; j++){
- if(tcfdbiternext(fdb) < 1 &&
- tcfdbecode(fdb) != TCEINVALID && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbiternext");
- err = true;
- }
- }
- } else {
- int vsiz;
- char *vbuf = tcfdbget2(fdb, buf, len, &vsiz);
- if(vbuf){
- if(map){
- int msiz = 0;
- const char *mbuf = tcmapget(map, buf, len, &msiz);
- if(msiz > width) msiz = width;
- if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- }
- }
- tcfree(vbuf);
- } else {
- if(tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbget");
- err = true;
+ int vsiz;
+ char *vbuf = tcfdbget2(fdb, buf, len, &vsiz);
+ if (vbuf) {
+ if (map) {
+ int msiz = 0;
+ const char *mbuf = tcmapget(map, buf, len, &msiz);
+ if (msiz > width) msiz = width;
+ if (!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
+ tcfree(vbuf);
+ } else {
+ if (tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbget");
+ err = true;
+ }
+ if (map && tcmapget(map, buf, len, &vsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
}
- if(map && tcmapget(map, buf, len, &vsiz)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- }
- }
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- }
- if(map){
- tcmapiterinit(map);
- int ksiz;
- const char *kbuf;
- while(!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL){
- int vsiz;
- char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
- if(vbuf){
- int msiz = 0;
- const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz);
- if(msiz > width) msiz = width;
- if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
+ if (map) {
+ tcmapiterinit(map);
+ int ksiz;
+ const char *kbuf;
+ while (!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL) {
+ int vsiz;
+ char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ int msiz = 0;
+ const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz);
+ if (msiz > width) msiz = width;
+ if (!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ tcfree(vbuf);
+ } else {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
}
- tcfree(vbuf);
- } else {
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- }
+ tcmapdel(map);
}
- tcmapdel(map);
- }
- return err ? "error" : NULL;
+ return err ? "error" : NULL;
}
/* print members of fixed-length database */
static void mprint(TCFDB *fdb){
- iprintf("minimum ID number: %" PRIuMAX "\n", (unsigned long long)tcfdbmin(fdb));
- iprintf("maximum ID number: %" PRIuMAX "\n", (unsigned long long)tcfdbmax(fdb));
+ iprintf("minimum ID number: %" PRIuMAX "\n", (uint64_t)tcfdbmin(fdb));
+ iprintf("maximum ID number: %" PRIuMAX "\n", (uint64_t)tcfdbmax(fdb));
iprintf("width of the value: %u\n", (unsigned int)tcfdbwidth(fdb));
- iprintf("limit file size: %" PRIuMAX "\n", (unsigned long long)tcfdblimsiz(fdb));
- iprintf("limit ID number: %" PRIuMAX "\n", (unsigned long long)tcfdblimid(fdb));
+ iprintf("limit file size: %" PRIuMAX "\n", (uint64_t)tcfdblimsiz(fdb));
+ iprintf("limit ID number: %" PRIuMAX "\n", (uint64_t)tcfdblimid(fdb));
#ifndef NDEBUG
if(fdb->cnt_writerec < 0) return;
- iprintf("cnt_writerec: %" PRIdMAX "\n", (long long)fdb->cnt_writerec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (long long)fdb->cnt_readrec);
- iprintf("cnt_truncfile: %" PRIdMAX "\n", (long long)fdb->cnt_truncfile);
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t)fdb->cnt_writerec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t)fdb->cnt_readrec);
+ iprintf("cnt_truncfile: %" PRIdMAX "\n", (int64_t)fdb->cnt_truncfile);
#endif
}
static int procwrite(const char *path, int rnum, int width, int64_t limsiz,
bool mt, int omode, bool rnd){
iprintf("<Writing Test>\n seed=%u path=%s rnum=%d width=%d limsiz=%" PRIdMAX " mt=%d omode=%d"
- " rnd=%d\n\n", g_randseed, path, rnum, width, (long long)limsiz, mt, omode, rnd);
+ " rnd=%d\n\n", g_randseed, path, rnum, width, (int64_t)limsiz, mt, omode, rnd);
bool err = false;
double stime = tctime();
TCFDB *fdb = tcfdbnew();
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
mprint(fdb);
sysprint();
if(!tcfdbclose(fdb)){
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
mprint(fdb);
sysprint();
if(!tcfdbclose(fdb)){
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
mprint(fdb);
sysprint();
if(!tcfdbclose(fdb)){
iprintf("<Random Concatenating Test>\n"
" seed=%u path=%s rnum=%d width=%d limsiz=%" PRIdMAX " mt=%d omode=%d pnum=%d"
" dai=%d dad=%d rl=%d ru=%d\n\n",
- g_randseed, path, rnum, width, (long long)limsiz, mt, omode, pnum, dai, dad, rl, ru);
+ g_randseed, path, rnum, width, (int64_t)limsiz, mt, omode, pnum, dai, dad, rl, ru);
if(pnum < 1) pnum = rnum;
bool err = false;
double stime = tctime();
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
mprint(fdb);
sysprint();
if(!tcfdbclose(fdb)){
err = true;
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
mprint(fdb);
sysprint();
if(!tcfdbclose(fdb)){
for(int i = 1; i <= rnum && !err; i++){
uint64_t id = myrand(rnum) + 1;
char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%" PRIuMAX "", (unsigned long long)id);
+ int ksiz = sprintf(kbuf, "%" PRIuMAX "", (uint64_t)id);
char vbuf[RECBUFSIZ];
int vsiz = myrand(RECBUFSIZ);
memset(vbuf, '*', vsiz);
eprint(fdb, __LINE__, "(validation)");
err = true;
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcfdbfsiz(fdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
mprint(fdb);
sysprint();
tcmapdel(map);
#elif !defined __GNU__
size_t xmsiz = (hdb->xmsiz > hdb->msiz) ? hdb->xmsiz : hdb->msiz;
if (!hdb->map || msync(hdb->map, xmsiz, MS_SYNC)) {
- tchmdbsetecode(hdb, TCEMMAP, __FILE__, __LINE__, __func__);
+ tchdbsetecode(hdb, TCEMMAP, __FILE__, __LINE__, __func__);
err = true;
}
#endif
}
if (*path == '@') {
char tsbuf[TCNUMBUFSIZ];
- sprintf(tsbuf, "%" PRIuMAX "", (unsigned long long) (tctime() * 1000000));
+ sprintf(tsbuf, "%" PRIuMAX "", (uint64_t) (tctime() * 1000000));
const char *args[3];
args[0] = path + 1;
args[1] = hdb->path;
wp += sprintf(wp, " rpath=%s", hdb->rpath ? hdb->rpath : "-");
wp += sprintf(wp, " type=%02X", hdb->type);
wp += sprintf(wp, " flags=%02X", hdb->flags);
- wp += sprintf(wp, " bnum=%" PRIuMAX "", (unsigned long long) hdb->bnum);
+ wp += sprintf(wp, " bnum=%" PRIuMAX "", (uint64_t) hdb->bnum);
wp += sprintf(wp, " apow=%u", hdb->apow);
wp += sprintf(wp, " fpow=%u", hdb->fpow);
wp += sprintf(wp, " opts=%u", hdb->opts);
wp += sprintf(wp, " path=%s", hdb->path ? hdb->path : "-");
wp += sprintf(wp, " fd=%d", hdb->fd);
wp += sprintf(wp, " omode=%u", hdb->omode);
- wp += sprintf(wp, " rnum=%" PRIuMAX "", (unsigned long long) hdb->rnum);
- wp += sprintf(wp, " fsiz=%" PRIuMAX "", (unsigned long long) hdb->fsiz);
- wp += sprintf(wp, " frec=%" PRIuMAX "", (unsigned long long) hdb->frec);
- wp += sprintf(wp, " dfcur=%" PRIuMAX "", (unsigned long long) hdb->dfcur);
- wp += sprintf(wp, " iter=%" PRIuMAX "", (unsigned long long) hdb->iter);
+ wp += sprintf(wp, " rnum=%" PRIuMAX "", (uint64_t) hdb->rnum);
+ wp += sprintf(wp, " fsiz=%" PRIuMAX "", (uint64_t) hdb->fsiz);
+ wp += sprintf(wp, " frec=%" PRIuMAX "", (uint64_t) hdb->frec);
+ wp += sprintf(wp, " dfcur=%" PRIuMAX "", (uint64_t) hdb->dfcur);
+ wp += sprintf(wp, " iter=%" PRIuMAX "", (uint64_t) hdb->iter);
wp += sprintf(wp, " map=%p", (void *) hdb->map);
- wp += sprintf(wp, " msiz=%" PRIuMAX "", (unsigned long long) hdb->msiz);
+ wp += sprintf(wp, " msiz=%" PRIuMAX "", (uint64_t) hdb->msiz);
wp += sprintf(wp, " ba64=%d", hdb->ba64);
wp += sprintf(wp, " align=%u", hdb->align);
wp += sprintf(wp, " runit=%u", hdb->runit);
wp += sprintf(wp, " fbpmis=%d", hdb->fbpmis);
wp += sprintf(wp, " drpool=%p", (void *) hdb->drpool);
wp += sprintf(wp, " drpdef=%p", (void *) hdb->drpdef);
- wp += sprintf(wp, " drpoff=%" PRIuMAX "", (unsigned long long) hdb->drpoff);
+ wp += sprintf(wp, " drpoff=%" PRIuMAX "", (uint64_t) hdb->drpoff);
wp += sprintf(wp, " recc=%p", (void *) hdb->recc);
wp += sprintf(wp, " rcnum=%u", hdb->rcnum);
wp += sprintf(wp, " ecode=%d", hdb->ecode);
wp += sprintf(wp, " fatal=%u", hdb->fatal);
- wp += sprintf(wp, " inode=%" PRIuMAX "", (unsigned long long) (uint64_t) hdb->inode);
- wp += sprintf(wp, " mtime=%" PRIuMAX "", (unsigned long long) (uint64_t) hdb->mtime);
+ wp += sprintf(wp, " inode=%" PRIuMAX "", (uint64_t) (uint64_t) hdb->inode);
+ wp += sprintf(wp, " mtime=%" PRIuMAX "", (uint64_t) (uint64_t) hdb->mtime);
wp += sprintf(wp, " dfunit=%u", hdb->dfunit);
wp += sprintf(wp, " dfcnt=%u", hdb->dfcnt);
wp += sprintf(wp, " tran=%d", hdb->tran);
wp += sprintf(wp, " walfd=%d", hdb->walfd);
- wp += sprintf(wp, " walend=%" PRIuMAX "", (unsigned long long) hdb->walend);
+ wp += sprintf(wp, " walend=%" PRIuMAX "", (uint64_t) hdb->walend);
wp += sprintf(wp, " dbgfd=%d", hdb->dbgfd);
#ifndef NDEBUG
- wp += sprintf(wp, " cnt_writerec=%" PRIdMAX "", (long long) hdb->cnt_writerec);
- wp += sprintf(wp, " cnt_reuserec=%" PRIdMAX "", (long long) hdb->cnt_reuserec);
- wp += sprintf(wp, " cnt_moverec=%" PRIdMAX "", (long long) hdb->cnt_moverec);
- wp += sprintf(wp, " cnt_readrec=%" PRIdMAX "", (long long) hdb->cnt_readrec);
- wp += sprintf(wp, " cnt_searchfbp=%" PRIdMAX "", (long long) hdb->cnt_searchfbp);
- wp += sprintf(wp, " cnt_insertfbp=%" PRIdMAX "", (long long) hdb->cnt_insertfbp);
- wp += sprintf(wp, " cnt_splicefbp=%" PRIdMAX "", (long long) hdb->cnt_splicefbp);
- wp += sprintf(wp, " cnt_dividefbp=%" PRIdMAX "", (long long) hdb->cnt_dividefbp);
- wp += sprintf(wp, " cnt_mergefbp=%" PRIdMAX "", (long long) hdb->cnt_mergefbp);
- wp += sprintf(wp, " cnt_reducefbp=%" PRIdMAX "", (long long) hdb->cnt_reducefbp);
- wp += sprintf(wp, " cnt_appenddrp=%" PRIdMAX "", (long long) hdb->cnt_appenddrp);
- wp += sprintf(wp, " cnt_deferdrp=%" PRIdMAX "", (long long) hdb->cnt_deferdrp);
- wp += sprintf(wp, " cnt_flushdrp=%" PRIdMAX "", (long long) hdb->cnt_flushdrp);
- wp += sprintf(wp, " cnt_adjrecc=%" PRIdMAX "", (long long) hdb->cnt_adjrecc);
- wp += sprintf(wp, " cnt_defrag=%" PRIdMAX "", (long long) hdb->cnt_defrag);
- wp += sprintf(wp, " cnt_shiftrec=%" PRIdMAX "", (long long) hdb->cnt_shiftrec);
- wp += sprintf(wp, " cnt_trunc=%" PRIdMAX "", (long long) hdb->cnt_trunc);
+ wp += sprintf(wp, " cnt_writerec=%" PRIdMAX "", (int64_t) hdb->cnt_writerec);
+ wp += sprintf(wp, " cnt_reuserec=%" PRIdMAX "", (int64_t) hdb->cnt_reuserec);
+ wp += sprintf(wp, " cnt_moverec=%" PRIdMAX "", (int64_t) hdb->cnt_moverec);
+ wp += sprintf(wp, " cnt_readrec=%" PRIdMAX "", (int64_t) hdb->cnt_readrec);
+ wp += sprintf(wp, " cnt_searchfbp=%" PRIdMAX "", (int64_t) hdb->cnt_searchfbp);
+ wp += sprintf(wp, " cnt_insertfbp=%" PRIdMAX "", (int64_t) hdb->cnt_insertfbp);
+ wp += sprintf(wp, " cnt_splicefbp=%" PRIdMAX "", (int64_t) hdb->cnt_splicefbp);
+ wp += sprintf(wp, " cnt_dividefbp=%" PRIdMAX "", (int64_t) hdb->cnt_dividefbp);
+ wp += sprintf(wp, " cnt_mergefbp=%" PRIdMAX "", (int64_t) hdb->cnt_mergefbp);
+ wp += sprintf(wp, " cnt_reducefbp=%" PRIdMAX "", (int64_t) hdb->cnt_reducefbp);
+ wp += sprintf(wp, " cnt_appenddrp=%" PRIdMAX "", (int64_t) hdb->cnt_appenddrp);
+ wp += sprintf(wp, " cnt_deferdrp=%" PRIdMAX "", (int64_t) hdb->cnt_deferdrp);
+ wp += sprintf(wp, " cnt_flushdrp=%" PRIdMAX "", (int64_t) hdb->cnt_flushdrp);
+ wp += sprintf(wp, " cnt_adjrecc=%" PRIdMAX "", (int64_t) hdb->cnt_adjrecc);
+ wp += sprintf(wp, " cnt_defrag=%" PRIdMAX "", (int64_t) hdb->cnt_defrag);
+ wp += sprintf(wp, " cnt_shiftrec=%" PRIdMAX "", (int64_t) hdb->cnt_shiftrec);
+ wp += sprintf(wp, " cnt_trunc=%" PRIdMAX "", (int64_t) hdb->cnt_trunc);
#endif
*(wp++) = '\n';
char buf[HDBIOBUFSIZ];
char *wp = buf;
wp += sprintf(wp, "REC:");
- wp += sprintf(wp, " off=%" PRIuMAX "", (unsigned long long) rec->off);
+ wp += sprintf(wp, " off=%" PRIuMAX "", (uint64_t) rec->off);
wp += sprintf(wp, " rsiz=%u", rec->rsiz);
wp += sprintf(wp, " magic=%02X", rec->magic);
wp += sprintf(wp, " hash=%02X", rec->hash);
- wp += sprintf(wp, " left=%" PRIuMAX "", (unsigned long long) rec->left);
- wp += sprintf(wp, " right=%" PRIuMAX "", (unsigned long long) rec->right);
+ wp += sprintf(wp, " left=%" PRIuMAX "", (uint64_t) rec->left);
+ wp += sprintf(wp, " right=%" PRIuMAX "", (uint64_t) rec->right);
wp += sprintf(wp, " ksiz=%u", rec->ksiz);
wp += sprintf(wp, " vsiz=%u", rec->vsiz);
wp += sprintf(wp, " psiz=%u", rec->psiz);
wp += sprintf(wp, " kbuf=%p", (void *) rec->kbuf);
wp += sprintf(wp, " vbuf=%p", (void *) rec->vbuf);
- wp += sprintf(wp, " boff=%" PRIuMAX "", (unsigned long long) rec->boff);
+ wp += sprintf(wp, " boff=%" PRIuMAX "", (uint64_t) rec->boff);
wp += sprintf(wp, " bbuf=%p", (void *) rec->bbuf);
*(wp++) = '\n';
tcwrite(dbgfd, buf, wp - buf);
if(flags & HDBFOPEN) printf(" open");
if(flags & HDBFFATAL) printf(" fatal");
printf("\n");
- printf("bucket number: %" PRIuMAX "\n", (unsigned long long)tchdbbnum(hdb));
+ printf("bucket number: %" PRIuMAX "\n", (uint64_t)tchdbbnum(hdb));
if(hdb->cnt_writerec >= 0)
- printf("used bucket number: %" PRIdMAX "\n", (long long)tchdbbnumused(hdb));
+ printf("used bucket number: %" PRIdMAX "\n", (int64_t)tchdbbnumused(hdb));
printf("alignment: %u\n", tchdbalign(hdb));
printf("free block pool: %u\n", tchdbfbpmax(hdb));
- printf("inode number: %" PRIdMAX "\n", (long long)tchdbinode(hdb));
+ printf("inode number: %" PRIdMAX "\n", (int64_t)tchdbinode(hdb));
char date[48];
tcdatestrwww(tchdbmtime(hdb), INT_MAX, date);
printf("modified time: %s\n", date);
if(opts & HDBTTCBS) printf(" tcbs");
if(opts & HDBTEXCODEC) printf(" excodec");
printf("\n");
- printf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- printf("file size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ printf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ printf("file size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
if(!tchdbclose(hdb)){
if(!err) printerr(hdb);
err = true;
/* print members of hash database */
static void mprint(TCHDB *hdb){
- iprintf("bucket number: %" PRIdMAX "\n", (long long)tchdbbnum(hdb));
- iprintf("used bucket number: %" PRIdMAX "\n", (long long)tchdbbnumused(hdb));
+ iprintf("bucket number: %" PRIdMAX "\n", (int64_t)tchdbbnum(hdb));
+ iprintf("used bucket number: %" PRIdMAX "\n", (int64_t)tchdbbnumused(hdb));
#ifndef NDEBUG
if(hdb->cnt_writerec < 0) return;
- iprintf("cnt_writerec: %" PRIdMAX "\n", (long long)hdb->cnt_writerec);
- iprintf("cnt_reuserec: %" PRIdMAX "\n", (long long)hdb->cnt_reuserec);
- iprintf("cnt_moverec: %" PRIdMAX "\n", (long long)hdb->cnt_moverec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (long long)hdb->cnt_readrec);
- iprintf("cnt_searchfbp: %" PRIdMAX "\n", (long long)hdb->cnt_searchfbp);
- iprintf("cnt_insertfbp: %" PRIdMAX "\n", (long long)hdb->cnt_insertfbp);
- iprintf("cnt_splicefbp: %" PRIdMAX "\n", (long long)hdb->cnt_splicefbp);
- iprintf("cnt_dividefbp: %" PRIdMAX "\n", (long long)hdb->cnt_dividefbp);
- iprintf("cnt_mergefbp: %" PRIdMAX "\n", (long long)hdb->cnt_mergefbp);
- iprintf("cnt_reducefbp: %" PRIdMAX "\n", (long long)hdb->cnt_reducefbp);
- iprintf("cnt_appenddrp: %" PRIdMAX "\n", (long long)hdb->cnt_appenddrp);
- iprintf("cnt_deferdrp: %" PRIdMAX "\n", (long long)hdb->cnt_deferdrp);
- iprintf("cnt_flushdrp: %" PRIdMAX "\n", (long long)hdb->cnt_flushdrp);
- iprintf("cnt_adjrecc: %" PRIdMAX "\n", (long long)hdb->cnt_adjrecc);
- iprintf("cnt_defrag: %" PRIdMAX "\n", (long long)hdb->cnt_defrag);
- iprintf("cnt_shiftrec: %" PRIdMAX "\n", (long long)hdb->cnt_shiftrec);
- iprintf("cnt_trunc: %" PRIdMAX "\n", (long long)hdb->cnt_trunc);
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t)hdb->cnt_writerec);
+ iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t)hdb->cnt_reuserec);
+ iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t)hdb->cnt_moverec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t)hdb->cnt_readrec);
+ iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_searchfbp);
+ iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_insertfbp);
+ iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_splicefbp);
+ iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_dividefbp);
+ iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_mergefbp);
+ iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_reducefbp);
+ iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_appenddrp);
+ iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_deferdrp);
+ iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_flushdrp);
+ iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t)hdb->cnt_adjrecc);
+ iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t)hdb->cnt_defrag);
+ iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t)hdb->cnt_shiftrec);
+ iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t)hdb->cnt_trunc);
#endif
}
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
}
tcmapdel(map);
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
/* print members of hash database */
static void mprint(TCHDB *hdb){
if(hdb->cnt_writerec < 0) return;
- iprintf("bucket number: %" PRIdMAX "\n", (long long)tchdbbnum(hdb));
- iprintf("used bucket number: %" PRIdMAX "\n", (long long)tchdbbnumused(hdb));
+ iprintf("bucket number: %" PRIdMAX "\n", (int64_t)tchdbbnum(hdb));
+ iprintf("used bucket number: %" PRIdMAX "\n", (int64_t)tchdbbnumused(hdb));
iprintf("msiz: %" PRIdMAX "\n", hdb->msiz);
iprintf("xmsiz: %" PRIdMAX "\n", hdb->xmsiz);
iprintf("fbpnum: %" PRIdMAX "\n", hdb->fbpnum);
iprintf("fbpool: %p\n", hdb->fbpool);
#ifndef NDEBUG
- iprintf("cnt_writerec: %" PRIdMAX "\n", (long long)hdb->cnt_writerec);
- iprintf("cnt_reuserec: %" PRIdMAX "\n", (long long)hdb->cnt_reuserec);
- iprintf("cnt_moverec: %" PRIdMAX "\n", (long long)hdb->cnt_moverec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (long long)hdb->cnt_readrec);
- iprintf("cnt_searchfbp: %" PRIdMAX "\n", (long long)hdb->cnt_searchfbp);
- iprintf("cnt_insertfbp: %" PRIdMAX "\n", (long long)hdb->cnt_insertfbp);
- iprintf("cnt_splicefbp: %" PRIdMAX "\n", (long long)hdb->cnt_splicefbp);
- iprintf("cnt_dividefbp: %" PRIdMAX "\n", (long long)hdb->cnt_dividefbp);
- iprintf("cnt_mergefbp: %" PRIdMAX "\n", (long long)hdb->cnt_mergefbp);
- iprintf("cnt_reducefbp: %" PRIdMAX "\n", (long long)hdb->cnt_reducefbp);
- iprintf("cnt_appenddrp: %" PRIdMAX "\n", (long long)hdb->cnt_appenddrp);
- iprintf("cnt_deferdrp: %" PRIdMAX "\n", (long long)hdb->cnt_deferdrp);
- iprintf("cnt_flushdrp: %" PRIdMAX "\n", (long long)hdb->cnt_flushdrp);
- iprintf("cnt_adjrecc: %" PRIdMAX "\n", (long long)hdb->cnt_adjrecc);
- iprintf("cnt_defrag: %" PRIdMAX "\n", (long long)hdb->cnt_defrag);
- iprintf("cnt_shiftrec: %" PRIdMAX "\n", (long long)hdb->cnt_shiftrec);
- iprintf("cnt_trunc: %" PRIdMAX "\n", (long long)hdb->cnt_trunc);
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t)hdb->cnt_writerec);
+ iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t)hdb->cnt_reuserec);
+ iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t)hdb->cnt_moverec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t)hdb->cnt_readrec);
+ iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_searchfbp);
+ iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_insertfbp);
+ iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_splicefbp);
+ iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_dividefbp);
+ iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_mergefbp);
+ iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_reducefbp);
+ iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_appenddrp);
+ iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_deferdrp);
+ iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_flushdrp);
+ iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t)hdb->cnt_adjrecc);
+ iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t)hdb->cnt_defrag);
+ iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t)hdb->cnt_shiftrec);
+ iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t)hdb->cnt_trunc);
#endif
}
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
eprint(hdb, __LINE__, "tchdbforeach");
err = true;
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
if(!tchdbclose(hdb)){
eprint(hdb, __LINE__, "(validation)");
err = true;
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tchdbfsiz(hdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
mprint(hdb);
sysprint();
tcmapdel(map);
}
tclistdel(res);
tcxstrprintf(qry->hint, "post treatment: get=%" PRIdMAX ", put=%" PRIdMAX ", out=%" PRIdMAX "\n",
- (long long) getnum, (long long) putnum, (long long) outnum);
+ (int64_t) getnum, (int64_t) putnum, (int64_t) outnum);
TDBUNLOCKMETHOD(tdb);
return !err;
}
}
tclistdel(res);
tcxstrprintf(qry->hint, "post treatment: get=%" PRIdMAX ", put=%" PRIdMAX ", out=%" PRIdMAX "\n",
- (long long) getnum, (long long) putnum, (long long) outnum);
+ (int64_t) getnum, (int64_t) putnum, (int64_t) outnum);
return !err;
}
tcmapdel(nmap);
nmap = tctdbidxgetbyfts(tdb, idx, cond, hint);
}
- tcxstrprintf(hint, "auxiliary result set size: %" PRIdMAX "\n", (long long) TCMAPRNUM(nmap));
+ tcxstrprintf(hint, "auxiliary result set size: %" PRIdMAX "\n", (int64_t) TCMAPRNUM(nmap));
return nmap;
}
int step;
TCREADVNUMBUF64(cbuf, tid, step);
char pkbuf[TCNUMBUFSIZ];
- int pksiz = sprintf(pkbuf, "%" PRIdMAX "", (long long) tid);
+ int pksiz = sprintf(pkbuf, "%" PRIdMAX "", (int64_t) tid);
if (cnt < 1) {
tcmapput(res, pkbuf, pksiz, "", 0);
} else if (wring) {
int step;
TCREADVNUMBUF64(cbuf, tid, step);
char pkbuf[TCNUMBUFSIZ];
- int pksiz = sprintf(pkbuf, "%" PRIdMAX "", (long long) tid);
+ int pksiz = sprintf(pkbuf, "%" PRIdMAX "", (int64_t) tid);
if (cnt < 1) {
tcmapput(res, pkbuf, pksiz, "", 0);
} else if (wring) {
if (off == ocr->off + rem) {
onum++;
char pkbuf[TCNUMBUFSIZ];
- int pksiz = sprintf(pkbuf, "%" PRIdMAX "", (long long) pkid);
+ int pksiz = sprintf(pkbuf, "%" PRIdMAX "", (int64_t) pkid);
if (ores) {
int rsiz;
if (tcmapget(ores, pkbuf, pksiz, &rsiz)) {
if (uniq) tcmapputkeep(uniq, pkbuf, pksiz, "", 0);
} else {
char numbuf[TCNUMBUFSIZ];
- int pksiz = sprintf(numbuf, "%" PRIdMAX "", (long long) pkid);
+ int pksiz = sprintf(numbuf, "%" PRIdMAX "", (int64_t) pkid);
if (ores) {
int rsiz;
if (tcmapget(ores, numbuf, pksiz, &rsiz)) {
if (uniq) tcmapputkeep(uniq, pkbuf, pksiz, "", 0);
} else {
char numbuf[TCNUMBUFSIZ];
- int pksiz = sprintf(numbuf, "%" PRIdMAX "", (long long) pkid);
+ int pksiz = sprintf(numbuf, "%" PRIdMAX "", (int64_t) pkid);
if (ores) {
int rsiz;
if (tcmapget(ores, numbuf, pksiz, &rsiz)) {
wp += sprintf(wp, " opts=%u", tdb->opts);
wp += sprintf(wp, " lcnum=%d", tdb->lcnum);
wp += sprintf(wp, " ncnum=%d", tdb->ncnum);
- wp += sprintf(wp, " iccmax=%" PRIdMAX "", (long long) tdb->iccmax);
+ wp += sprintf(wp, " iccmax=%" PRIdMAX "", (int64_t) tdb->iccmax);
wp += sprintf(wp, " iccsync=%f", tdb->iccsync);
wp += sprintf(wp, " idxs=%p", (void *) tdb->idxs);
wp += sprintf(wp, " inum=%d", tdb->inum);
if(flags & TDBFOPEN) printf(" open");
if(flags & TDBFFATAL) printf(" fatal");
printf("\n");
- printf("bucket number: %" PRIuMAX "\n", (unsigned long long)tctdbbnum(tdb));
+ printf("bucket number: %" PRIuMAX "\n", (uint64_t)tctdbbnum(tdb));
#ifndef NDEBUG
if(tdb->hdb->cnt_writerec >= 0)
- printf("used bucket number: %" PRIdMAX "\n", (long long)tctdbbnumused(tdb));
-#endif
+ printf("used bucket number: %" PRIdMAX "\n", (int64_t)tctdbbnumused(tdb));
+#endif
printf("alignment: %u\n", tctdbalign(tdb));
printf("free block pool: %u\n", tctdbfbpmax(tdb));
printf("index number: %d\n", tctdbinum(tdb));
switch(idxp->type){
case TDBITLEXICAL:
printf(" name=%s, type=lexical, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
- idxp->name, (long long)tcbdbrnum(idxp->db), (long long)tcbdbfsiz(idxp->db));
+ idxp->name, (int64_t)tcbdbrnum(idxp->db), (int64_t)tcbdbfsiz(idxp->db));
break;
case TDBITDECIMAL:
printf(" name=%s, type=decimal, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
- idxp->name, (long long)tcbdbrnum(idxp->db), (long long)tcbdbfsiz(idxp->db));
+ idxp->name, (int64_t)tcbdbrnum(idxp->db), (int64_t)tcbdbfsiz(idxp->db));
break;
case TDBITTOKEN:
printf(" name=%s, type=token, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
- idxp->name, (long long)tcbdbrnum(idxp->db), (long long)tcbdbfsiz(idxp->db));
+ idxp->name, (int64_t)tcbdbrnum(idxp->db), (int64_t)tcbdbfsiz(idxp->db));
break;
case TDBITQGRAM:
printf(" name=%s, type=qgram, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
- idxp->name, (long long)tcbdbrnum(idxp->db), (long long)tcbdbfsiz(idxp->db));
+ idxp->name, (int64_t)tcbdbrnum(idxp->db), (int64_t)tcbdbfsiz(idxp->db));
break;
}
}
- printf("unique ID seed: %" PRIdMAX "\n", (long long)tctdbuidseed(tdb));
- printf("inode number: %" PRIdMAX "\n", (long long)tctdbinode(tdb));
+ printf("unique ID seed: %" PRIdMAX "\n", (int64_t)tctdbuidseed(tdb));
+ printf("inode number: %" PRIdMAX "\n", (int64_t)tctdbinode(tdb));
char date[48];
tcdatestrwww(tctdbmtime(tdb), INT_MAX, date);
printf("modified time: %s\n", date);
if(opts & TDBTTCBS) printf(" tcbs");
if(opts & TDBTEXCODEC) printf(" excodec");
printf("\n");
- printf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- printf("file size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ printf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ printf("file size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
if(!tctdbclose(tdb)){
if(!err) printerr(tdb);
err = true;
bool err = false;
char pknumbuf[TCNUMBUFSIZ];
if(pksiz < 1){
- pksiz = sprintf(pknumbuf, "%" PRIdMAX "", (long long)tctdbgenuid(tdb));
+ pksiz = sprintf(pknumbuf, "%" PRIdMAX "", (int64_t)tctdbgenuid(tdb));
pkbuf = pknumbuf;
}
const char *vbuf;
if(sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
const char *pkey;
if(*line == '\0'){
- sprintf(numbuf, "%" PRIdMAX "", (long long)tctdbgenuid(tdb));
+ sprintf(numbuf, "%" PRIdMAX "", (int64_t)tctdbgenuid(tdb));
pkey = numbuf;
} else {
pkey = line;
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
}
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
eprint(tdb, __LINE__, "tctdbforeach");
err = true;
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
eprint(tdb, __LINE__, "tctdbsync");
err = true;
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctdbfsiz(tdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
sysprint();
if(!tctdbclose(tdb)){
eprint(tdb, __LINE__, "tctdbclose");
/* global variables */
-const char *g_progname; // program name
+const char *g_progname; // program name
/* function prototypes */
static int procbase(const char *ibuf, int isiz, bool dec);
static int procquote(const char *ibuf, int isiz, bool dec);
static int procmime(const char *ibuf, int isiz, bool dec, const char *ename, bool qb, bool on,
- bool hd, bool bd, int part);
+ bool hd, bool bd, int part);
static int prochex(const char *ibuf, int isiz, bool dec);
static int procpack(const char *ibuf, int isiz, bool dec, bool bwt);
static int proctcbs(const char *ibuf, int isiz, bool dec);
static int proctmpl(const char *ibuf, int isiz, TCMAP *vars);
static int procconf(int mode);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- if(argc < 2) usage();
- int 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], "hex")){
- rv = runhex(argc, argv);
- } else if(!strcmp(argv[1], "pack")){
- rv = runpack(argc, argv);
- } else if(!strcmp(argv[1], "tcbs")){
- rv = runtcbs(argc, argv);
- } else if(!strcmp(argv[1], "zlib")){
- rv = runzlib(argc, argv);
- } else if(!strcmp(argv[1], "bzip")){
- rv = runbzip(argc, argv);
- } else if(!strcmp(argv[1], "xml")){
- rv = runxml(argc, argv);
- } else if(!strcmp(argv[1], "cstr")){
- rv = runcstr(argc, argv);
- } else if(!strcmp(argv[1], "ucs")){
- rv = runucs(argc, argv);
- } else if(!strcmp(argv[1], "hash")){
- rv = runhash(argc, argv);
- } else if(!strcmp(argv[1], "cipher")){
- rv = runcipher(argc, argv);
- } else if(!strcmp(argv[1], "date")){
- rv = rundate(argc, argv);
- } else if(!strcmp(argv[1], "tmpl")){
- rv = runtmpl(argc, argv);
- } else if(!strcmp(argv[1], "conf")){
- rv = runconf(argc, argv);
- } else {
- usage();
- }
- return rv;
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ if (argc < 2) usage();
+ int 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], "hex")) {
+ rv = runhex(argc, argv);
+ } else if (!strcmp(argv[1], "pack")) {
+ rv = runpack(argc, argv);
+ } else if (!strcmp(argv[1], "tcbs")) {
+ rv = runtcbs(argc, argv);
+ } else if (!strcmp(argv[1], "zlib")) {
+ rv = runzlib(argc, argv);
+ } else if (!strcmp(argv[1], "bzip")) {
+ rv = runbzip(argc, argv);
+ } else if (!strcmp(argv[1], "xml")) {
+ rv = runxml(argc, argv);
+ } else if (!strcmp(argv[1], "cstr")) {
+ rv = runcstr(argc, argv);
+ } else if (!strcmp(argv[1], "ucs")) {
+ rv = runucs(argc, argv);
+ } else if (!strcmp(argv[1], "hash")) {
+ rv = runhash(argc, argv);
+ } else if (!strcmp(argv[1], "cipher")) {
+ rv = runcipher(argc, argv);
+ } else if (!strcmp(argv[1], "date")) {
+ rv = rundate(argc, argv);
+ } else if (!strcmp(argv[1], "tmpl")) {
+ rv = runtmpl(argc, argv);
+ } else if (!strcmp(argv[1], "conf")) {
+ rv = runconf(argc, argv);
+ } else {
+ usage();
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: popular encoders and decoders of Tokyo Cabinet\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s url [-d] [-br] [-rs base] [file]\n", g_progname);
- fprintf(stderr, " %s base [-d] [file]\n", g_progname);
- fprintf(stderr, " %s quote [-d] [file]\n", g_progname);
- fprintf(stderr, " %s mime [-d] [-en name] [-q] [-on] [-hd] [-bd] [-part num] [file]\n",
- g_progname);
- fprintf(stderr, " %s hex [-d] [file]\n", g_progname);
- fprintf(stderr, " %s pack [-d] [-bwt] [file]\n", g_progname);
- fprintf(stderr, " %s tcbs [-d] [file]\n", g_progname);
- fprintf(stderr, " %s zlib [-d] [-gz] [file]\n", g_progname);
- fprintf(stderr, " %s bzip [-d] [file]\n", g_progname);
- fprintf(stderr, " %s xml [-d] [-br] [file]\n", g_progname);
- fprintf(stderr, " %s cstr [-d] [-js] [file]\n", g_progname);
- fprintf(stderr, " %s ucs [-d] [-un] [file]\n", g_progname);
- fprintf(stderr, " %s hash [-crc] [-ch num] [file]\n", g_progname);
- fprintf(stderr, " %s cipher [-key str] [file]\n", g_progname);
- fprintf(stderr, " %s date [-ds str] [-jl num] [-wf] [-rf]\n", g_progname);
- fprintf(stderr, " %s tmpl [-var name val] [file]\n", g_progname);
- fprintf(stderr, " %s conf [-v|-i|-l|-p]\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: popular encoders and decoders of Tokyo Cabinet\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s url [-d] [-br] [-rs base] [file]\n", g_progname);
+ fprintf(stderr, " %s base [-d] [file]\n", g_progname);
+ fprintf(stderr, " %s quote [-d] [file]\n", g_progname);
+ fprintf(stderr, " %s mime [-d] [-en name] [-q] [-on] [-hd] [-bd] [-part num] [file]\n",
+ g_progname);
+ fprintf(stderr, " %s hex [-d] [file]\n", g_progname);
+ fprintf(stderr, " %s pack [-d] [-bwt] [file]\n", g_progname);
+ fprintf(stderr, " %s tcbs [-d] [file]\n", g_progname);
+ fprintf(stderr, " %s zlib [-d] [-gz] [file]\n", g_progname);
+ fprintf(stderr, " %s bzip [-d] [file]\n", g_progname);
+ fprintf(stderr, " %s xml [-d] [-br] [file]\n", g_progname);
+ fprintf(stderr, " %s cstr [-d] [-js] [file]\n", g_progname);
+ fprintf(stderr, " %s ucs [-d] [-un] [file]\n", g_progname);
+ fprintf(stderr, " %s hash [-crc] [-ch num] [file]\n", g_progname);
+ fprintf(stderr, " %s cipher [-key str] [file]\n", g_progname);
+ fprintf(stderr, " %s date [-ds str] [-jl num] [-wf] [-rf]\n", g_progname);
+ fprintf(stderr, " %s tmpl [-var name val] [file]\n", g_progname);
+ fprintf(stderr, " %s conf [-v|-i|-l|-p]\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print formatted error string */
-static void eprintf(const char *format, ...){
- va_list ap;
- va_start(ap, format);
- fprintf(stderr, "%s: ", g_progname);
- vfprintf(stderr, format, ap);
- fprintf(stderr, "\n");
- va_end(ap);
+static void eprintf(const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ fprintf(stderr, "%s: ", g_progname);
+ vfprintf(stderr, format, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
}
-
/* parse arguments of url command */
-static int runurl(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- bool br = false;
- char *base = NULL;
- for(int i = 2; i < argc; i++){
- if(!path && 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];
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runurl(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ bool br = false;
+ char *base = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!path && 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];
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = procurl(ibuf, isiz, dec, br, base);
- if(path && path[0] == '@' && !br) printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = procurl(ibuf, isiz, dec, br, base);
+ if (path && path[0] == '@' && !br) printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of base command */
-static int runbase(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runbase(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = procbase(ibuf, isiz, dec);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = procbase(ibuf, isiz, dec);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of quote command */
-static int runquote(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runquote(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = procquote(ibuf, isiz, dec);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = procquote(ibuf, isiz, dec);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of mime command */
-static int runmime(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- char *ename = NULL;
- bool qb = false;
- bool on = false;
- bool hd = false;
- bool bd = false;
- int part = -1;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else if(!strcmp(argv[i], "-en")){
- if(++i >= argc) usage();
- ename = argv[i];
- } else if(!strcmp(argv[i], "-q")){
- qb = true;
- } else if(!strcmp(argv[i], "-on")){
- on = 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();
- part = tcatoix(argv[i]);
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runmime(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ char *ename = NULL;
+ bool qb = false;
+ bool on = false;
+ bool hd = false;
+ bool bd = false;
+ int part = -1;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else if (!strcmp(argv[i], "-en")) {
+ if (++i >= argc) usage();
+ ename = argv[i];
+ } else if (!strcmp(argv[i], "-q")) {
+ qb = true;
+ } else if (!strcmp(argv[i], "-on")) {
+ on = 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();
+ part = tcatoix(argv[i]);
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- if(!ename) ename = "UTF-8";
- int rv = procmime(ibuf, isiz, dec, ename, qb, on, hd, bd, part);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ if (!ename) ename = "UTF-8";
+ int rv = procmime(ibuf, isiz, dec, ename, qb, on, hd, bd, part);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of hex command */
-static int runhex(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runhex(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = prochex(ibuf, isiz, dec);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = prochex(ibuf, isiz, dec);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of pack command */
-static int runpack(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- bool bwt = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else if(!strcmp(argv[i], "-bwt")){
- bwt = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runpack(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ bool bwt = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else if (!strcmp(argv[i], "-bwt")) {
+ bwt = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = procpack(ibuf, isiz, dec, bwt);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = procpack(ibuf, isiz, dec, bwt);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of tcbs command */
-static int runtcbs(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runtcbs(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = proctcbs(ibuf, isiz, dec);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = proctcbs(ibuf, isiz, dec);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of zlib command */
-static int runzlib(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- bool gz = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else if(!strcmp(argv[i], "-gz")){
- gz = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runzlib(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ bool gz = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else if (!strcmp(argv[i], "-gz")) {
+ gz = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = proczlib(ibuf, isiz, dec, gz);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = proczlib(ibuf, isiz, dec, gz);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of bzip command */
-static int runbzip(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runbzip(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = procbzip(ibuf, isiz, dec);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = procbzip(ibuf, isiz, dec);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of xml command */
-static int runxml(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- bool br = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else if(!strcmp(argv[i], "-br")){
- br = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runxml(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ bool br = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else if (!strcmp(argv[i], "-br")) {
+ br = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = procxml(ibuf, isiz, dec, br);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = procxml(ibuf, isiz, dec, br);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of cstr command */
-static int runcstr(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- bool js = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else if(!strcmp(argv[i], "-js")){
- js = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runcstr(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ bool js = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else if (!strcmp(argv[i], "-js")) {
+ js = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = proccstr(ibuf, isiz, dec, js);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = proccstr(ibuf, isiz, dec, js);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of ucs command */
-static int runucs(int argc, char **argv){
- char *path = NULL;
- bool dec = false;
- bool un = false;
- char *kw = NULL;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-d")){
- dec = true;
- } else if(!strcmp(argv[i], "-un")){
- un = true;
- } else if(!strcmp(argv[i], "-kw")){
- if(++i >= argc) usage();
- kw = argv[i];
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runucs(int argc, char **argv) {
+ char *path = NULL;
+ bool dec = false;
+ bool un = false;
+ char *kw = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-d")) {
+ dec = true;
+ } else if (!strcmp(argv[i], "-un")) {
+ un = true;
+ } else if (!strcmp(argv[i], "-kw")) {
+ if (++i >= argc) usage();
+ kw = argv[i];
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = procucs(ibuf, isiz, dec, un, kw);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = procucs(ibuf, isiz, dec, un, kw);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of hash command */
-static int runhash(int argc, char **argv){
- char *path = NULL;
- bool crc = false;
- int ch = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-crc")){
- crc = true;
- } else if(!strcmp(argv[i], "-ch")){
- if(++i >= argc) usage();
- ch = tcatoix(argv[i]);
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runhash(int argc, char **argv) {
+ char *path = NULL;
+ bool crc = false;
+ int ch = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-crc")) {
+ crc = true;
+ } else if (!strcmp(argv[i], "-ch")) {
+ if (++i >= argc) usage();
+ ch = tcatoix(argv[i]);
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = prochash(ibuf, isiz, crc, ch);
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = prochash(ibuf, isiz, crc, ch);
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of cipher command */
-static int runcipher(int argc, char **argv){
- char *path = NULL;
- char *key = NULL;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-key")){
- if(++i >= argc) usage();
- key = argv[i];
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runcipher(int argc, char **argv) {
+ char *path = NULL;
+ char *key = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-key")) {
+ if (++i >= argc) usage();
+ key = argv[i];
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = proccipher(ibuf, isiz, key);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = proccipher(ibuf, isiz, key);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of date command */
-static int rundate(int argc, char **argv){
- char *str = NULL;
- int jl = INT_MAX;
- bool wf = false;
- bool rf = false;
- for(int i = 2; i < argc; i++){
- if(argv[i][0] == '-'){
- if(!strcmp(argv[i], "-ds")){
- if(++i >= argc) usage();
- str = argv[i];
- } else if(!strcmp(argv[i], "-jl")){
- if(++i >= argc) usage();
- jl = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-wf")){
- wf = true;
- } else if(!strcmp(argv[i], "-rf")){
- rf = true;
- } else {
- usage();
- }
- } else {
- usage();
+static int rundate(int argc, char **argv) {
+ char *str = NULL;
+ int jl = INT_MAX;
+ bool wf = false;
+ bool rf = false;
+ for (int i = 2; i < argc; i++) {
+ if (argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-ds")) {
+ if (++i >= argc) usage();
+ str = argv[i];
+ } else if (!strcmp(argv[i], "-jl")) {
+ if (++i >= argc) usage();
+ jl = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-wf")) {
+ wf = true;
+ } else if (!strcmp(argv[i], "-rf")) {
+ rf = true;
+ } else {
+ usage();
+ }
+ } else {
+ usage();
+ }
}
- }
- int rv = procdate(str, jl, wf, rf);
- return rv;
+ int rv = procdate(str, jl, wf, rf);
+ return rv;
}
-
/* parse arguments of tmpl command */
-static int runtmpl(int argc, char **argv){
- char *path = NULL;
- TCMAP *vars = tcmpoolmapnew(tcmpoolglobal());
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-var")){
- if(++i >= argc) usage();
- const char *name = argv[i];
- if(++i >= argc) usage();
- const char *value = argv[i];
- tcmapput2(vars, name, value);
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
+static int runtmpl(int argc, char **argv) {
+ char *path = NULL;
+ TCMAP *vars = tcmpoolmapnew(tcmpoolglobal());
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-var")) {
+ if (++i >= argc) usage();
+ const char *name = argv[i];
+ if (++i >= argc) usage();
+ const char *value = argv[i];
+ tcmapput2(vars, name, value);
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
+ }
+ char *ibuf;
+ int isiz;
+ if (path && path[0] == '@') {
+ isiz = strlen(path) - 1;
+ ibuf = tcmemdup(path + 1, isiz);
} else {
- usage();
- }
- }
- char *ibuf;
- int isiz;
- if(path && path[0] == '@'){
- isiz = strlen(path) - 1;
- ibuf = tcmemdup(path + 1, isiz);
- } else {
- ibuf = tcreadfile(path, -1, &isiz);
- }
- if(!ibuf){
- eprintf("%s: cannot open", path ? path : "(stdin)");
- return 1;
- }
- int rv = proctmpl(ibuf, isiz, vars);
- if(path && path[0] == '@') printf("\n");
- tcfree(ibuf);
- return rv;
+ ibuf = tcreadfile(path, -1, &isiz);
+ }
+ if (!ibuf) {
+ eprintf("%s: cannot open", path ? path : "(stdin)");
+ return 1;
+ }
+ int rv = proctmpl(ibuf, isiz, vars);
+ if (path && path[0] == '@') printf("\n");
+ tcfree(ibuf);
+ return rv;
}
-
/* parse arguments of conf command */
-static int runconf(int argc, char **argv){
- int mode = 0;
- for(int i = 2; i < argc; i++){
- if(argv[i][0] == '-'){
- if(!strcmp(argv[i], "-v")){
- mode = 'v';
- } else if(!strcmp(argv[i], "-i")){
- mode = 'i';
- } else if(!strcmp(argv[i], "-l")){
- mode = 'l';
- } else if(!strcmp(argv[i], "-p")){
- mode = 'p';
- } else {
- usage();
- }
- } else {
- usage();
+static int runconf(int argc, char **argv) {
+ int mode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-v")) {
+ mode = 'v';
+ } else if (!strcmp(argv[i], "-i")) {
+ mode = 'i';
+ } else if (!strcmp(argv[i], "-l")) {
+ mode = 'l';
+ } else if (!strcmp(argv[i], "-p")) {
+ mode = 'p';
+ } else {
+ usage();
+ }
+ } else {
+ usage();
+ }
}
- }
- int rv = procconf(mode);
- return rv;
+ int rv = procconf(mode);
+ return rv;
}
-
/* perform url command */
-static int procurl(const char *ibuf, int isiz, bool dec, bool br, const char *base){
- if(base){
- char *obuf = tcurlresolve(base, ibuf);
- printf("%s", obuf);
- tcfree(obuf);
- } else if(br){
- TCMAP *elems = tcurlbreak(ibuf);
- const char *elem;
- if((elem = tcmapget2(elems, "self")) != NULL) printf("self: %s\n", elem);
- if((elem = tcmapget2(elems, "scheme")) != NULL) printf("scheme: %s\n", elem);
- if((elem = tcmapget2(elems, "host")) != NULL) printf("host: %s\n", elem);
- if((elem = tcmapget2(elems, "port")) != NULL) printf("port: %s\n", elem);
- if((elem = tcmapget2(elems, "authority")) != NULL) printf("authority: %s\n", elem);
- if((elem = tcmapget2(elems, "path")) != NULL) printf("path: %s\n", elem);
- if((elem = tcmapget2(elems, "file")) != NULL) printf("file: %s\n", elem);
- if((elem = tcmapget2(elems, "query")) != NULL) printf("query: %s\n", elem);
- if((elem = tcmapget2(elems, "fragment")) != NULL) printf("fragment: %s\n", elem);
- tcmapdel(elems);
- } else if(dec){
- int osiz;
- char *obuf = tcurldecode(ibuf, &osiz);
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
- } else {
- char *obuf = tcurlencode(ibuf, isiz);
- fwrite(obuf, 1, strlen(obuf), stdout);
- tcfree(obuf);
- }
- return 0;
+static int procurl(const char *ibuf, int isiz, bool dec, bool br, const char *base) {
+ if (base) {
+ char *obuf = tcurlresolve(base, ibuf);
+ printf("%s", obuf);
+ tcfree(obuf);
+ } else if (br) {
+ TCMAP *elems = tcurlbreak(ibuf);
+ const char *elem;
+ if ((elem = tcmapget2(elems, "self")) != NULL) printf("self: %s\n", elem);
+ if ((elem = tcmapget2(elems, "scheme")) != NULL) printf("scheme: %s\n", elem);
+ if ((elem = tcmapget2(elems, "host")) != NULL) printf("host: %s\n", elem);
+ if ((elem = tcmapget2(elems, "port")) != NULL) printf("port: %s\n", elem);
+ if ((elem = tcmapget2(elems, "authority")) != NULL) printf("authority: %s\n", elem);
+ if ((elem = tcmapget2(elems, "path")) != NULL) printf("path: %s\n", elem);
+ if ((elem = tcmapget2(elems, "file")) != NULL) printf("file: %s\n", elem);
+ if ((elem = tcmapget2(elems, "query")) != NULL) printf("query: %s\n", elem);
+ if ((elem = tcmapget2(elems, "fragment")) != NULL) printf("fragment: %s\n", elem);
+ tcmapdel(elems);
+ } else if (dec) {
+ int osiz;
+ char *obuf = tcurldecode(ibuf, &osiz);
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ } else {
+ char *obuf = tcurlencode(ibuf, isiz);
+ fwrite(obuf, 1, strlen(obuf), stdout);
+ tcfree(obuf);
+ }
+ return 0;
}
-
/* perform base command */
-static int procbase(const char *ibuf, int isiz, bool dec){
- if(dec){
- int osiz;
- char *obuf = tcbasedecode(ibuf, &osiz);
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
- } else {
- char *obuf = tcbaseencode(ibuf, isiz);
- fwrite(obuf, 1, strlen(obuf), stdout);
- tcfree(obuf);
- }
- return 0;
+static int procbase(const char *ibuf, int isiz, bool dec) {
+ if (dec) {
+ int osiz;
+ char *obuf = tcbasedecode(ibuf, &osiz);
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ } else {
+ char *obuf = tcbaseencode(ibuf, isiz);
+ fwrite(obuf, 1, strlen(obuf), stdout);
+ tcfree(obuf);
+ }
+ return 0;
}
-
/* perform quote command */
-static int procquote(const char *ibuf, int isiz, bool dec){
- if(dec){
- int osiz;
- char *obuf = tcquotedecode(ibuf, &osiz);
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
- } else {
- char *obuf = tcquoteencode(ibuf, isiz);
- fwrite(obuf, 1, strlen(obuf), stdout);
- tcfree(obuf);
- }
- return 0;
+static int procquote(const char *ibuf, int isiz, bool dec) {
+ if (dec) {
+ int osiz;
+ char *obuf = tcquotedecode(ibuf, &osiz);
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ } else {
+ char *obuf = tcquoteencode(ibuf, isiz);
+ fwrite(obuf, 1, strlen(obuf), stdout);
+ tcfree(obuf);
+ }
+ return 0;
}
-
/* perform mime command */
static int procmime(const char *ibuf, int isiz, bool dec, const char *ename, bool qb, bool on,
- bool hd, bool bd, int part){
- if(hd || bd || part > 0){
- TCMAP *hmap = tcmapnew2(16);
- int osiz;
- char *obuf = tcmimebreak(ibuf, isiz, hmap, &osiz);
- if(part > 0){
- const char *value;
- if(!(value = tcmapget2(hmap, "TYPE")) || !tcstrifwm(value, "multipart/") ||
- !(value = tcmapget2(hmap, "BOUNDARY"))){
- eprintf("not multipart");
- } else {
- TCLIST *parts = tcmimeparts(obuf, osiz, value);
- if(part <= tclistnum(parts)){
- int bsiz;
- const char *body = tclistval(parts, part - 1, &bsiz);
- fwrite(body, 1, bsiz, stdout);
+ bool hd, bool bd, int part) {
+ if (hd || bd || part > 0) {
+ TCMAP *hmap = tcmapnew2(16);
+ int osiz;
+ char *obuf = tcmimebreak(ibuf, isiz, hmap, &osiz);
+ if (part > 0) {
+ const char *value;
+ if (!(value = tcmapget2(hmap, "TYPE")) || !tcstrifwm(value, "multipart/") ||
+ !(value = tcmapget2(hmap, "BOUNDARY"))) {
+ eprintf("not multipart");
+ } else {
+ TCLIST *parts = tcmimeparts(obuf, osiz, value);
+ if (part <= tclistnum(parts)) {
+ int bsiz;
+ const char *body = tclistval(parts, part - 1, &bsiz);
+ fwrite(body, 1, bsiz, stdout);
+ } else {
+ eprintf("no such part");
+ }
+ tclistdel(parts);
+ }
} else {
- eprintf("no such part");
+ if (hd) {
+ TCLIST *names = tcmapkeys(hmap);
+ tclistsort(names);
+ int num = tclistnum(names);
+ for (int i = 0; i < num; i++) {
+ const char *name = tclistval2(names, i);
+ printf("%s\t%s\n", name, tcmapget2(hmap, name));
+ }
+ tclistdel(names);
+ if (bd) putchar('\n');
+ }
+ if (bd) fwrite(obuf, 1, osiz, stdout);
}
- tclistdel(parts);
- }
- } else {
- if(hd){
- TCLIST *names = tcmapkeys(hmap);
- tclistsort(names);
- int num = tclistnum(names);
- for(int i = 0; i < num; i++){
- const char *name = tclistval2(names, i);
- printf("%s\t%s\n", name, tcmapget2(hmap, name));
+ tcfree(obuf);
+ tcmapdel(hmap);
+ } else if (dec) {
+ char ebuf[32];
+ char *obuf = tcmimedecode(ibuf, ebuf);
+ if (on) {
+ fwrite(ebuf, 1, strlen(ebuf), stdout);
+ } else {
+ fwrite(obuf, 1, strlen(obuf), stdout);
}
- tclistdel(names);
- if(bd) putchar('\n');
- }
- if(bd) fwrite(obuf, 1, osiz, stdout);
- }
- tcfree(obuf);
- tcmapdel(hmap);
- } else if(dec){
- char ebuf[32];
- char *obuf = tcmimedecode(ibuf, ebuf);
- if(on){
- fwrite(ebuf, 1, strlen(ebuf), stdout);
+ tcfree(obuf);
} else {
- fwrite(obuf, 1, strlen(obuf), stdout);
+ char *obuf = tcmimeencode(ibuf, ename, !qb);
+ fwrite(obuf, 1, strlen(obuf), stdout);
+ tcfree(obuf);
}
- tcfree(obuf);
- } else {
- char *obuf = tcmimeencode(ibuf, ename, !qb);
- fwrite(obuf, 1, strlen(obuf), stdout);
- tcfree(obuf);
- }
- return 0;
+ return 0;
}
-
/* perform hex command */
-static int prochex(const char *ibuf, int isiz, bool dec){
- if(dec){
- int osiz;
- char *obuf = tchexdecode(ibuf, &osiz);
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
- } else {
- char *obuf = tchexencode(ibuf, isiz);
- fwrite(obuf, 1, strlen(obuf), stdout);
- tcfree(obuf);
- }
- return 0;
+static int prochex(const char *ibuf, int isiz, bool dec) {
+ if (dec) {
+ int osiz;
+ char *obuf = tchexdecode(ibuf, &osiz);
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ } else {
+ char *obuf = tchexencode(ibuf, isiz);
+ fwrite(obuf, 1, strlen(obuf), stdout);
+ tcfree(obuf);
+ }
+ return 0;
}
-
/* perform pack command */
-static int procpack(const char *ibuf, int isiz, bool dec, bool bwt){
- if(dec){
- int osiz;
- char *obuf = tcpackdecode(ibuf, isiz, &osiz);
- if(bwt && osiz > 0){
- int idx, step;
- TCREADVNUMBUF(obuf, idx, step);
- char *tbuf = tcbwtdecode(obuf + step, osiz - step, idx);
- fwrite(tbuf, 1, osiz - step, stdout);
- tcfree(tbuf);
+static int procpack(const char *ibuf, int isiz, bool dec, bool bwt) {
+ if (dec) {
+ int osiz;
+ char *obuf = tcpackdecode(ibuf, isiz, &osiz);
+ if (bwt && osiz > 0) {
+ int idx, step;
+ TCREADVNUMBUF(obuf, idx, step);
+ char *tbuf = tcbwtdecode(obuf + step, osiz - step, idx);
+ fwrite(tbuf, 1, osiz - step, stdout);
+ tcfree(tbuf);
+ } else {
+ fwrite(obuf, 1, osiz, stdout);
+ }
+ tcfree(obuf);
} else {
- fwrite(obuf, 1, osiz, stdout);
+ char *tbuf = NULL;
+ if (bwt) {
+ int idx;
+ tbuf = tcbwtencode(ibuf, isiz, &idx);
+ char vnumbuf[sizeof (int) + 1];
+ int step;
+ TCSETVNUMBUF(step, vnumbuf, idx);
+ tbuf = tcrealloc(tbuf, isiz + step + 1);
+ memmove(tbuf + step, tbuf, isiz);
+ memcpy(tbuf, vnumbuf, step);
+ isiz += step;
+ ibuf = tbuf;
+ }
+ int osiz;
+ char *obuf = tcpackencode(ibuf, isiz, &osiz);
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ tcfree(tbuf);
}
- tcfree(obuf);
- } else {
- char *tbuf = NULL;
- if(bwt){
- int idx;
- tbuf = tcbwtencode(ibuf, isiz, &idx);
- char vnumbuf[sizeof(int)+1];
- int step;
- TCSETVNUMBUF(step, vnumbuf, idx);
- tbuf = tcrealloc(tbuf, isiz + step + 1);
- memmove(tbuf + step, tbuf, isiz);
- memcpy(tbuf, vnumbuf, step);
- isiz += step;
- ibuf = tbuf;
- }
- int osiz;
- char *obuf = tcpackencode(ibuf, isiz, &osiz);
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
- tcfree(tbuf);
- }
- return 0;
+ return 0;
}
-
/* perform tcbs command */
-static int proctcbs(const char *ibuf, int isiz, bool dec){
- if(dec){
- int osiz;
- char *obuf = tcbsdecode(ibuf, isiz, &osiz);
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
- } else {
- int osiz;
- char *obuf = tcbsencode(ibuf, isiz, &osiz);
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
- }
- return 0;
+static int proctcbs(const char *ibuf, int isiz, bool dec) {
+ if (dec) {
+ int osiz;
+ char *obuf = tcbsdecode(ibuf, isiz, &osiz);
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ } else {
+ int osiz;
+ char *obuf = tcbsencode(ibuf, isiz, &osiz);
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ }
+ return 0;
}
-
/* perform zlib command */
-static int proczlib(const char *ibuf, int isiz, bool dec, bool gz){
- if(dec){
- int osiz;
- char *obuf = gz ? tcgzipdecode(ibuf, isiz, &osiz) : tcinflate(ibuf, isiz, &osiz);
- if(obuf){
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
- } else {
- eprintf("inflate failure");
- }
- } else {
- int osiz;
- char *obuf = gz ? tcgzipencode(ibuf, isiz, &osiz) : tcdeflate(ibuf, isiz, &osiz);
- if(obuf){
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
+static int proczlib(const char *ibuf, int isiz, bool dec, bool gz) {
+ if (dec) {
+ int osiz;
+ char *obuf = gz ? tcgzipdecode(ibuf, isiz, &osiz) : tcinflate(ibuf, isiz, &osiz);
+ if (obuf) {
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ } else {
+ eprintf("inflate failure");
+ }
} else {
- eprintf("deflate failure");
+ int osiz;
+ char *obuf = gz ? tcgzipencode(ibuf, isiz, &osiz) : tcdeflate(ibuf, isiz, &osiz);
+ if (obuf) {
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ } else {
+ eprintf("deflate failure");
+ }
}
- }
- return 0;
+ return 0;
}
-
/* perform bzip command */
-static int procbzip(const char *ibuf, int isiz, bool dec){
- if(dec){
- int osiz;
- char *obuf = tcbzipdecode(ibuf, isiz, &osiz);
- if(obuf){
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
- } else {
- eprintf("inflate failure");
- }
- } else {
- int osiz;
- char *obuf = tcbzipencode(ibuf, isiz, &osiz);
- if(obuf){
- fwrite(obuf, 1, osiz, stdout);
- tcfree(obuf);
+static int procbzip(const char *ibuf, int isiz, bool dec) {
+ if (dec) {
+ int osiz;
+ char *obuf = tcbzipdecode(ibuf, isiz, &osiz);
+ if (obuf) {
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ } else {
+ eprintf("inflate failure");
+ }
} else {
- eprintf("deflate failure");
+ int osiz;
+ char *obuf = tcbzipencode(ibuf, isiz, &osiz);
+ if (obuf) {
+ fwrite(obuf, 1, osiz, stdout);
+ tcfree(obuf);
+ } else {
+ eprintf("deflate failure");
+ }
}
- }
- return 0;
+ return 0;
}
-
/* perform xml command */
-static int procxml(const char *ibuf, int isiz, bool dec, bool br){
- if(br){
- TCLIST *elems = tcxmlbreak(ibuf);
- for(int i = 0; i < tclistnum(elems); i++){
- int esiz;
- const char *elem = tclistval(elems, i, &esiz);
- char *estr = tcmemdup(elem, esiz);
- tcstrsubchr(estr, "\t\n\r", " ");
- tcstrtrim(estr);
- if(*estr != '\0'){
- if(*elem == '<'){
- if(tcstrfwm(estr, "<!--")){
- printf("COMMENT\t%s\n", estr);
- } else if(tcstrfwm(estr, "<![CDATA[")){
- printf("CDATA\t%s\n", estr);
- } else if(tcstrfwm(estr, "<!")){
- printf("DECL\t%s\n", estr);
- } else if(tcstrfwm(estr, "<?")){
- printf("XMLDECL\t%s\n", estr);
- } else {
- TCMAP *attrs = tcxmlattrs(estr);
- tcmapiterinit(attrs);
- const char *name;
- if((name = tcmapget2(attrs, "")) != NULL){
- if(tcstrfwm(estr, "</")){
- printf("END");
- } else if(tcstrbwm(estr, "/>")){
- printf("EMPTY");
- } else {
- printf("BEGIN");
- }
- printf("\t%s", name);
- while((name = tcmapiternext2(attrs)) != NULL){
- if(*name == '\0') continue;
- printf("\t%s\t%s", name, tcmapiterval2(name));
- }
- printf("\n");
+static int procxml(const char *ibuf, int isiz, bool dec, bool br) {
+ if (br) {
+ TCLIST *elems = tcxmlbreak(ibuf);
+ for (int i = 0; i < tclistnum(elems); i++) {
+ int esiz;
+ const char *elem = tclistval(elems, i, &esiz);
+ char *estr = tcmemdup(elem, esiz);
+ tcstrsubchr(estr, "\t\n\r", " ");
+ tcstrtrim(estr);
+ if (*estr != '\0') {
+ if (*elem == '<') {
+ if (tcstrfwm(estr, "<!--")) {
+ printf("COMMENT\t%s\n", estr);
+ } else if (tcstrfwm(estr, "<![CDATA[")) {
+ printf("CDATA\t%s\n", estr);
+ } else if (tcstrfwm(estr, "<!")) {
+ printf("DECL\t%s\n", estr);
+ } else if (tcstrfwm(estr, "<?")) {
+ printf("XMLDECL\t%s\n", estr);
+ } else {
+ TCMAP *attrs = tcxmlattrs(estr);
+ tcmapiterinit(attrs);
+ const char *name;
+ if ((name = tcmapget2(attrs, "")) != NULL) {
+ if (tcstrfwm(estr, "</")) {
+ printf("END");
+ } else if (tcstrbwm(estr, "/>")) {
+ printf("EMPTY");
+ } else {
+ printf("BEGIN");
+ }
+ printf("\t%s", name);
+ while ((name = tcmapiternext2(attrs)) != NULL) {
+ if (*name == '\0') continue;
+ printf("\t%s\t%s", name, tcmapiterval2(name));
+ }
+ printf("\n");
+ }
+ tcmapdel(attrs);
+ }
+ } else {
+ char *dstr = tcxmlunescape(estr);
+ printf("TEXT\t%s\n", dstr);
+ tcfree(dstr);
+ }
}
- tcmapdel(attrs);
- }
- } else {
- char *dstr = tcxmlunescape(estr);
- printf("TEXT\t%s\n", dstr);
- tcfree(dstr);
+ tcfree(estr);
}
- }
- tcfree(estr);
+ tclistdel(elems);
+ } else if (dec) {
+ char *obuf = tcxmlunescape(ibuf);
+ fwrite(obuf, 1, strlen(obuf), stdout);
+ tcfree(obuf);
+ } else {
+ char *obuf = tcxmlescape(ibuf);
+ fwrite(obuf, 1, strlen(obuf), stdout);
+ tcfree(obuf);
}
- tclistdel(elems);
- } else if(dec){
- char *obuf = tcxmlunescape(ibuf);
- fwrite(obuf, 1, strlen(obuf), stdout);
- tcfree(obuf);
- } else {
- char *obuf = tcxmlescape(ibuf);
- fwrite(obuf, 1, strlen(obuf), stdout);
- tcfree(obuf);
- }
- return 0;
+ return 0;
}
-
/* perform cstr command */
-static int proccstr(const char *ibuf, int isiz, bool dec, bool js){
- if(js){
- if(dec){
- char *ostr = tcjsonunescape(ibuf);
- printf("%s", ostr);
- tcfree(ostr);
- } else {
- char *ostr = tcjsonescape(ibuf);
- printf("%s", ostr);
- tcfree(ostr);
- }
- } else {
- if(dec){
- char *ostr = tccstrunescape(ibuf);
- printf("%s", ostr);
- tcfree(ostr);
+static int proccstr(const char *ibuf, int isiz, bool dec, bool js) {
+ if (js) {
+ if (dec) {
+ char *ostr = tcjsonunescape(ibuf);
+ printf("%s", ostr);
+ tcfree(ostr);
+ } else {
+ char *ostr = tcjsonescape(ibuf);
+ printf("%s", ostr);
+ tcfree(ostr);
+ }
} else {
- char *ostr = tccstrescape(ibuf);
- printf("%s", ostr);
- tcfree(ostr);
+ if (dec) {
+ char *ostr = tccstrunescape(ibuf);
+ printf("%s", ostr);
+ tcfree(ostr);
+ } else {
+ char *ostr = tccstrescape(ibuf);
+ printf("%s", ostr);
+ tcfree(ostr);
+ }
}
- }
- return 0;
+ return 0;
}
-
/* perform ucs command */
-static int procucs(const char *ibuf, int isiz, bool dec, bool un, const char *kw){
- if(un){
- uint16_t *ary = tcmalloc(isiz * sizeof(uint16_t) + 1);
- int anum;
- tcstrutftoucs(ibuf, ary, &anum);
- anum = tcstrucsnorm(ary, anum, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
- char *str = tcmalloc(anum * 3 + 1);
- tcstrucstoutf(ary, anum, str);
- printf("%s", str);
- tcfree(str);
- tcfree(ary);
- } else if(kw){
- TCLIST *words = tcstrtokenize(kw);
- TCLIST *texts = tcstrkwic(ibuf, words, 10, TCKWMUTAB);
- for(int i = 0; i < tclistnum(texts); i++){
- printf("%s\n", tclistval2(texts, i));
- }
- tclistdel(texts);
- tclistdel(words);
- } else if(dec){
- uint16_t *ary = tcmalloc(isiz + 1);
- int anum = 0;
- for(int i = 0; i < isiz; i += 2){
- ary[anum++] = (((unsigned char *)ibuf)[i] << 8) + ((unsigned char *)ibuf)[i+1];
- }
- char *str = tcmalloc(isiz * 3 + 1);
- tcstrucstoutf(ary, anum, str);
- printf("%s", str);
- tcfree(str);
- tcfree(ary);
- } else {
- uint16_t *ary = tcmalloc(isiz * sizeof(uint16_t) + 1);
- int anum;
- tcstrutftoucs(ibuf, ary, &anum);
- for(int i = 0; i < anum; i++){
- int c = ary[i];
- putchar(c >> 8);
- putchar(c & 0xff);
- }
- tcfree(ary);
- }
- return 0;
+static int procucs(const char *ibuf, int isiz, bool dec, bool un, const char *kw) {
+ if (un) {
+ uint16_t *ary = tcmalloc(isiz * sizeof (uint16_t) + 1);
+ int anum;
+ tcstrutftoucs(ibuf, ary, &anum);
+ anum = tcstrucsnorm(ary, anum, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
+ char *str = tcmalloc(anum * 3 + 1);
+ tcstrucstoutf(ary, anum, str);
+ printf("%s", str);
+ tcfree(str);
+ tcfree(ary);
+ } else if (kw) {
+ TCLIST *words = tcstrtokenize(kw);
+ TCLIST *texts = tcstrkwic(ibuf, words, 10, TCKWMUTAB);
+ for (int i = 0; i < tclistnum(texts); i++) {
+ printf("%s\n", tclistval2(texts, i));
+ }
+ tclistdel(texts);
+ tclistdel(words);
+ } else if (dec) {
+ uint16_t *ary = tcmalloc(isiz + 1);
+ int anum = 0;
+ for (int i = 0; i < isiz; i += 2) {
+ ary[anum++] = (((unsigned char *) ibuf)[i] << 8) + ((unsigned char *) ibuf)[i + 1];
+ }
+ char *str = tcmalloc(isiz * 3 + 1);
+ tcstrucstoutf(ary, anum, str);
+ printf("%s", str);
+ tcfree(str);
+ tcfree(ary);
+ } else {
+ uint16_t *ary = tcmalloc(isiz * sizeof (uint16_t) + 1);
+ int anum;
+ tcstrutftoucs(ibuf, ary, &anum);
+ for (int i = 0; i < anum; i++) {
+ int c = ary[i];
+ putchar(c >> 8);
+ putchar(c & 0xff);
+ }
+ tcfree(ary);
+ }
+ return 0;
}
-
/* perform hash command */
-static int prochash(const char *ibuf, int isiz, bool crc, int ch){
- if(crc){
- printf("%08x\n", tcgetcrc(ibuf, isiz));
- } else if(ch > 0){
- TCCHIDX *chidx = tcchidxnew(ch);
- printf("%d\n", tcchidxhash(chidx, ibuf, isiz));
- tcchidxdel(chidx);
- } else {
- char buf[48];
- tcmd5hash(ibuf, isiz, buf);
- printf("%s\n", buf);
- }
- return 0;
+static int prochash(const char *ibuf, int isiz, bool crc, int ch) {
+ if (crc) {
+ printf("%08x\n", tcgetcrc(ibuf, isiz));
+ } else if (ch > 0) {
+ TCCHIDX *chidx = tcchidxnew(ch);
+ printf("%d\n", tcchidxhash(chidx, ibuf, isiz));
+ tcchidxdel(chidx);
+ } else {
+ char buf[48];
+ tcmd5hash(ibuf, isiz, buf);
+ printf("%s\n", buf);
+ }
+ return 0;
}
-
/* perform cipher command */
-static int proccipher(const char *ibuf, int isiz, const char *key){
- char *obuf = tcmalloc(isiz + 1);
- const char *kbuf = "";
- int ksiz = 0;
- if(key){
- kbuf = key;
- ksiz = strlen(key);
- }
- tcarccipher(ibuf, isiz, kbuf, ksiz, obuf);
- fwrite(obuf, 1, isiz, stdout);
- tcfree(obuf);
- return 0;
+static int proccipher(const char *ibuf, int isiz, const char *key) {
+ char *obuf = tcmalloc(isiz + 1);
+ const char *kbuf = "";
+ int ksiz = 0;
+ if (key) {
+ kbuf = key;
+ ksiz = strlen(key);
+ }
+ tcarccipher(ibuf, isiz, kbuf, ksiz, obuf);
+ fwrite(obuf, 1, isiz, stdout);
+ tcfree(obuf);
+ return 0;
}
-
/* perform date command */
-static int procdate(const char *str, int jl, bool wf, bool rf){
- int64_t t = str ? tcstrmktime(str) : time(NULL);
- if(wf){
- char buf[48];
- tcdatestrwww(t, jl, buf);
- printf("%s\n", buf);
- } else if(rf){
- char buf[48];
- tcdatestrhttp(t, jl, buf);
- printf("%s\n", buf);
- } else {
- printf("%" PRIdMAX "\n", (long long int)t);
- }
- return 0;
+static int procdate(const char *str, int jl, bool wf, bool rf) {
+ int64_t t = str ? tcstrmktime(str) : time(NULL);
+ if (wf) {
+ char buf[48];
+ tcdatestrwww(t, jl, buf);
+ printf("%s\n", buf);
+ } else if (rf) {
+ char buf[48];
+ tcdatestrhttp(t, jl, buf);
+ printf("%s\n", buf);
+ } else {
+ printf("%" PRIdMAX "\n", (int64_t) t);
+ }
+ return 0;
}
-
/* perform tmpl command */
-static int proctmpl(const char *ibuf, int isiz, TCMAP *vars){
- TCTMPL *tmpl = tctmplnew();
- tctmplload(tmpl, ibuf);
- char *str = tctmpldump(tmpl, vars);
- printf("%s", str);
- tcfree(str);
- tctmpldel(tmpl);
- return 0;
+static int proctmpl(const char *ibuf, int isiz, TCMAP *vars) {
+ TCTMPL *tmpl = tctmplnew();
+ tctmplload(tmpl, ibuf);
+ char *str = tctmpldump(tmpl, vars);
+ printf("%s", str);
+ tcfree(str);
+ tctmpldel(tmpl);
+ return 0;
}
-
/* perform conf command */
-static int procconf(int mode){
- switch(mode){
- case 'v':
- printf("%s\n", tcversion);
- break;
- case 'i':
- printf("%s\n", _TC_APPINC);
- break;
- case 'l':
- printf("%s\n", _TC_APPLIBS);
- break;
- case 'p':
- printf("%s\n", _TC_BINDIR);
- break;
- default:
- printf("myconf(version): %s\n", tcversion);
- printf("myconf(sysname): %s\n", TCSYSNAME);
- printf("myconf(libver): %d\n", _TC_LIBVER);
- printf("myconf(formatver): %s\n", _TC_FORMATVER);
- printf("myconf(prefix): %s\n", _TC_PREFIX);
- printf("myconf(includedir): %s\n", _TC_INCLUDEDIR);
- printf("myconf(libdir): %s\n", _TC_LIBDIR);
- printf("myconf(bindir): %s\n", _TC_BINDIR);
- printf("myconf(libexecdir): %s\n", _TC_LIBEXECDIR);
- printf("myconf(appinc): %s\n", _TC_APPINC);
- printf("myconf(applibs): %s\n", _TC_APPLIBS);
- printf("myconf(bigend): %d\n", TCBIGEND);
- printf("myconf(usezlib): %d\n", TCUSEZLIB);
- printf("myconf(usebzip): %d\n", TCUSEBZIP);
- printf("type(bool): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(bool), (int)_alignof(bool), TCALIGNOF(bool),
- (unsigned long long)true);
- printf("type(char): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(char), (int)_alignof(char), TCALIGNOF(char),
- (unsigned long long)CHAR_MAX);
- printf("type(short): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(short), (int)_alignof(short), TCALIGNOF(short),
- (unsigned long long)SHRT_MAX);
- printf("type(int): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(int), (int)_alignof(int), TCALIGNOF(int),
- (unsigned long long)INT_MAX);
- printf("type(long): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(long), (int)_alignof(long), TCALIGNOF(long),
- (unsigned long long)LONG_MAX);
- printf("type(long long): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(long long), (int)_alignof(long long), TCALIGNOF(long long),
- (unsigned long long)LLONG_MAX);
- printf("type(float): size=%d align=%d offset=%d max=%g\n",
- (int)sizeof(float), (int)_alignof(float), TCALIGNOF(float),
- (double)FLT_MAX);
- printf("type(double): size=%d align=%d offset=%d max=%g\n",
- (int)sizeof(double), (int)_alignof(double), TCALIGNOF(double),
- (double)DBL_MAX);
- printf("type(long double): size=%d align=%d offset=%d max=%Lg\n",
- (int)sizeof(long double), (int)_alignof(long double), TCALIGNOF(long double),
- (long double)LDBL_MAX);
- printf("type(void *): size=%d align=%d offset=%d\n",
- (int)sizeof(void *), (int)_alignof(void *), TCALIGNOF(void *));
- printf("type(intptr_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(intptr_t), (int)_alignof(intptr_t), TCALIGNOF(intptr_t),
- (unsigned long long)INTPTR_MAX);
- printf("type(size_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(size_t), (int)_alignof(size_t), TCALIGNOF(size_t),
- (unsigned long long)SIZE_MAX);
- printf("type(ptrdiff_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(ptrdiff_t), (int)_alignof(ptrdiff_t), TCALIGNOF(ptrdiff_t),
- (unsigned long long)PTRDIFF_MAX);
- printf("type(wchar_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(wchar_t), (int)_alignof(wchar_t), TCALIGNOF(wchar_t),
- (unsigned long long)WCHAR_MAX);
- printf("type(sig_atomic_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(sig_atomic_t), (int)_alignof(sig_atomic_t), TCALIGNOF(sig_atomic_t),
- (unsigned long long)SIG_ATOMIC_MAX);
- printf("type(time_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(time_t), (int)_alignof(time_t), TCALIGNOF(time_t),
- (unsigned long long)_maxof(time_t));
- printf("type(off_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(off_t), (int)_alignof(off_t), TCALIGNOF(off_t),
- (unsigned long long)_maxof(off_t));
- printf("type(ino_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
- (int)sizeof(ino_t), (int)_alignof(ino_t), TCALIGNOF(ino_t),
- (unsigned long long)_maxof(ino_t));
- printf("type(tcgeneric_t): size=%d align=%d offset=%d\n",
- (int)sizeof(tcgeneric_t), (int)_alignof(tcgeneric_t), TCALIGNOF(tcgeneric_t));
- printf("macro(RAND_MAX): %" PRIuMAX "\n", (unsigned long long)RAND_MAX);
- printf("macro(PATH_MAX): %" PRIuMAX "\n", (unsigned long long)PATH_MAX);
- printf("macro(NAME_MAX): %" PRIuMAX "\n", (unsigned long long)NAME_MAX);
+static int procconf(int mode) {
+ switch (mode) {
+ case 'v':
+ printf("%s\n", tcversion);
+ break;
+ case 'i':
+ printf("%s\n", _TC_APPINC);
+ break;
+ case 'l':
+ printf("%s\n", _TC_APPLIBS);
+ break;
+ case 'p':
+ printf("%s\n", _TC_BINDIR);
+ break;
+ default:
+ printf("myconf(version): %s\n", tcversion);
+ printf("myconf(sysname): %s\n", TCSYSNAME);
+ printf("myconf(libver): %d\n", _TC_LIBVER);
+ printf("myconf(formatver): %s\n", _TC_FORMATVER);
+ printf("myconf(prefix): %s\n", _TC_PREFIX);
+ printf("myconf(includedir): %s\n", _TC_INCLUDEDIR);
+ printf("myconf(libdir): %s\n", _TC_LIBDIR);
+ printf("myconf(bindir): %s\n", _TC_BINDIR);
+ printf("myconf(libexecdir): %s\n", _TC_LIBEXECDIR);
+ printf("myconf(appinc): %s\n", _TC_APPINC);
+ printf("myconf(applibs): %s\n", _TC_APPLIBS);
+ printf("myconf(bigend): %d\n", TCBIGEND);
+ printf("myconf(usezlib): %d\n", TCUSEZLIB);
+ printf("myconf(usebzip): %d\n", TCUSEBZIP);
+ printf("type(bool): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (bool), (int) _alignof(bool), TCALIGNOF(bool),
+ (uint64_t) true);
+ printf("type(char): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (char), (int) _alignof(char), TCALIGNOF(char),
+ (uint64_t) CHAR_MAX);
+ printf("type(short): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (short), (int) _alignof(short), TCALIGNOF(short),
+ (uint64_t) SHRT_MAX);
+ printf("type(int): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (int), (int) _alignof(int), TCALIGNOF(int),
+ (uint64_t) INT_MAX);
+ printf("type(long): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (long), (int) _alignof(long), TCALIGNOF(long),
+ (uint64_t) LONG_MAX);
+ printf("typeint64_t: size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (int64_t), (int) _alignof(int64_t), TCALIGNOF(int64_t),
+ (uint64_t) LLONG_MAX);
+ printf("type(float): size=%d align=%d offset=%d max=%g\n",
+ (int) sizeof (float), (int) _alignof(float), TCALIGNOF(float),
+ (double) FLT_MAX);
+ printf("type(double): size=%d align=%d offset=%d max=%g\n",
+ (int) sizeof (double), (int) _alignof(double), TCALIGNOF(double),
+ (double) DBL_MAX);
+ printf("type(long double): size=%d align=%d offset=%d max=%Lg\n",
+ (int) sizeof (long double), (int) _alignof(long double), TCALIGNOF(long double),
+ (long double) LDBL_MAX);
+ printf("type(void *): size=%d align=%d offset=%d\n",
+ (int) sizeof (void *), (int) _alignof(void *), TCALIGNOF(void *));
+ printf("type(intptr_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (intptr_t), (int) _alignof(intptr_t), TCALIGNOF(intptr_t),
+ (uint64_t) INTPTR_MAX);
+ printf("type(size_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (size_t), (int) _alignof(size_t), TCALIGNOF(size_t),
+ (uint64_t) SIZE_MAX);
+ printf("type(ptrdiff_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (ptrdiff_t), (int) _alignof(ptrdiff_t), TCALIGNOF(ptrdiff_t),
+ (uint64_t) PTRDIFF_MAX);
+ printf("type(wchar_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (wchar_t), (int) _alignof(wchar_t), TCALIGNOF(wchar_t),
+ (uint64_t) WCHAR_MAX);
+ printf("type(sig_atomic_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (sig_atomic_t), (int) _alignof(sig_atomic_t), TCALIGNOF(sig_atomic_t),
+ (uint64_t) SIG_ATOMIC_MAX);
+ printf("type(time_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (time_t), (int) _alignof(time_t), TCALIGNOF(time_t),
+ (uint64_t) _maxof(time_t));
+ printf("type(off_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (off_t), (int) _alignof(off_t), TCALIGNOF(off_t),
+ (uint64_t) _maxof(off_t));
+ printf("type(ino_t): size=%d align=%d offset=%d max=%" PRIuMAX "\n",
+ (int) sizeof (ino_t), (int) _alignof(ino_t), TCALIGNOF(ino_t),
+ (uint64_t) _maxof(ino_t));
+ printf("type(tcgeneric_t): size=%d align=%d offset=%d\n",
+ (int) sizeof (tcgeneric_t), (int) _alignof(tcgeneric_t), TCALIGNOF(tcgeneric_t));
+ printf("macro(RAND_MAX): %" PRIuMAX "\n", (uint64_t) RAND_MAX);
+ printf("macro(PATH_MAX): %" PRIuMAX "\n", (uint64_t) PATH_MAX);
+ printf("macro(NAME_MAX): %" PRIuMAX "\n", (uint64_t) NAME_MAX);
#ifndef _WIN32
- printf("macro(P_tmpdir): %s\n", P_tmpdir);
- printf("sysconf(_SC_OPEN_MAX): %ld\n", sysconf(_SC_OPEN_MAX));
+ printf("macro(P_tmpdir): %s\n", P_tmpdir);
+ printf("sysconf(_SC_OPEN_MAX): %ld\n", sysconf(_SC_OPEN_MAX));
#endif
- printf("sysconf(_SC_CLK_TCK): %ld\n", sysconf_SC_CLK_TCK);
- printf("sysconf(_SC_PAGESIZE): %ld\n", tcpagsize());
- TCMAP *info = tcsysinfo();
- if(info){
- tcmapiterinit(info);
- const char *name;
- while((name = tcmapiternext2(info)) != NULL){
- printf("sysinfo(%s): %s\n", name, tcmapiterval2(name));
- }
- tcmapdel(info);
- }
- struct stat sbuf;
- if(stat(MYCDIRSTR, &sbuf) == 0){
- printf("stat(st_uid): %d\n", (int)sbuf.st_uid);
- printf("stat(st_gid): %d\n", (int)sbuf.st_gid);
+ printf("sysconf(_SC_CLK_TCK): %ld\n", sysconf_SC_CLK_TCK);
+ printf("sysconf(_SC_PAGESIZE): %ld\n", tcpagsize());
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ tcmapiterinit(info);
+ const char *name;
+ while ((name = tcmapiternext2(info)) != NULL) {
+ printf("sysinfo(%s): %s\n", name, tcmapiterval2(name));
+ }
+ tcmapdel(info);
+ }
+ struct stat sbuf;
+ if (stat(MYCDIRSTR, &sbuf) == 0) {
+ printf("stat(st_uid): %d\n", (int) sbuf.st_uid);
+ printf("stat(st_gid): %d\n", (int) sbuf.st_gid);
#ifndef _WIN32
- printf("stat(st_blksize): %d\n", (int)sbuf.st_blksize);
+ printf("stat(st_blksize): %d\n", (int) sbuf.st_blksize);
#endif
- }
- }
- return 0;
+ }
+ }
+ return 0;
}
}
}
if(tr){
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcndbrnum(ndb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcndbmsiz(ndb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcndbrnum(ndb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcndbmsiz(ndb));
} else {
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcmdbrnum(mdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcmdbmsiz(mdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcmdbrnum(mdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcmdbmsiz(mdb));
}
tcndbdel(ndb);
tcmdbdel(mdb);
}
}
if(tr){
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcndbrnum(ndb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcndbmsiz(ndb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcndbrnum(ndb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcndbmsiz(ndb));
} else {
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcmdbrnum(mdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcmdbmsiz(mdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcmdbrnum(mdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcmdbmsiz(mdb));
}
tcndbdel(ndb);
tcmdbdel(mdb);
}
if(rnd && rnum > 250) iprintf(" (%08d)\n", inum);
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcmaprnum(map));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcmapmsiz(map));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcmaprnum(map));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcmapmsiz(map));
sysprint();
tcmapdel(map);
iprintf("time: %.3f\n", tctime() - stime);
}
if(rnd && rnum > 250) iprintf(" (%08d)\n", inum);
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tctreernum(tree));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tctreemsiz(tree));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctreernum(tree));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tctreemsiz(tree));
sysprint();
tctreedel(tree);
iprintf("time: %.3f\n", tctime() - stime);
}
if(rnd && rnum > 250) iprintf(" (%08d)\n", inum);
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcmdbrnum(mdb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcmdbmsiz(mdb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcmdbrnum(mdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcmdbmsiz(mdb));
sysprint();
tcmdbdel(mdb);
iprintf("time: %.3f\n", tctime() - stime);
}
if(rnd && rnum > 250) iprintf(" (%08d)\n", inum);
}
- iprintf("record number: %" PRIuMAX "\n", (unsigned long long)tcndbrnum(ndb));
- iprintf("size: %" PRIuMAX "\n", (unsigned long long)tcndbmsiz(ndb));
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcndbrnum(ndb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t)tcndbmsiz(ndb));
sysprint();
tcndbdel(ndb);
iprintf("time: %.3f\n", tctime() - stime);
case 3:
iputchar('3');
tcxstrprintf(xstr, "[%s:%d:%llu:%b:%llb]\n",
- kbuf, i, (long long)i * 65521, i, (unsigned long long)i * 65521);
+ kbuf, i, (int64_t) i * 65521, i, (unsigned long long)i * 65521);
break;
case 4:
iputchar('4');
}
if (tcstrifwm(line, "VmSize:")) {
int64_t size = tcatoix(rp);
- if (size > 0) tcmapprintf(info, "size", "%" PRIdMAX "", (long long) size);
+ if (size > 0) tcmapprintf(info, "size", "%" PRIdMAX "", (int64_t) size);
} else if (tcstrifwm(line, "VmRSS:")) {
int64_t size = tcatoix(rp);
- if (size > 0) tcmapprintf(info, "rss", "%" PRIdMAX "", (long long) size);
+ if (size > 0) tcmapprintf(info, "rss", "%" PRIdMAX "", (int64_t) size);
}
}
tclistdel(lines);
}
if (tcstrifwm(line, "MemTotal:")) {
int64_t size = tcatoix(rp);
- if (size > 0) tcmapprintf(info, "total", "%" PRIdMAX "", (long long) size);
+ if (size > 0) tcmapprintf(info, "total", "%" PRIdMAX "", (int64_t) size);
} else if (tcstrifwm(line, "MemFree:")) {
int64_t size = tcatoix(rp);
- if (size > 0) tcmapprintf(info, "free", "%" PRIdMAX "", (long long) size);
+ if (size > 0) tcmapprintf(info, "free", "%" PRIdMAX "", (int64_t) size);
} else if (tcstrifwm(line, "Cached:")) {
int64_t size = tcatoix(rp);
- if (size > 0) tcmapprintf(info, "cached", "%" PRIdMAX "", (long long) size);
+ if (size > 0) tcmapprintf(info, "cached", "%" PRIdMAX "", (int64_t) size);
}
}
tclistdel(lines);
const char *line = TCLISTVALPTR(lines, i);
if (tcstrifwm(line, "processor")) cnum++;
}
- if (cnum > 0) tcmapprintf(info, "corenum", "%" PRIdMAX "", (long long) cnum);
+ if (cnum > 0) tcmapprintf(info, "corenum", "%" PRIdMAX "", (int64_t) cnum);
tclistdel(lines);
}
return info;
rbuf.ru_stime.tv_sec + rbuf.ru_stime.tv_usec / 1000000.0);
long tck = sysconf_SC_CLK_TCK;
int64_t size = (((double) rbuf.ru_ixrss + rbuf.ru_idrss + rbuf.ru_isrss) / tck) * 1024.0;
- if (size > 0) tcmapprintf(info, "rss", "%" PRIdMAX "", (long long) size);
+ if (size > 0) tcmapprintf(info, "rss", "%" PRIdMAX "", (int64_t) size);
}
return info;
#elif defined(_WIN32)
int rsiz;
while (1) {
#ifndef _WIN32
- rsiz = read(fd, wp, limit - (wp - buf)));
+ rsiz = read(fd, wp, limit - (wp - buf));
#else
DWORD red;
if (!ReadFile(fd, wp, limit - (wp - buf), &red, NULL)) {
} else if (whence == TCFEND) {
w = SEEK_END;
}
- return (lseek(fd, off, w) != -1)
+ return (lseek(fd, off, w) != -1);
#endif
}