Commit d14fc2e1 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #1531 Ported utils to windows

git-svn-id: file:///svn/toku/tokudb@10478 c7de825b-a66e-492c-adef-691d508d4ae1
parent 48ce40ee
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
.DEFAULT_GOAL= build .DEFAULT_GOAL= build
TOKUROOT=../ TOKUROOT=../
INCLUDEDIRS=-I. INCLUDEDIRS=-I. -I$(TOKUROOT)toku_include -I$(TOKUROOT)include -I$(TOKUROOT)src
DEPEND_COMPILE += \ DEPEND_COMPILE += \
./*.h \ ./*.h \
#end #end
...@@ -14,48 +14,61 @@ include $(TOKUROOT)toku_include/Makefile.include ...@@ -14,48 +14,61 @@ include $(TOKUROOT)toku_include/Makefile.include
ifndef BDBDIR ifndef BDBDIR
BDBDIR=/usr/local/BerkeleyDB.4.4 BDBDIR=/usr/local/BerkeleyDB.4.4
endif endif
BDB_DUMP=$(BDBDIR)/bin/db_dump BDB_DUMP=$(BDBDIR)/bin/db_dump$(BINSUF)
BDB_LOAD=$(BDBDIR)/bin/db_load BDB_LOAD=$(BDBDIR)/bin/db_load$(BINSUF)
DIFF=diff -I 'db_pagesize=' DIFF=diff -w -I 'db_pagesize='
OPTFLAGS = -O2
CFLAGS = -std=gnu89 -W -Wall -Wno-unused -g $(OPTFLAGS) $(GCOV_FLAGS)
# vars to compile bins that handle tokudb using libdb.so # vars to compile bins that handle tokudb using libdb.so
# when one uses relative address in an rpath, the library better be located relative # when one uses relative address in an rpath, the library better be located relative
# to the current directory # to the current directory
CPPFLAGS = -I../include
ifneq ($(OSX),)
#Note: OSX 10.4 needs DYLD_LIBRARY_PATH. OSX 10.5 claims to support -rpath.
TDB_LOADLIBES =
BDB_LOADLIBES =
SETTOKUENV=export DYLD_LIBRARY_PATH=.. ;
UNSETTOKUENV=export DYLD_LIBRARY_PATH=$(BDBDIR)/lib ;
else
TDB_LOADLIBES = -Wl,-rpath,$(PWD)/../lib
BDB_LOADLIBES = -Wl,-rpath,$(BDBDIR)/lib
SETTOKUENV=
UNSETTOKUENV=
endif
LDFLAGS = -L../lib -ltokudb -lpthread $(TDB_LOADLIBES) -lz
# vars to compile bins that handle tokudb using libtokudb.a # vars to compile bins that handle tokudb using libtokudb.a
STATIC_CPPFLAGS = -I../include
STATIC_LDFLAGS = ../lib/libtokudb.a -lz -lpthread
# vars to compile bins that handle bdb # vars to compile bins that handle bdb
BDB_CPPFLAGS = -I$(BDBDIR)/include BDB_CPPFLAGS = -I$(BDBDIR)/include
BDB_LDFLAGS = -L$(BDBDIR)/lib -ldb -lpthread $(BDB_LOADLIBES) BDB_LDFLAGS = -L$(BDBDIR)/lib -ldb -lpthread $(BDB_LOADLIBES)
UTILS= \ UTILS= \
tokudb_gen \ tokudb_gen$(BINSUF) \
tokudb_load \ tokudb_load$(BINSUF) \
tokudb_dump \ tokudb_dump$(BINSUF) \
#End #End
BDB_UTILS=$(patsubst %,%.bdb,$(UTILS)) BDB_UTILS=$(patsubst %$(BINSUF),%.bdb$(BINSUF),$(UTILS))
STATIC_UTILS=$(patsubst %,%_static,$(UTILS)) STATIC_UTILS=$(patsubst %$(BINSUF),%_static$(BINSUF),$(UTILS))
$(UTILS): DLINK_FILES=$(TOKUROOT)lib/libtokudb.$(SOEXT)
$(STATIC_UTILS): LINK_FILES+=$(TOKUROOT)lib/libtokudb.$(AEXT)
ifeq ($(OS_CHOICE),windows)
ifdef BDBDIR
$(BDB_UTILS): INCLUDEDIRS=-I$(BDBDIR)/include
$(BDB_UTILS): RPATH_DIRS=$(BDBDIR)/lib
endif
ifeq ($(DEBUG),0)
WINDOWS_BDB_LIB_NAME=libdb.$(SOEXT)
$(WINDOWS_BDB_LIB_NAME):
cp $(BDBDIR)/lib/libdb[0-9][0-9].$(SOEXT) ./
else
WINDOWS_BDB_LIB_NAME=libdbd.$(SOEXT)
$(WINDOWS_BDB_LIB_NAME):
cp $(BDBDIR)/lib/libdb[0-9][0-9]d.$(SOEXT) ./
endif
$(BDB_UTILS): DLINK_FILES=$(BDBDIR)/lib/$(WINDOWS_BDB_LIB_NAME)
#empty
else
WINDOWS_BDB_LIB_NAME=
#linux
ifdef BDBDIR
$(BDB_UTILS): INCLUDEDIRS=-I$(BDBDIR)/include
$(BDB_UTILS): RPATH_DIRS=$(BDBDIR)/lib
endif
$(BDB_UTILS): DLINK_FILES=db.$(SOEXT)
endif
$(BDB_UTILS): CPPFLAGS+=-DTOKU_ALLOW_DEPRECATED
#empty on purpose
$(BDB_UTILS): CPPFLAGS+=-DIS_TDB=0
$(UTILS) $(STATIC_UTILS): CPPFLAGS+=-DIS_TDB=1
HERE=utils HERE=utils
...@@ -67,25 +80,35 @@ endif ...@@ -67,25 +80,35 @@ endif
.PHONY: all clean test test_gen test_gen_hex test_load test_dump .PHONY: all clean test test_gen test_gen_hex test_load test_dump
build all: $(UTILS) $(BDB_UTILS) $(STATIC_UTILS); build all: build.tdb build.bdb;
ifeq ($(OS_CHOICE),windows)
build.tdb: $(UTILS) copy.tdb;
build.bdb: $(BDB_UTILS) copy.bdb;
else
build.tdb: $(UTILS) $(STATIC_UTILS); build.tdb: $(UTILS) $(STATIC_UTILS);
build.bdb: $(BDB_UTILS); build.bdb: $(BDB_UTILS);
endif
copy.tdb:
cp ../lib/*.dll ./
copy.bdb:
cp $(BDBDIR)/lib/*.dll ./
coverage: $(UTILS) coverage: $(UTILS)
%: %.c %$(BINSUF): %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LDFLAGS) $(CC) $< $(BIN_FROM_C_FLAGS) $(LINK_MUST_BE_LAST)
%.bdb: %.c %.bdb$(BINSUF): %.c
$(CC) $(BDB_CPPFLAGS) $(CFLAGS) -o $@ $< $(BDB_LDFLAGS) $(CC) $< $(BIN_FROM_C_FLAGS) $(LINK_MUST_BE_LAST)
%_static: %.c ../lib/libtokudb.a %_static$(BINSUF): %.c ../lib/libtokudb.$(AEXT)
$(CC) $(STATIC_CPPFLAGS) $(CFLAGS) -o $@ $< $(STATIC_LDFLAGS) $(CC) $< ../lib/libtokudb.$(AEXT) $(BIN_FROM_C_FLAGS) $(LINK_MUST_BE_LAST)
strip: $(STATIC_UTILS) strip: $(STATIC_UTILS)
strip $(STATIC_UTILS) strip $(STATIC_UTILS)
check: $(UTILS) $(BDB_UTILS) $(STATIC_UTILS) test_gen test_load test_dump test_nodup test_dupsort check: build test_gen test_load test_dump test_nodup test_dupsort
test-coverage: $(UTILS) test_gen test_load test_dump test_nodup test_dupsort test-coverage: $(UTILS) test_gen test_load test_dump test_nodup test_dupsort
...@@ -96,17 +119,22 @@ TEST_GEN_HEX_LENGTHMIN=0 ...@@ -96,17 +119,22 @@ TEST_GEN_HEX_LENGTHMIN=0
TEST_GEN_HEX_LENGTHLIMIT=1024 TEST_GEN_HEX_LENGTHLIMIT=1024
TEST_GEN_HEX_FLAGS=-n $(TEST_GEN_HEX_NUMKEYS) -m $(TEST_GEN_HEX_LENGTHMIN) -M $(TEST_GEN_HEX_LENGTHLIMIT) -r 5 TEST_GEN_HEX_FLAGS=-n $(TEST_GEN_HEX_NUMKEYS) -m $(TEST_GEN_HEX_LENGTHMIN) -M $(TEST_GEN_HEX_LENGTHLIMIT) -r 5
TDB_GEN=./tokudb_gen$(BINSUF)
TDB_LOAD=./tokudb_load$(BINSUF)
TDB_DUMP=./tokudb_dump$(BINSUF)
TDB_DUMPBDB=./tokudb_dump.bdb$(BINSUF)
test_gen_hex: test_gen_hex:
#Generating $(TEST_GEN_HEX_NUMKEYS) keys. [$(TEST_GEN_HEX_LENGTHMIN),$(TEST_GEN_HEX_LENGTHLIMIT)) bytes + identifier overhead #Generating $(TEST_GEN_HEX_NUMKEYS) keys. [$(TEST_GEN_HEX_LENGTHMIN),$(TEST_GEN_HEX_LENGTHLIMIT)) bytes + identifier overhead
@#echo "Generating text input > db > text" @#echo "Generating text input > db > text"
rm -f $@.*.temp rm -f $@.*.temp
./tokudb_gen $(TEST_GEN_HEX_FLAGS) > $@.gen.temp && \ $(TDB_GEN) $(TEST_GEN_HEX_FLAGS) > $@.gen.temp && \
$(UNSETTOKUENV) $(BDB_LOAD) $@.db.temp < $@.gen.temp && \ $(BDB_LOAD) $@.db.temp < $@.gen.temp && \
$(UNSETTOKUENV) $(BDB_DUMP) $@.db.temp > $@.load_dump.temp && \ $(BDB_DUMP) $@.db.temp > $@.load_dump.temp && \
./tokudb_gen -Hf > $@.gen_sorted.temp && \ $(TDB_GEN) -H -f > $@.gen_sorted.temp && \
export LC_ALL=C;./tokudb_gen -hf $(TEST_GEN_HEX_FLAGS) -d "\t" -s "\n" | sort -k 1,1 | tr -d "\n" | tr "\t" "\n" >> $@.gen_sorted.temp && \ export LC_ALL=C;$(TDB_GEN) -h -f $(TEST_GEN_HEX_FLAGS) -d "\t" -s "\n" | sort -k 1,1 | tr -d "\n" | tr "\t" "\n" >> $@.gen_sorted.temp && \
./tokudb_gen -Fh >> $@.gen_sorted.temp && \ $(TDB_GEN) -F -h >> $@.gen_sorted.temp && \
$(DIFF) -q $@.load_dump.temp $@.gen_sorted.temp \ $(DIFF) $@.load_dump.temp $@.gen_sorted.temp \
$(SUMMARIZE_CMD) $(SUMMARIZE_CMD)
test_load: test_load_hex test_load_text test_load_text_noendline test_load: test_load_hex test_load_text test_load_text_noendline
...@@ -115,25 +143,25 @@ test_load_hex: ...@@ -115,25 +143,25 @@ test_load_hex:
#Generating $(TEST_GEN_HEX_NUMKEYS) keys. [$(TEST_GEN_HEX_LENGTHMIN),$(TEST_GEN_HEX_LENGTHLIMIT)) bytes + identifier overhead #Generating $(TEST_GEN_HEX_NUMKEYS) keys. [$(TEST_GEN_HEX_LENGTHMIN),$(TEST_GEN_HEX_LENGTHLIMIT)) bytes + identifier overhead
@#echo "Generating text input > db > text" @#echo "Generating text input > db > text"
rm -f $@.*.temp rm -f $@.*.temp
./tokudb_gen $(TEST_GEN_HEX_FLAGS) > $@.gen.temp && \ $(TDB_GEN) $(TEST_GEN_HEX_FLAGS) > $@.gen.temp && \
$(UNSETTOKUENV) $(BDB_LOAD) $@.bdb.temp < $@.gen.temp && \ $(BDB_LOAD) $@.bdb.temp < $@.gen.temp && \
$(SETTOKUENV) ./tokudb_load $@.tokudb.temp < $@.gen.temp && \ $(TDB_LOAD) $@.tokudb.temp < $@.gen.temp && \
$(UNSETTOKUENV) $(BDB_DUMP) $@.bdb.temp > $@.dump.bdb.temp && \ $(BDB_DUMP) $@.bdb.temp > $@.dump.bdb.temp && \
$(SETTOKUENV) ./tokudb_dump $@.tokudb.temp > $@.dump.tokudb.temp && \ $(TDB_DUMP) $@.tokudb.temp > $@.dump.tokudb.temp && \
$(DIFF) -q $@.dump.bdb.temp $@.dump.tokudb.temp \ $(DIFF) -q $@.dump.bdb.temp $@.dump.tokudb.temp \
$(SUMMARIZE_CMD) $(SUMMARIZE_CMD)
TEST_GEN_TEXT_FLAGS=-n $(TEST_GEN_HEX_NUMKEYS) -m $(TEST_GEN_HEX_LENGTHMIN) -M $(TEST_GEN_HEX_LENGTHLIMIT) -r 5 -TP TEST_GEN_TEXT_FLAGS=-n $(TEST_GEN_HEX_NUMKEYS) -m $(TEST_GEN_HEX_LENGTHMIN) -M $(TEST_GEN_HEX_LENGTHLIMIT) -r 5 -T -P
test_load_text: test_load_text:
#Generating $(TEST_GEN_HEX_NUMKEYS) keys. [$(TEST_GEN_HEX_LENGTHMIN),$(TEST_GEN_HEX_LENGTHLIMIT)) bytes + identifier overhead #Generating $(TEST_GEN_HEX_NUMKEYS) keys. [$(TEST_GEN_HEX_LENGTHMIN),$(TEST_GEN_HEX_LENGTHLIMIT)) bytes + identifier overhead
@#echo "Generating text input > db > text" @#echo "Generating text input > db > text"
rm -f $@.*.temp rm -f $@.*.temp
./tokudb_gen $(TEST_GEN_TEXT_FLAGS) > $@.gen.temp && \ $(TDB_GEN) $(TEST_GEN_TEXT_FLAGS) > $@.gen.temp && \
$(UNSETTOKUENV) $(BDB_LOAD) -T -t btree $@.bdb.temp < $@.gen.temp && \ $(BDB_LOAD) -T -t btree $@.bdb.temp < $@.gen.temp && \
$(SETTOKUENV) ./tokudb_load -T -t btree $@.tokudb.temp < $@.gen.temp && \ $(TDB_LOAD) -T -t btree $@.tokudb.temp < $@.gen.temp && \
$(UNSETTOKUENV) $(BDB_DUMP) -p $@.bdb.temp > $@.dump.bdb.temp && \ $(BDB_DUMP) -p $@.bdb.temp > $@.dump.bdb.temp && \
$(SETTOKUENV) ./tokudb_dump -p $@.tokudb.temp > $@.dump.tokudb.temp && \ $(TDB_DUMP) -p $@.tokudb.temp > $@.dump.tokudb.temp && \
$(DIFF) -q $@.dump.bdb.temp $@.dump.tokudb.temp \ $(DIFF) -q $@.dump.bdb.temp $@.dump.tokudb.temp \
$(SUMMARIZE_CMD) $(SUMMARIZE_CMD)
...@@ -141,43 +169,43 @@ test_load_text_noendline: ...@@ -141,43 +169,43 @@ test_load_text_noendline:
@#echo "Testing no end of line at end of file." @#echo "Testing no end of line at end of file."
rm -f $@.*.temp rm -f $@.*.temp
echo -en "key\nvalue" > $@.gen.temp echo -en "key\nvalue" > $@.gen.temp
./tokudb_load -T -t btree $@.tokudb.temp < $@.gen.temp $(SUMMARIZE_CMD) $(TDB_LOAD) -T -t btree $@.tokudb.temp < $@.gen.temp $(SUMMARIZE_CMD)
test_dump: test_dump:
#Generating $(TEST_GEN_HEX_NUMKEYS) keys. [$(TEST_GEN_HEX_LENGTHMIN),$(TEST_GEN_HEX_LENGTHLIMIT)) bytes + identifier overhead #Generating $(TEST_GEN_HEX_NUMKEYS) keys. [$(TEST_GEN_HEX_LENGTHMIN),$(TEST_GEN_HEX_LENGTHLIMIT)) bytes + identifier overhead
@#echo "Generating text input > db > text" @#echo "Generating text input > db > text"
rm -f $@.*.temp rm -f $@.*.temp
./tokudb_gen $(TEST_GEN_HEX_FLAGS) > $@.gen.temp && \ $(TDB_GEN) $(TEST_GEN_HEX_FLAGS) > $@.gen.temp && \
$(UNSETTOKUENV) $(BDB_LOAD) $@.bdb.temp < $@.gen.temp && \ $(BDB_LOAD) $@.bdb.temp < $@.gen.temp && \
$(UNSETTOKUENV) $(BDB_DUMP) $@.bdb.temp > $@.dump.bdb.temp && \ $(BDB_DUMP) $@.bdb.temp > $@.dump.bdb.temp && \
$(UNSETTOKUENV) ./tokudb_dump.bdb $@.bdb.temp > $@.dump.tokudb.temp && \ $(TDB_DUMPBDB) $@.bdb.temp > $@.dump.tokudb.temp && \
$(DIFF) -q $@.dump.bdb.temp $@.dump.tokudb.temp \ $(DIFF) -q $@.dump.bdb.temp $@.dump.tokudb.temp \
$(SUMMARIZE_CMD) $(SUMMARIZE_CMD)
test_nodup: test_nodup:
rm -rf $@.*.temp rm -rf $@.*.temp
./tokudb_gen $(TEST_GEN_HEX_FLAGS) >$@.gen.temp && \ $(TDB_GEN) $(TEST_GEN_HEX_FLAGS) >$@.gen.temp && \
$(UNSETTOKUENV) $(BDB_LOAD) $@.bdb.temp <$@.gen.temp && \ $(BDB_LOAD) $@.bdb.temp <$@.gen.temp && \
$(UNSETTOKUENV) $(BDB_DUMP) $@.bdb.temp >$@.dump.bdb.temp && \ $(BDB_DUMP) $@.bdb.temp >$@.dump.bdb.temp && \
$(SETTOKUENV) ./tokudb_load $@.tdb.temp <$@.gen.temp && \ $(TDB_LOAD) $@.tdb.temp <$@.gen.temp && \
$(SETTOKUENV) ./tokudb_dump $@.tdb.temp >$@.dump.tdb.temp && \ $(TDB_DUMP) $@.tdb.temp >$@.dump.tdb.temp && \
$(DIFF) -q $@.dump.bdb.temp $@.dump.tdb.temp && \ $(DIFF) -q $@.dump.bdb.temp $@.dump.tdb.temp && \
$(SETTOKUENV) ./tokudb_load_static $@.tdb.temp <$@.gen.temp && \ $(TDB_LOAD) $@.tdb.temp <$@.gen.temp && \
$(SETTOKUENV) ./tokudb_dump_static $@.tdb.temp >$@.dump.tdb.temp && \ $(TDB_DUMP) $@.tdb.temp >$@.dump.tdb.temp && \
$(DIFF) -q $@.dump.bdb.temp $@.dump.tdb.temp \ $(DIFF) -q $@.dump.bdb.temp $@.dump.tdb.temp \
$(SUMMARIZE_CMD) $(SUMMARIZE_CMD)
test_dupsort: test_dupsort:
rm -rf $@.*.temp rm -rf $@.*.temp
./tokudb_gen $(TEST_GEN_HEX_FLAGS) -DS >$@.gen.temp && \ $(TDB_GEN) $(TEST_GEN_HEX_FLAGS) -D -S >$@.gen.temp && \
$(UNSETTOKUENV) $(BDB_LOAD) $@.bdb.temp <$@.gen.temp && \ $(BDB_LOAD) $@.bdb.temp <$@.gen.temp && \
$(UNSETTOKUENV) $(BDB_DUMP) $@.bdb.temp >$@.dump.bdb.temp && \ $(BDB_DUMP) $@.bdb.temp >$@.dump.bdb.temp && \
$(SETTOKUENV) ./tokudb_load $@.tdb.temp <$@.gen.temp && \ $(TDB_LOAD) $@.tdb.temp <$@.gen.temp && \
$(SETTOKUENV) ./tokudb_dump $@.tdb.temp >$@.dump.tdb.temp && \ $(TDB_DUMP) $@.tdb.temp >$@.dump.tdb.temp && \
$(DIFF) -q $@.dump.bdb.temp $@.dump.tdb.temp && \ $(DIFF) -q $@.dump.bdb.temp $@.dump.tdb.temp && \
$(SETTOKUENV) ./tokudb_load_static $@.tdb.temp <$@.gen.temp && \ $(TDB_LOAD) $@.tdb.temp <$@.gen.temp && \
$(SETTOKUENV) ./tokudb_dump_static $@.tdb.temp >$@.dump.tdb.temp && \ $(TDB_DUMP) $@.tdb.temp >$@.dump.tdb.temp && \
$(DIFF) -q $@.dump.bdb.temp $@.dump.tdb.temp \ $(DIFF) -q $@.dump.bdb.temp $@.dump.tdb.temp \
$(SUMMARIZE_CMD) $(SUMMARIZE_CMD)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "tokudb_common.h" #include "tokudb_common.h"
//DB_ENV->err disabled since it does not use db_strerror //DB_ENV->err disabled since it does not use db_strerror
#define ERROR(retval, ...) \ #define PRINT_ERROR(retval, ...) \
if (0) g.dbenv->err(g.dbenv, retval, __VA_ARGS__); \ if (0) g.dbenv->err(g.dbenv, retval, __VA_ARGS__); \
else { \ else { \
fprintf(stderr, "%s: %s:", g.progname, db_strerror(retval)); \ fprintf(stderr, "%s: %s:", g.progname, db_strerror(retval)); \
...@@ -16,7 +16,7 @@ else { \ ...@@ -16,7 +16,7 @@ else { \
} }
//DB_ENV->err disabled since it does not use db_strerror, errx does not exist. //DB_ENV->err disabled since it does not use db_strerror, errx does not exist.
#define ERRORX(...) \ #define PRINT_ERRORX(...) \
if (0) g.dbenv->err(g.dbenv, 0, __VA_ARGS__); \ if (0) g.dbenv->err(g.dbenv, 0, __VA_ARGS__); \
else { \ else { \
fprintf(stderr, "%s: ", g.progname); \ fprintf(stderr, "%s: ", g.progname); \
...@@ -57,19 +57,19 @@ int name(char* str, type* num, type min, type max, int base) \ ...@@ -57,19 +57,19 @@ int name(char* str, type* num, type min, type max, int base) \
while (isspace(*str)) str++; \ while (isspace(*str)) str++; \
value = strtofunc(str, &test, base); \ value = strtofunc(str, &test, base); \
if ((*test != '\0' && *test != '\n') || test == str) { \ if ((*test != '\0' && *test != '\n') || test == str) { \
ERRORX("%s: Invalid numeric argument\n", str); \ PRINT_ERRORX("%s: Invalid numeric argument\n", str); \
errno = EINVAL; \ errno = EINVAL; \
goto error; \ goto error; \
} \ } \
if (errno != 0) { \ if (errno != 0) { \
ERROR(errno, "%s\n", str); \ PRINT_ERROR(errno, "%s\n", str); \
} \ } \
if (value < min) { \ if (value < min) { \
ERRORX("%s: Less than minimum value (%" frmt ")\n", str, min); \ PRINT_ERRORX("%s: Less than minimum value (%" frmt ")\n", str, min); \
goto error; \ goto error; \
} \ } \
if (value > max) { \ if (value > max) { \
ERRORX("%s: Greater than maximum value (%" frmt ")\n", str, max); \ PRINT_ERRORX("%s: Greater than maximum value (%" frmt ")\n", str, max); \
goto error; \ goto error; \
} \ } \
*num = value; \ *num = value; \
...@@ -78,12 +78,13 @@ error: \ ...@@ -78,12 +78,13 @@ error: \
return errno; \ return errno; \
} }
DEF_STR_TO(strtoint32, int32_t, int64_t, strtoll, PRId32); DEF_STR_TO(strtoint32, int32_t, int64_t, strtoll, PRId32)
DEF_STR_TO(strtouint32, u_int32_t, u_int64_t, strtoull, PRIu32); DEF_STR_TO(strtouint32, u_int32_t, u_int64_t, strtoull, PRIu32)
DEF_STR_TO(strtoint64, int64_t, int64_t, strtoll, PRId64); DEF_STR_TO(strtoint64, int64_t, int64_t, strtoll, PRId64)
DEF_STR_TO(strtouint64, u_int64_t, u_int64_t, strtoull, PRIu64); DEF_STR_TO(strtouint64, u_int64_t, u_int64_t, strtoull, PRIu64)
void outputbyte(u_int8_t ch) static inline void
outputbyte(u_int8_t ch)
{ {
if (g.plaintext) { if (g.plaintext) {
if (ch == '\\') printf("\\\\"); if (ch == '\\') printf("\\\\");
...@@ -93,7 +94,8 @@ void outputbyte(u_int8_t ch) ...@@ -93,7 +94,8 @@ void outputbyte(u_int8_t ch)
else printf("%02x", ch); else printf("%02x", ch);
} }
void outputstring(char* str) static inline void
outputstring(char* str)
{ {
char* p; char* p;
...@@ -102,7 +104,8 @@ void outputstring(char* str) ...@@ -102,7 +104,8 @@ void outputstring(char* str)
} }
} }
void outputplaintextstring(char* str) static inline void
outputplaintextstring(char* str)
{ {
bool old_plaintext = g.plaintext; bool old_plaintext = g.plaintext;
g.plaintext = true; g.plaintext = true;
...@@ -110,7 +113,8 @@ void outputplaintextstring(char* str) ...@@ -110,7 +113,8 @@ void outputplaintextstring(char* str)
g.plaintext = old_plaintext; g.plaintext = old_plaintext;
} }
int hextoint(int ch) static inline int
hextoint(int ch)
{ {
if (ch >= '0' && ch <= '9') { if (ch >= '0' && ch <= '9') {
return ch - '0'; return ch - '0';
...@@ -124,7 +128,8 @@ int hextoint(int ch) ...@@ -124,7 +128,8 @@ int hextoint(int ch)
return EOF; return EOF;
} }
int printabletocstring(char* inputstr, char** poutputstr) static inline int
printabletocstring(char* inputstr, char** poutputstr)
{ {
char highch; char highch;
char lowch; char lowch;
...@@ -137,7 +142,7 @@ int printabletocstring(char* inputstr, char** poutputstr) ...@@ -137,7 +142,7 @@ int printabletocstring(char* inputstr, char** poutputstr)
cstring = (char*)malloc((strlen(inputstr) + 1) * sizeof(char)); cstring = (char*)malloc((strlen(inputstr) + 1) * sizeof(char));
if (cstring == NULL) { if (cstring == NULL) {
ERROR(errno, "printabletocstring"); PRINT_ERROR(errno, "printabletocstring");
goto error; goto error;
} }
...@@ -148,21 +153,21 @@ int printabletocstring(char* inputstr, char** poutputstr) ...@@ -148,21 +153,21 @@ int printabletocstring(char* inputstr, char** poutputstr)
continue; continue;
} }
if (highch == '\0' || (lowch = *++inputstr) == '\0') { if (highch == '\0' || (lowch = *++inputstr) == '\0') {
ERROR(0, "unexpected end of input data or key/data pair"); PRINT_ERROR(0, "unexpected end of input data or key/data pair");
goto error; goto error;
} }
if (!isxdigit(highch)) { if (!isxdigit(highch)) {
ERROR(0, "Unexpected '%c' (non-hex) input.\n", highch); PRINT_ERROR(0, "Unexpected '%c' (non-hex) input.\n", highch);
goto error; goto error;
} }
if (!isxdigit(lowch)) { if (!isxdigit(lowch)) {
ERROR(0, "Unexpected '%c' (non-hex) input.\n", lowch); PRINT_ERROR(0, "Unexpected '%c' (non-hex) input.\n", lowch);
goto error; goto error;
} }
nextch = (hextoint(highch) << 4) | hextoint(lowch); nextch = (char)((hextoint(highch) << 4) | hextoint(lowch));
if (nextch == '\0') { if (nextch == '\0') {
/* Database names are c strings, and cannot have extra NULL terminators. */ /* Database names are c strings, and cannot have extra NULL terminators. */
ERROR(0, "Unexpected '\\00' in input.\n"); PRINT_ERROR(0, "Unexpected '\\00' in input.\n");
goto error; goto error;
} }
*cstring++ = nextch; *cstring++ = nextch;
...@@ -174,18 +179,19 @@ int printabletocstring(char* inputstr, char** poutputstr) ...@@ -174,18 +179,19 @@ int printabletocstring(char* inputstr, char** poutputstr)
return EXIT_SUCCESS; return EXIT_SUCCESS;
error: error:
ERROR(0, "Quitting out due to errors.\n"); PRINT_ERROR(0, "Quitting out due to errors.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
int verify_library_version() static inline int
verify_library_version()
{ {
int major; int major;
int minor; int minor;
db_version(&major, &minor, NULL); db_version(&major, &minor, NULL);
if (major != DB_VERSION_MAJOR || minor != DB_VERSION_MINOR) { if (major != DB_VERSION_MAJOR || minor != DB_VERSION_MINOR) {
ERRORX("version %d.%d doesn't match library version %d.%d\n", PRINT_ERRORX("version %d.%d doesn't match library version %d.%d\n",
DB_VERSION_MAJOR, DB_VERSION_MINOR, major, minor); DB_VERSION_MAJOR, DB_VERSION_MINOR, major, minor);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -199,22 +205,52 @@ static void catch_signal(int signal) { ...@@ -199,22 +205,52 @@ static void catch_signal(int signal) {
if (last_caught == 0) last_caught = SIGINT; if (last_caught == 0) last_caught = SIGINT;
} }
void init_catch_signals(void) { static inline void
signal(SIGHUP, catch_signal); init_catch_signals(void) {
signal(SIGINT, catch_signal); signal(SIGINT, catch_signal);
signal(SIGPIPE, catch_signal);
signal(SIGTERM, catch_signal); signal(SIGTERM, catch_signal);
#ifdef SIGHUP
signal(SIGHUP, catch_signal);
#endif
#ifdef SIGPIPE
signal(SIGPIPE, catch_signal);
#endif
} }
int caught_any_signals(void) { static inline int
caught_any_signals(void) {
return last_caught != 0; return last_caught != 0;
} }
void resend_signals(void) { static inline void
resend_signals(void) {
if (last_caught) { if (last_caught) {
signal(last_caught, SIG_DFL); signal(last_caught, SIG_DFL);
raise(last_caught); raise(last_caught);
} }
} }
#include <memory.h>
#if IS_TDB && (defined(_WIN32) || defined(_WIN64))
#include <ydb.h>
#endif
static int test_main (int argc, char *argv[]);
int
main(int argc, char *argv[]) {
int r;
#if IS_TDB && (defined(_WIN32) || defined(_WIN64))
//toku_ydb_init();
#endif
#if !IS_TDB && DB_VERSION_MINOR==4 && DB_VERSION_MINOR == 7
r = db_env_set_func_malloc(toku_malloc); assert(r==0);
r = db_env_set_func_free(toku_free); assert(r==0);
r = db_env_set_func_realloc(toku_realloc); assert(r==0);
#endif
r = test_main(argc, argv);
#if IS_TDB && (defined(_WIN32) || defined(_WIN64))
//toku_ydb_destroy();
#endif
return r;
}
#endif /* #if !defined(TOKUDB_COMMON_H) */ #endif /* #if !defined(TOKUDB_COMMON_H) */
/* -*- mode: C; c-basic-offset: 3 -*- */ /* -*- mode: C; c-basic-offset: 3 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#include <toku_portability.h>
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -33,16 +34,16 @@ typedef struct { ...@@ -33,16 +34,16 @@ typedef struct {
dump_globals g; dump_globals g;
#include "tokudb_common_funcs.h" #include "tokudb_common_funcs.h"
int usage (); static int usage (void);
int create_init_env(); static int create_init_env(void);
int dump_database (); static int dump_database (void);
int open_database (); static int open_database (void);
int dump_pairs (); static int dump_pairs (void);
int dump_footer (); static int dump_footer (void);
int dump_header (); static int dump_header (void);
int close_database (); static int close_database (void);
int main(int argc, char *argv[]) { int test_main(int argc, char *argv[]) {
int ch; int ch;
int retval; int retval;
...@@ -61,7 +62,7 @@ int main(int argc, char *argv[]) { ...@@ -61,7 +62,7 @@ int main(int argc, char *argv[]) {
while ((ch = getopt(argc, argv, "d:f:h:klNP:ps:RrVT")) != EOF) { while ((ch = getopt(argc, argv, "d:f:h:klNP:ps:RrVT")) != EOF) {
switch (ch) { switch (ch) {
case ('d'): { case ('d'): {
ERRORX("-%c option not supported.\n", ch); PRINT_ERRORX("-%c option not supported.\n", ch);
goto error; goto error;
} }
case ('f'): { case ('f'): {
...@@ -78,22 +79,22 @@ int main(int argc, char *argv[]) { ...@@ -78,22 +79,22 @@ int main(int argc, char *argv[]) {
break; break;
} }
case ('k'): { case ('k'): {
ERRORX("-%c option not supported.\n", ch); PRINT_ERRORX("-%c option not supported.\n", ch);
goto error; goto error;
} }
case ('l'): { case ('l'): {
//TODO: Implement (Requires master database support) //TODO: Implement (Requires master database support)
ERRORX("-%c option not supported.\n", ch); //YET! PRINT_ERRORX("-%c option not supported.\n", ch); //YET!
goto error; goto error;
} }
case ('N'): { case ('N'): {
ERRORX("-%c option not supported.\n", ch); PRINT_ERRORX("-%c option not supported.\n", ch);
goto error; goto error;
} }
case ('P'): { case ('P'): {
/* Clear password. */ /* Clear password. */
memset(optarg, 0, strlen(optarg)); memset(optarg, 0, strlen(optarg));
ERRORX("-%c option not supported.\n", ch); PRINT_ERRORX("-%c option not supported.\n", ch);
goto error; goto error;
} }
case ('p'): { case ('p'): {
...@@ -105,7 +106,7 @@ int main(int argc, char *argv[]) { ...@@ -105,7 +106,7 @@ int main(int argc, char *argv[]) {
/*g.recover_flags |= DB_SALVAGE | DB_AGGRESSIVE;*/ /*g.recover_flags |= DB_SALVAGE | DB_AGGRESSIVE;*/
//TODO: Implement aggressive recovery (requires db->verify()) //TODO: Implement aggressive recovery (requires db->verify())
ERRORX("-%c option not supported.\n", ch); PRINT_ERRORX("-%c option not supported.\n", ch);
goto error; goto error;
} }
case ('r'): { case ('r'): {
...@@ -113,7 +114,7 @@ int main(int argc, char *argv[]) { ...@@ -113,7 +114,7 @@ int main(int argc, char *argv[]) {
/*g.recover_flags |= DB_SALVAGE;*/ /*g.recover_flags |= DB_SALVAGE;*/
//TODO: Implement recovery (requires db->verify()) //TODO: Implement recovery (requires db->verify())
ERRORX("-%c option not supported.\n", ch); PRINT_ERRORX("-%c option not supported.\n", ch);
goto error; goto error;
} }
case ('s'): { case ('s'): {
...@@ -147,10 +148,10 @@ int main(int argc, char *argv[]) { ...@@ -147,10 +148,10 @@ int main(int argc, char *argv[]) {
if (g.subdatabase != NULL && IS_SET_ALL(g.recover_flags, DB_SALVAGE)) { if (g.subdatabase != NULL && IS_SET_ALL(g.recover_flags, DB_SALVAGE)) {
if (IS_SET_ALL(g.recover_flags, DB_AGGRESSIVE)) { if (IS_SET_ALL(g.recover_flags, DB_AGGRESSIVE)) {
ERRORX("The -s and -R options may not both be specified.\n"); PRINT_ERRORX("The -s and -R options may not both be specified.\n");
goto error; goto error;
} }
ERRORX("The -s and -r options may not both be specified.\n"); PRINT_ERRORX("The -s and -r options may not both be specified.\n");
goto error; goto error;
} }
...@@ -191,14 +192,14 @@ int dump_database() ...@@ -191,14 +192,14 @@ int dump_database()
/* Create a database handle. */ /* Create a database handle. */
retval = db_create(&g.db, g.dbenv, 0); retval = db_create(&g.db, g.dbenv, 0);
if (retval != 0) { if (retval != 0) {
ERROR(retval, "db_create"); PRINT_ERROR(retval, "db_create");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* /*
TODO: If/when supporting encryption TODO: If/when supporting encryption
if (g.password && (retval = db->set_flags(db, DB_ENCRYPT))) { if (g.password && (retval = db->set_flags(db, DB_ENCRYPT))) {
ERROR(ret, "DB->set_flags: DB_ENCRYPT"); PRINT_ERROR(ret, "DB->set_flags: DB_ENCRYPT");
goto error; goto error;
} }
*/ */
...@@ -263,7 +264,7 @@ int create_init_env() ...@@ -263,7 +264,7 @@ int create_init_env()
///TODO: UNCOMMENT/IMPLEMENT ///TODO: UNCOMMENT/IMPLEMENT
retval = dbenv->set_cachesize(dbenv, 0, cache, 1); retval = dbenv->set_cachesize(dbenv, 0, cache, 1);
if (retval) { if (retval) {
ERROR(retval, "DB_ENV->set_cachesize"); PRINT_ERROR(retval, "DB_ENV->set_cachesize");
goto error; goto error;
} }
*/ */
...@@ -276,7 +277,7 @@ int create_init_env() ...@@ -276,7 +277,7 @@ int create_init_env()
retval = dbenv->open(dbenv, g.homedir, flags, 0); retval = dbenv->open(dbenv, g.homedir, flags, 0);
if (retval) { if (retval) {
ERROR(retval, "DB_ENV->open"); PRINT_ERROR(retval, "DB_ENV->open");
goto error; goto error;
} }
success: success:
...@@ -313,7 +314,7 @@ int dump_header() ...@@ -313,7 +314,7 @@ int dump_header()
} }
//TODO: Uncomment when db->get_flags is implemented //TODO: Uncomment when db->get_flags is implemented
if ((retval = db->get_flags(db, &flags)) != 0) { if ((retval = db->get_flags(db, &flags)) != 0) {
ERROR(retval, "DB->get_flags"); PRINT_ERROR(retval, "DB->get_flags");
goto error; goto error;
} }
DUMP_IGNORED_FLAG(DB_CHKSUM, "chksum=1\n"); DUMP_IGNORED_FLAG(DB_CHKSUM, "chksum=1\n");
...@@ -350,22 +351,22 @@ int open_database() ...@@ -350,22 +351,22 @@ int open_database()
retval = db->open(db, NULL, g.database, g.subdatabase, g.dbtype, open_flags, 0666); retval = db->open(db, NULL, g.database, g.subdatabase, g.dbtype, open_flags, 0666);
if (retval != 0) { if (retval != 0) {
ERROR(retval, "DB->open: %s", g.database); PRINT_ERROR(retval, "DB->open: %s", g.database);
goto error; goto error;
} }
//TODO: Uncomment when DB_UNKNOWN + db->get_type are implemented. //TODO: Uncomment when DB_UNKNOWN + db->get_type are implemented.
/* /*
retval = db->get_type(db, &g.opened_dbtype); retval = db->get_type(db, &g.opened_dbtype);
if (retval != 0) { if (retval != 0) {
ERROR(retval, "DB->get_type"); PRINT_ERROR(retval, "DB->get_type");
goto error; goto error;
} }
if (g.opened_dbtype != DB_BTREE) { if (g.opened_dbtype != DB_BTREE) {
ERRORX("Unsupported db type %d\n", g.opened_dbtype); PRINT_ERRORX("Unsupported db type %d\n", g.opened_dbtype);
goto error; goto error;
} }
if (g.dbtype != DB_UNKNOWN && g.opened_dbtype != g.dbtype) { if (g.dbtype != DB_UNKNOWN && g.opened_dbtype != g.dbtype) {
ERRORX("DBTYPE %d does not match opened DBTYPE %d.\n", g.dbtype, g.opened_dbtype); PRINT_ERRORX("DBTYPE %d does not match opened DBTYPE %d.\n", g.dbtype, g.opened_dbtype);
goto error; goto error;
}*/ }*/
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -374,7 +375,7 @@ error: ...@@ -374,7 +375,7 @@ error:
return EXIT_FAILURE; return EXIT_FAILURE;
} }
int dump_dbt(DBT* dbt) static int dump_dbt(DBT* dbt)
{ {
char* str; char* str;
u_int32_t index; u_int32_t index;
...@@ -414,7 +415,7 @@ int dump_pairs() ...@@ -414,7 +415,7 @@ int dump_pairs()
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
if ((retval = db->cursor(db, (DB_TXN*)NULL, &dbc, 0)) != 0) { if ((retval = db->cursor(db, (DB_TXN*)NULL, &dbc, 0)) != 0) {
ERROR(retval, "DB->cursor"); PRINT_ERROR(retval, "DB->cursor");
goto error; goto error;
} }
while ((retval = dbc->c_get(dbc, &key, &data, DB_NEXT)) == 0) { while ((retval = dbc->c_get(dbc, &key, &data, DB_NEXT)) == 0) {
...@@ -423,7 +424,7 @@ int dump_pairs() ...@@ -423,7 +424,7 @@ int dump_pairs()
if (dump_dbt(&data) != 0) goto error; if (dump_dbt(&data) != 0) goto error;
} }
if (retval != DB_NOTFOUND) { if (retval != DB_NOTFOUND) {
ERROR(retval, "DBC->c_get"); PRINT_ERROR(retval, "DBC->c_get");
goto error; goto error;
} }
...@@ -434,7 +435,7 @@ error: ...@@ -434,7 +435,7 @@ error:
} }
cleanup: cleanup:
if (dbc && (retval = dbc->c_close(dbc)) != 0) { if (dbc && (retval = dbc->c_close(dbc)) != 0) {
ERROR(retval, "DBC->c_close"); PRINT_ERROR(retval, "DBC->c_close");
g.exitcode = EXIT_FAILURE; g.exitcode = EXIT_FAILURE;
} }
success: success:
...@@ -448,7 +449,7 @@ int close_database() ...@@ -448,7 +449,7 @@ int close_database()
assert(db); assert(db);
if ((retval = db->close(db, 0)) != 0) { if ((retval = db->close(db, 0)) != 0) {
ERROR(retval, "DB->close"); PRINT_ERROR(retval, "DB->close");
goto error; goto error;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
/* -*- mode: C; c-basic-offset: 3 -*- */ /* -*- mode: C; c-basic-offset: 3 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#include <toku_portability.h>
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -10,6 +11,9 @@ ...@@ -10,6 +11,9 @@
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <db.h> #include <db.h>
#if IS_TDB
#include <ydb.h>
#endif
#include "tokudb_common.h" #include "tokudb_common.h"
...@@ -22,9 +26,9 @@ typedef struct { ...@@ -22,9 +26,9 @@ typedef struct {
gen_globals g; gen_globals g;
#include "tokudb_common_funcs.h" #include "tokudb_common_funcs.h"
int usage(void); static int usage(void);
void generate_keys(void); static void generate_keys(void);
int get_delimiter(char* str); static int get_delimiter(char* str);
...@@ -49,7 +53,7 @@ bool force_unique = true; ...@@ -49,7 +53,7 @@ bool force_unique = true;
bool duplicates = false; bool duplicates = false;
bool dupsort = false; bool dupsort = false;
int main (int argc, char *argv[]) { static int test_main (int argc, char *argv[]) {
int ch; int ch;
/* Set up the globals. */ /* Set up the globals. */
...@@ -81,14 +85,14 @@ int main (int argc, char *argv[]) { ...@@ -81,14 +85,14 @@ int main (int argc, char *argv[]) {
} }
case ('o'): { case ('o'): {
if (freopen(optarg, "w", stdout) == NULL) { if (freopen(optarg, "w", stdout) == NULL) {
ERROR(errno, "%s: reopen\n", optarg); PRINT_ERROR(errno, "%s: reopen\n", optarg);
goto error; goto error;
} }
break; break;
} }
case ('r'): { case ('r'): {
if (strtouint32(optarg, &seed, 0, UINT32_MAX, 10)) { if (strtouint32(optarg, &seed, 0, UINT32_MAX, 10)) {
ERRORX("%s: (-r) Random seed invalid.", optarg); PRINT_ERRORX("%s: (-r) Random seed invalid.", optarg);
goto error; goto error;
} }
set_seed = true; set_seed = true;
...@@ -96,7 +100,7 @@ int main (int argc, char *argv[]) { ...@@ -96,7 +100,7 @@ int main (int argc, char *argv[]) {
} }
case ('m'): { case ('m'): {
if (strtouint32(optarg, &lengthmin, 0, UINT32_MAX, 10)) { if (strtouint32(optarg, &lengthmin, 0, UINT32_MAX, 10)) {
ERRORX("%s: (-m) Min length of keys/values invalid.", optarg); PRINT_ERRORX("%s: (-m) Min length of keys/values invalid.", optarg);
goto error; goto error;
} }
set_lengthmin = true; set_lengthmin = true;
...@@ -104,7 +108,7 @@ int main (int argc, char *argv[]) { ...@@ -104,7 +108,7 @@ int main (int argc, char *argv[]) {
} }
case ('M'): { case ('M'): {
if (strtouint32(optarg, &lengthlimit, 1, UINT32_MAX, 10)) { if (strtouint32(optarg, &lengthlimit, 1, UINT32_MAX, 10)) {
ERRORX("%s: (-M) Limit of key/value length invalid.", optarg); PRINT_ERRORX("%s: (-M) Limit of key/value length invalid.", optarg);
goto error; goto error;
} }
set_lengthlimit = true; set_lengthlimit = true;
...@@ -112,7 +116,7 @@ int main (int argc, char *argv[]) { ...@@ -112,7 +116,7 @@ int main (int argc, char *argv[]) {
} }
case ('n'): { case ('n'): {
if (strtouint64(optarg, &numkeys, 0, UINT64_MAX, 10)) { if (strtouint64(optarg, &numkeys, 0, UINT64_MAX, 10)) {
ERRORX("%s: (-n) Number of keys to generate invalid.", optarg); PRINT_ERRORX("%s: (-n) Number of keys to generate invalid.", optarg);
goto error; goto error;
} }
set_numkeys = true; set_numkeys = true;
...@@ -141,12 +145,12 @@ int main (int argc, char *argv[]) { ...@@ -141,12 +145,12 @@ int main (int argc, char *argv[]) {
case ('d'): { case ('d'): {
int temp = get_delimiter(optarg); int temp = get_delimiter(optarg);
if (temp == EOF) { if (temp == EOF) {
ERRORX("%s: (-d) Key (or value) delimiter must be one character.", PRINT_ERRORX("%s: (-d) Key (or value) delimiter must be one character.",
optarg); optarg);
goto error; goto error;
} }
if (isxdigit(temp)) { if (isxdigit(temp)) {
ERRORX("%c: (-d) Key (or value) delimiter cannot be a hex digit.", PRINT_ERRORX("%c: (-d) Key (or value) delimiter cannot be a hex digit.",
temp); temp);
goto error; goto error;
} }
...@@ -156,12 +160,12 @@ int main (int argc, char *argv[]) { ...@@ -156,12 +160,12 @@ int main (int argc, char *argv[]) {
case ('s'): { case ('s'): {
int temp = get_delimiter(optarg); int temp = get_delimiter(optarg);
if (temp == EOF) { if (temp == EOF) {
ERRORX("%s: (-s) Sorting (Between key/value pairs) delimiter must be one character.", PRINT_ERRORX("%s: (-s) Sorting (Between key/value pairs) delimiter must be one character.",
optarg); optarg);
goto error; goto error;
} }
if (isxdigit(temp)) { if (isxdigit(temp)) {
ERRORX("%c: (-s) Sorting (Between key/value pairs) delimiter cannot be a hex digit.", PRINT_ERRORX("%c: (-s) Sorting (Between key/value pairs) delimiter cannot be a hex digit.",
temp); temp);
goto error; goto error;
} }
...@@ -185,55 +189,55 @@ int main (int argc, char *argv[]) { ...@@ -185,55 +189,55 @@ int main (int argc, char *argv[]) {
argv += optind; argv += optind;
if (justheader && !header) { if (justheader && !header) {
ERRORX("The -h and -H options may not both be specified.\n"); PRINT_ERRORX("The -h and -H options may not both be specified.\n");
goto error; goto error;
} }
if (justfooter && !footer) { if (justfooter && !footer) {
ERRORX("The -f and -F options may not both be specified.\n"); PRINT_ERRORX("The -f and -F options may not both be specified.\n");
goto error; goto error;
} }
if (justfooter && justheader) { if (justfooter && justheader) {
ERRORX("The -H and -F options may not both be specified.\n"); PRINT_ERRORX("The -H and -F options may not both be specified.\n");
goto error; goto error;
} }
if (justfooter && header) { if (justfooter && header) {
ERRORX("-F implies -h\n"); PRINT_ERRORX("-F implies -h\n");
header = false; header = false;
} }
if (justheader && footer) { if (justheader && footer) {
ERRORX("-H implies -f\n"); PRINT_ERRORX("-H implies -f\n");
footer = false; footer = false;
} }
if (!leadingspace) { if (!leadingspace) {
if (footer) { if (footer) {
ERRORX("-p implies -f\n"); PRINT_ERRORX("-p implies -f\n");
footer = false; footer = false;
} }
if (header) { if (header) {
ERRORX("-p implies -h\n"); PRINT_ERRORX("-p implies -h\n");
header = false; header = false;
} }
} }
if (justfooter || justheader) outputkeys = false; if (justfooter || justheader) outputkeys = false;
else if (!set_numkeys) else if (!set_numkeys)
{ {
ERRORX("Using default number of keys. (-n 1024).\n"); PRINT_ERRORX("Using default number of keys. (-n 1024).\n");
numkeys = 1024; numkeys = 1024;
} }
if (outputkeys && !set_seed) { if (outputkeys && !set_seed) {
ERRORX("Using default seed. (-r 1).\n"); PRINT_ERRORX("Using default seed. (-r 1).\n");
seed = 1; seed = 1;
} }
if (outputkeys && !set_lengthmin) { if (outputkeys && !set_lengthmin) {
ERRORX("Using default lengthmin. (-m 0).\n"); PRINT_ERRORX("Using default lengthmin. (-m 0).\n");
lengthmin = 0; lengthmin = 0;
} }
if (outputkeys && !set_lengthlimit) { if (outputkeys && !set_lengthlimit) {
ERRORX("Using default lengthlimit. (-M 1024).\n"); PRINT_ERRORX("Using default lengthlimit. (-M 1024).\n");
lengthlimit = 1024; lengthlimit = 1024;
} }
if (outputkeys && lengthmin >= lengthlimit) { if (outputkeys && lengthmin >= lengthlimit) {
ERRORX("Max key size must be greater than min key size.\n"); PRINT_ERRORX("Max key size must be greater than min key size.\n");
goto error; goto error;
} }
...@@ -260,7 +264,7 @@ error: ...@@ -260,7 +264,7 @@ error:
return EXIT_FAILURE; return EXIT_FAILURE;
} }
int usage() static int usage()
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s [-PpTuVhHfFDS] [-o output] [-r seed] [-m minsize] [-M limitsize]\n" "usage: %s [-PpTuVhHfFDS] [-o output] [-r seed] [-m minsize] [-M limitsize]\n"
...@@ -269,7 +273,7 @@ int usage() ...@@ -269,7 +273,7 @@ int usage()
return EXIT_FAILURE; return EXIT_FAILURE;
} }
u_int8_t randbyte() static u_int8_t randbyte()
{ {
static u_int32_t numsavedbits = 0; static u_int32_t numsavedbits = 0;
static u_int64_t savedbits = 0; static u_int64_t savedbits = 0;
...@@ -286,13 +290,13 @@ u_int8_t randbyte() ...@@ -286,13 +290,13 @@ u_int8_t randbyte()
} }
/* Almost-uniformly random int from [0,limit) */ /* Almost-uniformly random int from [0,limit) */
int32_t random_below(int32_t limit) static int32_t random_below(int32_t limit)
{ {
assert(limit > 0); assert(limit > 0);
return random() % limit; return random() % limit;
} }
void generate_keys() static void generate_keys()
{ {
bool usedemptykey = false; bool usedemptykey = false;
u_int64_t numgenerated = 0; u_int64_t numgenerated = 0;
...@@ -361,7 +365,9 @@ int get_delimiter(char* str) ...@@ -361,7 +365,9 @@ int get_delimiter(char* str)
switch (str[1]) { switch (str[1]) {
case ('a'): return '\a'; case ('a'): return '\a';
case ('b'): return '\b'; case ('b'): return '\b';
#ifndef __ICL
case ('e'): return '\e'; case ('e'): return '\e';
#endif
case ('f'): return '\f'; case ('f'): return '\f';
case ('n'): return '\n'; case ('n'): return '\n';
case ('r'): return '\r'; case ('r'): return '\r';
......
/* -*- mode: C; c-basic-offset: 3 -*- */ /* -*- mode: C; c-basic-offset: 3 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#include <toku_portability.h>
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -42,18 +43,18 @@ typedef struct { ...@@ -42,18 +43,18 @@ typedef struct {
load_globals g; load_globals g;
#include "tokudb_common_funcs.h" #include "tokudb_common_funcs.h"
int usage (); static int usage (void);
int longusage (); static int longusage (void);
int load_database (); static int load_database (void);
int create_init_env(); static int create_init_env(void);
int read_header (); static int read_header (void);
int open_database (); static int open_database (void);
int read_keys (); static int read_keys (void);
int apply_commandline_options(); static int apply_commandline_options(void);
int close_database (); static int close_database (void);
int doublechararray(char** pmem, u_int64_t* size); static int doublechararray(char** pmem, u_int64_t* size);
int main(int argc, char *argv[]) { int test_main(int argc, char *argv[]) {
int ch; int ch;
int retval; int retval;
char** next_config_option; char** next_config_option;
...@@ -62,8 +63,8 @@ int main(int argc, char *argv[]) { ...@@ -62,8 +63,8 @@ int main(int argc, char *argv[]) {
memset(&g, 0, sizeof(g)); memset(&g, 0, sizeof(g));
g.leadingspace = true; g.leadingspace = true;
g.overwritekeys = true; g.overwritekeys = true;
//TODO: g.dbtype = DB_UNKNOWN; when defined. g.dbtype = DB_UNKNOWN;
g.dbtype = DB_BTREE; //g.dbtype = DB_BTREE;
g.progname = argv[0]; g.progname = argv[0];
g.header = true; g.header = true;
...@@ -71,7 +72,7 @@ int main(int argc, char *argv[]) { ...@@ -71,7 +72,7 @@ int main(int argc, char *argv[]) {
next_config_option = g.config_options = (char**) calloc(argc, sizeof(char*)); next_config_option = g.config_options = (char**) calloc(argc, sizeof(char*));
if (next_config_option == NULL) { if (next_config_option == NULL) {
ERROR(errno, "main: calloc\n"); PRINT_ERROR(errno, "main: calloc\n");
goto error; goto error;
} }
while ((ch = getopt(argc, argv, "c:f:h:nP:r:Tt:V")) != EOF) { while ((ch = getopt(argc, argv, "c:f:h:nP:r:Tt:V")) != EOF) {
...@@ -95,17 +96,17 @@ int main(int argc, char *argv[]) { ...@@ -95,17 +96,17 @@ int main(int argc, char *argv[]) {
} }
case ('n'): { case ('n'): {
/* g.overwritekeys = false; */ /* g.overwritekeys = false; */
ERRORX("-%c option not supported.\n", ch); PRINT_ERRORX("-%c option not supported.\n", ch);
goto error; goto error;
} }
case ('P'): { case ('P'): {
/* Clear password. */ /* Clear password. */
memset(optarg, 0, strlen(optarg)); memset(optarg, 0, strlen(optarg));
ERRORX("-%c option not supported.\n", ch); PRINT_ERRORX("-%c option not supported.\n", ch);
goto error; goto error;
} }
case ('r'): { case ('r'): {
ERRORX("-%c option not supported.\n", ch); PRINT_ERRORX("-%c option not supported.\n", ch);
goto error; goto error;
} }
case ('T'): { case ('T'): {
...@@ -181,7 +182,7 @@ int load_database() ...@@ -181,7 +182,7 @@ int load_database()
/* Create a database handle. */ /* Create a database handle. */
retval = db_create(&g.db, g.dbenv, 0); retval = db_create(&g.db, g.dbenv, 0);
if (retval != 0) { if (retval != 0) {
ERROR(retval, "db_create"); PRINT_ERROR(retval, "db_create");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -195,7 +196,7 @@ int load_database() ...@@ -195,7 +196,7 @@ int load_database()
/* /*
TODO: If/when supporting encryption TODO: If/when supporting encryption
if (g.password && (retval = db->set_flags(db, DB_ENCRYPT))) { if (g.password && (retval = db->set_flags(db, DB_ENCRYPT))) {
ERROR(ret, "DB->set_flags: DB_ENCRYPT"); PRINT_ERROR(ret, "DB->set_flags: DB_ENCRYPT");
goto error; goto error;
} }
*/ */
...@@ -243,7 +244,7 @@ int create_init_env() ...@@ -243,7 +244,7 @@ int create_init_env()
/* /*
TODO: If/when supporting encryption TODO: If/when supporting encryption
if (g.password && (retval = dbenv->set_encrypt(dbenv, g.password, DB_ENCRYPT_AES))) { if (g.password && (retval = dbenv->set_encrypt(dbenv, g.password, DB_ENCRYPT_AES))) {
ERROR(retval, "set_passwd"); PRINT_ERROR(retval, "set_passwd");
goto error; goto error;
} }
*/ */
...@@ -262,7 +263,7 @@ int create_init_env() ...@@ -262,7 +263,7 @@ int create_init_env()
///TODO: UNCOMMENT/IMPLEMENT ///TODO: UNCOMMENT/IMPLEMENT
retval = dbenv->set_cachesize(dbenv, 0, cache, 1); retval = dbenv->set_cachesize(dbenv, 0, cache, 1);
if (retval) { if (retval) {
ERROR(retval, "DB_ENV->set_cachesize"); PRINT_ERROR(retval, "DB_ENV->set_cachesize");
goto error; goto error;
} }
*/ */
...@@ -275,7 +276,7 @@ int create_init_env() ...@@ -275,7 +276,7 @@ int create_init_env()
retval = dbenv->open(dbenv, g.homedir ? g.homedir : ".", flags, 0); retval = dbenv->open(dbenv, g.homedir ? g.homedir : ".", flags, 0);
if (retval) { if (retval) {
ERROR(retval, "DB_ENV->open"); PRINT_ERROR(retval, "DB_ENV->open");
goto error; goto error;
} }
success: success:
...@@ -295,25 +296,25 @@ if (!strcmp(field, match)) { \ ...@@ -295,25 +296,25 @@ if (!strcmp(field, match)) { \
#define PARSE_UNSUPPORTEDNUMBER(match, dbfunction) \ #define PARSE_UNSUPPORTEDNUMBER(match, dbfunction) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strtoint32(value, &num, 1, INT32_MAX, 10)) goto error; \ if (strtoint32(value, &num, 1, INT32_MAX, 10)) goto error; \
ERRORX("%s option not supported.\n", field); \ PRINT_ERRORX("%s option not supported.\n", field); \
goto error; \ goto error; \
} }
#define PARSE_IGNOREDNUMBER(match, dbfunction) \ #define PARSE_IGNOREDNUMBER(match, dbfunction) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strtoint32(value, &num, 1, INT32_MAX, 10)) goto error; \ if (strtoint32(value, &num, 1, INT32_MAX, 10)) goto error; \
ERRORX("%s option not supported yet (ignored).\n", field); \ PRINT_ERRORX("%s option not supported yet (ignored).\n", field); \
continue; \ continue; \
} }
#define PARSE_FLAG(match, flag) \ #define PARSE_FLAG(match, flag) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strtoint32(value, &num, 0, 1, 10)) { \ if (strtoint32(value, &num, 0, 1, 10)) { \
ERRORX("%s: boolean name=value pairs require a value of 0 or 1", \ PRINT_ERRORX("%s: boolean name=value pairs require a value of 0 or 1", \
field); \ field); \
goto error; \ goto error; \
} \ } \
if ((retval = db->set_flags(db, flag)) != 0) { \ if ((retval = db->set_flags(db, flag)) != 0) { \
ERROR(retval, "set_flags: %s", field); \ PRINT_ERROR(retval, "set_flags: %s", field); \
goto error; \ goto error; \
} \ } \
continue; \ continue; \
...@@ -322,29 +323,29 @@ if (!strcmp(field, match)) { \ ...@@ -322,29 +323,29 @@ if (!strcmp(field, match)) { \
#define PARSE_UNSUPPORTEDFLAG(match, flag) \ #define PARSE_UNSUPPORTEDFLAG(match, flag) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strtoint32(value, &num, 0, 1, 10)) { \ if (strtoint32(value, &num, 0, 1, 10)) { \
ERRORX("%s: boolean name=value pairs require a value of 0 or 1", \ PRINT_ERRORX("%s: boolean name=value pairs require a value of 0 or 1", \
field); \ field); \
goto error; \ goto error; \
} \ } \
ERRORX("%s option not supported.\n", field); \ PRINT_ERRORX("%s option not supported.\n", field); \
goto error; \ goto error; \
} }
#define PARSE_IGNOREDFLAG(match, flag) \ #define PARSE_IGNOREDFLAG(match, flag) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strtoint32(value, &num, 0, 1, 10)) { \ if (strtoint32(value, &num, 0, 1, 10)) { \
ERRORX("%s: boolean name=value pairs require a value of 0 or 1", \ PRINT_ERRORX("%s: boolean name=value pairs require a value of 0 or 1", \
field); \ field); \
goto error; \ goto error; \
} \ } \
ERRORX("%s option not supported yet (ignored).\n", field); \ PRINT_ERRORX("%s option not supported yet (ignored).\n", field); \
continue; \ continue; \
} }
#define PARSE_CHAR(match, dbfunction) \ #define PARSE_CHAR(match, dbfunction) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strlen(value) != 1) { \ if (strlen(value) != 1) { \
ERRORX("%s=%s: Expected 1-byte value", \ PRINT_ERRORX("%s=%s: Expected 1-byte value", \
field, value); \ field, value); \
goto error; \ goto error; \
} \ } \
...@@ -357,11 +358,11 @@ if (!strcmp(field, match)) { \ ...@@ -357,11 +358,11 @@ if (!strcmp(field, match)) { \
#define PARSE_UNSUPPORTEDCHAR(match, dbfunction) \ #define PARSE_UNSUPPORTEDCHAR(match, dbfunction) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strlen(value) != 1) { \ if (strlen(value) != 1) { \
ERRORX("%s=%s: Expected 1-byte value", \ PRINT_ERRORX("%s=%s: Expected 1-byte value", \
field, value); \ field, value); \
goto error; \ goto error; \
} \ } \
ERRORX("%s option not supported.\n", field); \ PRINT_ERRORX("%s option not supported.\n", field); \
goto error; \ goto error; \
} }
...@@ -393,11 +394,12 @@ int read_header() ...@@ -393,11 +394,12 @@ int read_header()
int retval; int retval;
DB* db = g.db; DB* db = g.db;
DB_ENV* dbenv = g.dbenv; DB_ENV* dbenv = g.dbenv;
int r;
assert(g.header); assert(g.header);
if (g.read_header.data == NULL && (g.read_header.data = (char*)malloc(datasize * sizeof(char))) == NULL) { if (g.read_header.data == NULL && (g.read_header.data = (char*)malloc(datasize * sizeof(char))) == NULL) {
ERROR(errno, "read_header: malloc"); PRINT_ERROR(errno, "read_header: malloc");
goto error; goto error;
} }
while (!g.eof) { while (!g.eof) {
...@@ -413,7 +415,7 @@ int read_header() ...@@ -413,7 +415,7 @@ int read_header()
} }
if (ch == '\n') break; if (ch == '\n') break;
g.read_header.data[index] = ch; g.read_header.data[index] = (char)ch;
index++; index++;
/* Ensure room exists for next character/null terminator. */ /* Ensure room exists for next character/null terminator. */
...@@ -433,7 +435,7 @@ int read_header() ...@@ -433,7 +435,7 @@ int read_header()
if (!strcmp(field, "VERSION")) { if (!strcmp(field, "VERSION")) {
if (strtoint32(value, &g.version, 1, INT32_MAX, 10)) goto error; if (strtoint32(value, &g.version, 1, INT32_MAX, 10)) goto error;
if (g.version != 3) { if (g.version != 3) {
ERRORX("line %"PRIu64": VERSION %d is unsupported", g.linenumber, g.version); PRINT_ERRORX("line %"PRIu64": VERSION %d is unsupported", g.linenumber, g.version);
goto error; goto error;
} }
continue; continue;
...@@ -455,10 +457,10 @@ int read_header() ...@@ -455,10 +457,10 @@ int read_header()
continue; continue;
} }
if (!strcmp(value, "hash") || strcmp(value, "recno") || strcmp(value, "queue")) { if (!strcmp(value, "hash") || strcmp(value, "recno") || strcmp(value, "queue")) {
ERRORX("db type %s not supported.\n", value); PRINT_ERRORX("db type %s not supported.\n", value);
goto error; goto error;
} }
ERRORX("line %"PRIu64": unknown type %s", g.linenumber, value); PRINT_ERRORX("line %"PRIu64": unknown type %s", g.linenumber, value);
goto error; goto error;
} }
if (!strcmp(field, "database") || !strcmp(field, "subdatabase")) { if (!strcmp(field, "database") || !strcmp(field, "subdatabase")) {
...@@ -467,7 +469,7 @@ int read_header() ...@@ -467,7 +469,7 @@ int read_header()
g.subdatabase = NULL; g.subdatabase = NULL;
} }
if ((retval = printabletocstring(value, &g.subdatabase))) { if ((retval = printabletocstring(value, &g.subdatabase))) {
ERROR(retval, "error reading db name"); PRINT_ERROR(retval, "error reading db name");
goto error; goto error;
} }
continue; continue;
...@@ -475,40 +477,43 @@ int read_header() ...@@ -475,40 +477,43 @@ int read_header()
if (!strcmp(field, "keys")) { if (!strcmp(field, "keys")) {
int32_t temp; int32_t temp;
if (strtoint32(value, &temp, 0, 1, 10)) { if (strtoint32(value, &temp, 0, 1, 10)) {
ERROR(0, PRINT_ERROR(0,
"%s: boolean name=value pairs require a value of 0 or 1", "%s: boolean name=value pairs require a value of 0 or 1",
field); field);
goto error; goto error;
} }
g.keys = temp; g.keys = (bool)temp;
if (!g.keys) { if (!g.keys) {
ERRORX("keys=0 not supported"); PRINT_ERRORX("keys=0 not supported");
goto error; goto error;
} }
continue; continue;
} }
PARSE_COMMON_CONFIGURATIONS(); PARSE_COMMON_CONFIGURATIONS();
ERRORX("unknown input-file header configuration keyword \"%s\"", field); PRINT_ERRORX("unknown input-file header configuration keyword \"%s\"", field);
goto error; goto error;
} }
success: success:
return EXIT_SUCCESS; r = 0;
if (false) { if (false) {
printerror: printerror:
ERROR(retval, "%s=%s", field, value); r = EXIT_FAILURE;
PRINT_ERROR(retval, "%s=%s", field, value);
} }
if (false) { if (false) {
formaterror: formaterror:
ERRORX("line %"PRIu64": unexpected format", g.linenumber); r = EXIT_FAILURE;
PRINT_ERRORX("line %"PRIu64": unexpected format", g.linenumber);
} }
error: error:
return EXIT_FAILURE; return r;
} }
int apply_commandline_options() int apply_commandline_options()
{ {
int r;
char** next_config_option = g.config_options; char** next_config_option = g.config_options;
unsigned index; unsigned index;
char* field; char* field;
...@@ -529,14 +534,14 @@ int apply_commandline_options() ...@@ -529,14 +534,14 @@ int apply_commandline_options()
field = g.config_options[index]; field = g.config_options[index];
if ((value = strchr(field, '=')) == NULL) { if ((value = strchr(field, '=')) == NULL) {
ERRORX("command-line configuration uses name=value format"); PRINT_ERRORX("command-line configuration uses name=value format");
goto error; goto error;
} }
value[0] = '\0'; value[0] = '\0';
value++; value++;
if (field[0] == '\0' || value[0] == '\0') { if (field[0] == '\0' || value[0] == '\0') {
ERRORX("command-line configuration uses name=value format"); PRINT_ERRORX("command-line configuration uses name=value format");
goto error; goto error;
} }
...@@ -546,7 +551,7 @@ int apply_commandline_options() ...@@ -546,7 +551,7 @@ int apply_commandline_options()
g.subdatabase = NULL; g.subdatabase = NULL;
} }
if ((retval = printabletocstring(value, &g.subdatabase))) { if ((retval = printabletocstring(value, &g.subdatabase))) {
ERROR(retval, "error reading db name"); PRINT_ERROR(retval, "error reading db name");
goto error; goto error;
} }
continue; continue;
...@@ -554,21 +559,21 @@ int apply_commandline_options() ...@@ -554,21 +559,21 @@ int apply_commandline_options()
if (!strcmp(field, "keys")) { if (!strcmp(field, "keys")) {
int32_t temp; int32_t temp;
if (strtoint32(value, &temp, 0, 1, 10)) { if (strtoint32(value, &temp, 0, 1, 10)) {
ERROR(0, PRINT_ERROR(0,
"%s: boolean name=value pairs require a value of 0 or 1", "%s: boolean name=value pairs require a value of 0 or 1",
field); field);
goto error; goto error;
} }
g.keys = temp; g.keys = (bool)temp;
if (!g.keys) { if (!g.keys) {
ERRORX("keys=0 not supported"); PRINT_ERRORX("keys=0 not supported");
goto error; goto error;
} }
continue; continue;
} }
PARSE_COMMON_CONFIGURATIONS(); PARSE_COMMON_CONFIGURATIONS();
ERRORX("unknown input-file header configuration keyword \"%s\"", field); PRINT_ERRORX("unknown input-file header configuration keyword \"%s\"", field);
goto error; goto error;
} }
if (value) { if (value) {
...@@ -576,14 +581,15 @@ int apply_commandline_options() ...@@ -576,14 +581,15 @@ int apply_commandline_options()
value[-1] = '='; value[-1] = '=';
value = NULL; value = NULL;
} }
return EXIT_SUCCESS; r = 0;
if (false) { if (false) {
printerror: printerror:
ERROR(retval, "%s=%s", field, value); r = EXIT_FAILURE;
PRINT_ERROR(retval, "%s=%s", field, value);
} }
error: error:
return EXIT_FAILURE; return r;
} }
int open_database() int open_database()
...@@ -604,7 +610,7 @@ int open_database() ...@@ -604,7 +610,7 @@ int open_database()
//TODO: Uncomment when DB_UNKNOWN + db->get_type are implemented. //TODO: Uncomment when DB_UNKNOWN + db->get_type are implemented.
/* /*
if (g.dbtype == DB_UNKNOWN) { if (g.dbtype == DB_UNKNOWN) {
ERRORX("no database type specified"); PRINT_ERRORX("no database type specified");
goto error; goto error;
}*/ }*/
SET_BITS(open_flags, DB_CREATE); SET_BITS(open_flags, DB_CREATE);
...@@ -612,21 +618,21 @@ int open_database() ...@@ -612,21 +618,21 @@ int open_database()
retval = db->open(db, NULL, g.database, g.subdatabase, g.dbtype, open_flags, 0666); retval = db->open(db, NULL, g.database, g.subdatabase, g.dbtype, open_flags, 0666);
} }
if (retval != 0) { if (retval != 0) {
ERROR(retval, "DB->open: %s", g.database); PRINT_ERROR(retval, "DB->open: %s", g.database);
goto error; goto error;
} }
//TODO: Uncomment when DB_UNKNOWN + db->get_type are implemented. //TODO: Uncomment when DB_UNKNOWN + db->get_type are implemented.
/* /*
if ((retval = db->get_type(db, &opened_type)) != 0) { if ((retval = db->get_type(db, &opened_type)) != 0) {
ERROR(retval, "DB->get_type"); PRINT_ERROR(retval, "DB->get_type");
goto error; goto error;
} }
if (opened_type != DB_BTREE) { if (opened_type != DB_BTREE) {
ERRORX("Unsupported db type %d\n", opened_type); PRINT_ERRORX("Unsupported db type %d\n", opened_type);
goto error; goto error;
} }
if (g.dbtype != DB_UNKNOWN && opened_type != g.dbtype) { if (g.dbtype != DB_UNKNOWN && opened_type != g.dbtype) {
ERRORX("DBTYPE %d does not match opened DBTYPE %d.\n", g.dbtype, opened_type); PRINT_ERRORX("DBTYPE %d does not match opened DBTYPE %d.\n", g.dbtype, opened_type);
goto error; goto error;
}*/ }*/
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -646,11 +652,11 @@ int doublechararray(char** pmem, u_int64_t* size) ...@@ -646,11 +652,11 @@ int doublechararray(char** pmem, u_int64_t* size)
*size <<= 1; *size <<= 1;
if (*size == 0) { if (*size == 0) {
/* Overflowed u_int64_t. */ /* Overflowed u_int64_t. */
ERRORX("Line %"PRIu64": Line too long.\n", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Line too long.\n", g.linenumber);
goto error; goto error;
} }
if ((*pmem = (char*)realloc(*pmem, *size)) == NULL) { if ((*pmem = (char*)realloc(*pmem, *size)) == NULL) {
ERROR(errno, "doublechararray: realloc"); PRINT_ERROR(errno, "doublechararray: realloc");
goto error; goto error;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -659,7 +665,7 @@ error: ...@@ -659,7 +665,7 @@ error:
return EXIT_FAILURE; return EXIT_FAILURE;
} }
int get_dbt(DBT* pdbt) static int get_dbt(DBT* pdbt)
{ {
DB_ENV* dbenv = g.dbenv; DB_ENV* dbenv = g.dbenv;
/* Need to store a key and value. */ /* Need to store a key and value. */
...@@ -675,7 +681,7 @@ int get_dbt(DBT* pdbt) ...@@ -675,7 +681,7 @@ int get_dbt(DBT* pdbt)
which = 1 - which; which = 1 - which;
if (g.get_dbt.data[which] == NULL && if (g.get_dbt.data[which] == NULL &&
(g.get_dbt.data[which] = (char*)malloc(datasize[which] * sizeof(char))) == NULL) { (g.get_dbt.data[which] = (char*)malloc(datasize[which] * sizeof(char))) == NULL) {
ERROR(errno, "get_dbt: malloc"); PRINT_ERROR(errno, "get_dbt: malloc");
goto error; goto error;
} }
...@@ -701,22 +707,22 @@ int get_dbt(DBT* pdbt) ...@@ -701,22 +707,22 @@ int get_dbt(DBT* pdbt)
} }
else if (highch == EOF) { else if (highch == EOF) {
g.eof = true; g.eof = true;
ERRORX("Line %"PRIu64": Unexpected end of file (2 hex digits per byte).\n", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Unexpected end of file (2 hex digits per byte).\n", g.linenumber);
goto error; goto error;
} }
else if (!isxdigit(highch)) { else if (!isxdigit(highch)) {
ERRORX("Line %"PRIu64": Unexpected '%c' (non-hex) input.\n", g.linenumber, highch); PRINT_ERRORX("Line %"PRIu64": Unexpected '%c' (non-hex) input.\n", g.linenumber, highch);
goto error; goto error;
} }
lowch = getchar(); lowch = getchar();
if (lowch == EOF) { if (lowch == EOF) {
g.eof = true; g.eof = true;
ERRORX("Line %"PRIu64": Unexpected end of file (2 hex digits per byte).\n", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Unexpected end of file (2 hex digits per byte).\n", g.linenumber);
goto error; goto error;
} }
else if (!isxdigit(lowch)) { else if (!isxdigit(lowch)) {
ERRORX("Line %"PRIu64": Unexpected '%c' (non-hex) input.\n", g.linenumber, lowch); PRINT_ERRORX("Line %"PRIu64": Unexpected '%c' (non-hex) input.\n", g.linenumber, lowch);
goto error; goto error;
} }
...@@ -728,7 +734,7 @@ int get_dbt(DBT* pdbt) ...@@ -728,7 +734,7 @@ int get_dbt(DBT* pdbt)
nextch = firstch; nextch = firstch;
break; break;
} }
ERRORX("Line %"PRIu64": Nonprintable character found.", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Nonprintable character found.", g.linenumber);
goto error; goto error;
} }
} }
...@@ -740,7 +746,7 @@ int get_dbt(DBT* pdbt) ...@@ -740,7 +746,7 @@ int get_dbt(DBT* pdbt)
if (doublechararray(&g.get_dbt.data[which], &datasize[which])) goto error; if (doublechararray(&g.get_dbt.data[which], &datasize[which])) goto error;
datum = g.get_dbt.data[which]; datum = g.get_dbt.data[which];
} }
datum[index] = nextch; datum[index] = (char)nextch;
index++; index++;
} }
if (firstch == EOF) g.eof = true; if (firstch == EOF) g.eof = true;
...@@ -755,15 +761,15 @@ int get_dbt(DBT* pdbt) ...@@ -755,15 +761,15 @@ int get_dbt(DBT* pdbt)
lowch = getchar(); lowch = getchar();
if (lowch == EOF) { if (lowch == EOF) {
g.eof = true; g.eof = true;
ERRORX("Line %"PRIu64": Unexpected end of file (2 hex digits per byte).\n", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Unexpected end of file (2 hex digits per byte).\n", g.linenumber);
goto error; goto error;
} }
if (!isxdigit(highch)) { if (!isxdigit(highch)) {
ERRORX("Line %"PRIu64": Unexpected '%c' (non-hex) input.\n", g.linenumber, highch); PRINT_ERRORX("Line %"PRIu64": Unexpected '%c' (non-hex) input.\n", g.linenumber, highch);
goto error; goto error;
} }
if (!isxdigit(lowch)) { if (!isxdigit(lowch)) {
ERRORX("Line %"PRIu64": Unexpected '%c' (non-hex) input.\n", g.linenumber, lowch); PRINT_ERRORX("Line %"PRIu64": Unexpected '%c' (non-hex) input.\n", g.linenumber, lowch);
goto error; goto error;
} }
if (index == datasize[which]) { if (index == datasize[which]) {
...@@ -771,7 +777,7 @@ int get_dbt(DBT* pdbt) ...@@ -771,7 +777,7 @@ int get_dbt(DBT* pdbt)
if (doublechararray(&g.get_dbt.data[which], &datasize[which])) goto error; if (doublechararray(&g.get_dbt.data[which], &datasize[which])) goto error;
datum = g.get_dbt.data[which]; datum = g.get_dbt.data[which];
} }
datum[index] = (hextoint(highch) << 4) | hextoint(lowch); datum[index] = (char)((hextoint(highch) << 4) | hextoint(lowch));
index++; index++;
} }
if (highch == EOF) g.eof = true; if (highch == EOF) g.eof = true;
...@@ -789,7 +795,7 @@ error: ...@@ -789,7 +795,7 @@ error:
#define DB_YESOVERWRITE 0 #define DB_YESOVERWRITE 0
#endif #endif
int insert_pair(DBT* key, DBT* data) static int insert_pair(DBT* key, DBT* data)
{ {
DB_ENV* dbenv = g.dbenv; DB_ENV* dbenv = g.dbenv;
DB* db = g.db; DB* db = g.db;
...@@ -797,7 +803,7 @@ int insert_pair(DBT* key, DBT* data) ...@@ -797,7 +803,7 @@ int insert_pair(DBT* key, DBT* data)
int retval = db->put(db, NULL, key, data, g.overwritekeys ? DB_YESOVERWRITE : DB_NOOVERWRITE); int retval = db->put(db, NULL, key, data, g.overwritekeys ? DB_YESOVERWRITE : DB_NOOVERWRITE);
if (retval != 0) { if (retval != 0) {
//TODO: Check for transaction failures/etc.. retry if necessary. //TODO: Check for transaction failures/etc.. retry if necessary.
ERROR(retval, "DB->put"); PRINT_ERROR(retval, "DB->put");
if (!(retval == DB_KEYEXIST && g.overwritekeys)) goto error; if (!(retval == DB_KEYEXIST && g.overwritekeys)) goto error;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -834,7 +840,7 @@ int read_keys() ...@@ -834,7 +840,7 @@ int read_keys()
//Last entry had no newline. Done. //Last entry had no newline. Done.
break; break;
} }
ERRORX("Line %"PRIu64": Key exists but value missing.", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Key exists but value missing.", g.linenumber);
goto error; goto error;
} }
g.linenumber++; g.linenumber++;
...@@ -867,13 +873,13 @@ int read_keys() ...@@ -867,13 +873,13 @@ int read_keys()
} }
default: { default: {
unexpectedinput: unexpectedinput:
ERRORX("Line %"PRIu64": Unexpected input while reading key.\n", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Unexpected input while reading key.\n", g.linenumber);
goto error; goto error;
} }
} }
if (g.eof) { if (g.eof) {
ERRORX("Line %"PRIu64": Key exists but value missing.", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Key exists but value missing.", g.linenumber);
goto error; goto error;
} }
g.linenumber++; g.linenumber++;
...@@ -881,7 +887,7 @@ unexpectedinput: ...@@ -881,7 +887,7 @@ unexpectedinput:
switch (spacech) { switch (spacech) {
case (EOF): { case (EOF): {
g.eof = true; g.eof = true;
ERRORX("Line %"PRIu64": Unexpected end of file while reading value.\n", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Unexpected end of file while reading value.\n", g.linenumber);
goto error; goto error;
} }
case (' '): { case (' '): {
...@@ -890,7 +896,7 @@ unexpectedinput: ...@@ -890,7 +896,7 @@ unexpectedinput:
break; break;
} }
default: { default: {
ERRORX("Line %"PRIu64": Unexpected input while reading value.\n", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Unexpected input while reading value.\n", g.linenumber);
goto error; goto error;
} }
} }
...@@ -910,7 +916,7 @@ int close_database() ...@@ -910,7 +916,7 @@ int close_database()
assert(db); assert(db);
if ((retval = db->close(db, 0)) != 0) { if ((retval = db->close(db, 0)) != 0) {
ERROR(retval, "DB->close"); PRINT_ERROR(retval, "DB->close");
goto error; goto error;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment