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
This diff is collapsed.
......@@ -7,7 +7,7 @@
#include "tokudb_common.h"
//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__); \
else { \
fprintf(stderr, "%s: %s:", g.progname, db_strerror(retval)); \
......@@ -16,7 +16,7 @@ else { \
}
//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__); \
else { \
fprintf(stderr, "%s: ", g.progname); \
......@@ -57,19 +57,19 @@ int name(char* str, type* num, type min, type max, int base) \
while (isspace(*str)) str++; \
value = strtofunc(str, &test, base); \
if ((*test != '\0' && *test != '\n') || test == str) { \
ERRORX("%s: Invalid numeric argument\n", str); \
PRINT_ERRORX("%s: Invalid numeric argument\n", str); \
errno = EINVAL; \
goto error; \
} \
if (errno != 0) { \
ERROR(errno, "%s\n", str); \
PRINT_ERROR(errno, "%s\n", str); \
} \
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; \
} \
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; \
} \
*num = value; \
......@@ -78,12 +78,13 @@ error: \
return errno; \
}
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(strtoint64, int64_t, int64_t, strtoll, PRId64);
DEF_STR_TO(strtouint64, u_int64_t, u_int64_t, strtoull, PRIu64);
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(strtoint64, int64_t, int64_t, strtoll, PRId64)
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 (ch == '\\') printf("\\\\");
......@@ -93,7 +94,8 @@ void outputbyte(u_int8_t ch)
else printf("%02x", ch);
}
void outputstring(char* str)
static inline void
outputstring(char* str)
{
char* p;
......@@ -102,7 +104,8 @@ void outputstring(char* str)
}
}
void outputplaintextstring(char* str)
static inline void
outputplaintextstring(char* str)
{
bool old_plaintext = g.plaintext;
g.plaintext = true;
......@@ -110,7 +113,8 @@ void outputplaintextstring(char* str)
g.plaintext = old_plaintext;
}
int hextoint(int ch)
static inline int
hextoint(int ch)
{
if (ch >= '0' && ch <= '9') {
return ch - '0';
......@@ -124,7 +128,8 @@ int hextoint(int ch)
return EOF;
}
int printabletocstring(char* inputstr, char** poutputstr)
static inline int
printabletocstring(char* inputstr, char** poutputstr)
{
char highch;
char lowch;
......@@ -137,7 +142,7 @@ int printabletocstring(char* inputstr, char** poutputstr)
cstring = (char*)malloc((strlen(inputstr) + 1) * sizeof(char));
if (cstring == NULL) {
ERROR(errno, "printabletocstring");
PRINT_ERROR(errno, "printabletocstring");
goto error;
}
......@@ -148,21 +153,21 @@ int printabletocstring(char* inputstr, char** poutputstr)
continue;
}
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;
}
if (!isxdigit(highch)) {
ERROR(0, "Unexpected '%c' (non-hex) input.\n", highch);
PRINT_ERROR(0, "Unexpected '%c' (non-hex) input.\n", highch);
goto error;
}
if (!isxdigit(lowch)) {
ERROR(0, "Unexpected '%c' (non-hex) input.\n", lowch);
PRINT_ERROR(0, "Unexpected '%c' (non-hex) input.\n", lowch);
goto error;
}
nextch = (hextoint(highch) << 4) | hextoint(lowch);
nextch = (char)((hextoint(highch) << 4) | hextoint(lowch));
if (nextch == '\0') {
/* 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;
}
*cstring++ = nextch;
......@@ -174,18 +179,19 @@ int printabletocstring(char* inputstr, char** poutputstr)
return EXIT_SUCCESS;
error:
ERROR(0, "Quitting out due to errors.\n");
PRINT_ERROR(0, "Quitting out due to errors.\n");
return EXIT_FAILURE;
}
int verify_library_version()
static inline int
verify_library_version()
{
int major;
int minor;
db_version(&major, &minor, NULL);
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);
return EXIT_FAILURE;
}
......@@ -199,22 +205,52 @@ static void catch_signal(int signal) {
if (last_caught == 0) last_caught = SIGINT;
}
void init_catch_signals(void) {
signal(SIGHUP, catch_signal);
static inline void
init_catch_signals(void) {
signal(SIGINT, catch_signal);
signal(SIGPIPE, 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;
}
void resend_signals(void) {
static inline void
resend_signals(void) {
if (last_caught) {
signal(last_caught, SIG_DFL);
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) */
/* -*- mode: C; c-basic-offset: 3 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#include <toku_portability.h>
#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
......@@ -33,16 +34,16 @@ typedef struct {
dump_globals g;
#include "tokudb_common_funcs.h"
int usage ();
int create_init_env();
int dump_database ();
int open_database ();
int dump_pairs ();
int dump_footer ();
int dump_header ();
int close_database ();
static int usage (void);
static int create_init_env(void);
static int dump_database (void);
static int open_database (void);
static int dump_pairs (void);
static int dump_footer (void);
static int dump_header (void);
static int close_database (void);
int main(int argc, char *argv[]) {
int test_main(int argc, char *argv[]) {
int ch;
int retval;
......@@ -61,7 +62,7 @@ int main(int argc, char *argv[]) {
while ((ch = getopt(argc, argv, "d:f:h:klNP:ps:RrVT")) != EOF) {
switch (ch) {
case ('d'): {
ERRORX("-%c option not supported.\n", ch);
PRINT_ERRORX("-%c option not supported.\n", ch);
goto error;
}
case ('f'): {
......@@ -78,22 +79,22 @@ int main(int argc, char *argv[]) {
break;
}
case ('k'): {
ERRORX("-%c option not supported.\n", ch);
PRINT_ERRORX("-%c option not supported.\n", ch);
goto error;
}
case ('l'): {
//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;
}
case ('N'): {
ERRORX("-%c option not supported.\n", ch);
PRINT_ERRORX("-%c option not supported.\n", ch);
goto error;
}
case ('P'): {
/* Clear password. */
memset(optarg, 0, strlen(optarg));
ERRORX("-%c option not supported.\n", ch);
PRINT_ERRORX("-%c option not supported.\n", ch);
goto error;
}
case ('p'): {
......@@ -105,7 +106,7 @@ int main(int argc, char *argv[]) {
/*g.recover_flags |= DB_SALVAGE | DB_AGGRESSIVE;*/
//TODO: Implement aggressive recovery (requires db->verify())
ERRORX("-%c option not supported.\n", ch);
PRINT_ERRORX("-%c option not supported.\n", ch);
goto error;
}
case ('r'): {
......@@ -113,7 +114,7 @@ int main(int argc, char *argv[]) {
/*g.recover_flags |= DB_SALVAGE;*/
//TODO: Implement recovery (requires db->verify())
ERRORX("-%c option not supported.\n", ch);
PRINT_ERRORX("-%c option not supported.\n", ch);
goto error;
}
case ('s'): {
......@@ -147,10 +148,10 @@ int main(int argc, char *argv[]) {
if (g.subdatabase != NULL && IS_SET_ALL(g.recover_flags, DB_SALVAGE)) {
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;
}
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;
}
......@@ -191,14 +192,14 @@ int dump_database()
/* Create a database handle. */
retval = db_create(&g.db, g.dbenv, 0);
if (retval != 0) {
ERROR(retval, "db_create");
PRINT_ERROR(retval, "db_create");
return EXIT_FAILURE;
}
/*
TODO: If/when supporting encryption
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;
}
*/
......@@ -263,7 +264,7 @@ int create_init_env()
///TODO: UNCOMMENT/IMPLEMENT
retval = dbenv->set_cachesize(dbenv, 0, cache, 1);
if (retval) {
ERROR(retval, "DB_ENV->set_cachesize");
PRINT_ERROR(retval, "DB_ENV->set_cachesize");
goto error;
}
*/
......@@ -276,7 +277,7 @@ int create_init_env()
retval = dbenv->open(dbenv, g.homedir, flags, 0);
if (retval) {
ERROR(retval, "DB_ENV->open");
PRINT_ERROR(retval, "DB_ENV->open");
goto error;
}
success:
......@@ -313,7 +314,7 @@ int dump_header()
}
//TODO: Uncomment when db->get_flags is implemented
if ((retval = db->get_flags(db, &flags)) != 0) {
ERROR(retval, "DB->get_flags");
PRINT_ERROR(retval, "DB->get_flags");
goto error;
}
DUMP_IGNORED_FLAG(DB_CHKSUM, "chksum=1\n");
......@@ -350,22 +351,22 @@ int open_database()
retval = db->open(db, NULL, g.database, g.subdatabase, g.dbtype, open_flags, 0666);
if (retval != 0) {
ERROR(retval, "DB->open: %s", g.database);
PRINT_ERROR(retval, "DB->open: %s", g.database);
goto error;
}
//TODO: Uncomment when DB_UNKNOWN + db->get_type are implemented.
/*
retval = db->get_type(db, &g.opened_dbtype);
if (retval != 0) {
ERROR(retval, "DB->get_type");
PRINT_ERROR(retval, "DB->get_type");
goto error;
}
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;
}
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;
}*/
return EXIT_SUCCESS;
......@@ -374,7 +375,7 @@ int open_database()
return EXIT_FAILURE;
}
int dump_dbt(DBT* dbt)
static int dump_dbt(DBT* dbt)
{
char* str;
u_int32_t index;
......@@ -414,7 +415,7 @@ int dump_pairs()
memset(&data, 0, sizeof(data));
if ((retval = db->cursor(db, (DB_TXN*)NULL, &dbc, 0)) != 0) {
ERROR(retval, "DB->cursor");
PRINT_ERROR(retval, "DB->cursor");
goto error;
}
while ((retval = dbc->c_get(dbc, &key, &data, DB_NEXT)) == 0) {
......@@ -423,7 +424,7 @@ int dump_pairs()
if (dump_dbt(&data) != 0) goto error;
}
if (retval != DB_NOTFOUND) {
ERROR(retval, "DBC->c_get");
PRINT_ERROR(retval, "DBC->c_get");
goto error;
}
......@@ -434,7 +435,7 @@ int dump_pairs()
}
cleanup:
if (dbc && (retval = dbc->c_close(dbc)) != 0) {
ERROR(retval, "DBC->c_close");
PRINT_ERROR(retval, "DBC->c_close");
g.exitcode = EXIT_FAILURE;
}
success:
......@@ -448,7 +449,7 @@ int close_database()
assert(db);
if ((retval = db->close(db, 0)) != 0) {
ERROR(retval, "DB->close");
PRINT_ERROR(retval, "DB->close");
goto error;
}
return EXIT_SUCCESS;
......
/* -*- mode: C; c-basic-offset: 3 -*- */
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#include <toku_portability.h>
#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
......@@ -10,6 +11,9 @@
#include <errno.h>
#include <getopt.h>
#include <db.h>
#if IS_TDB
#include <ydb.h>
#endif
#include "tokudb_common.h"
......@@ -22,9 +26,9 @@ typedef struct {
gen_globals g;
#include "tokudb_common_funcs.h"
int usage(void);
void generate_keys(void);
int get_delimiter(char* str);
static int usage(void);
static void generate_keys(void);
static int get_delimiter(char* str);
......@@ -49,7 +53,7 @@ bool force_unique = true;
bool duplicates = false;
bool dupsort = false;
int main (int argc, char *argv[]) {
static int test_main (int argc, char *argv[]) {
int ch;
/* Set up the globals. */
......@@ -81,14 +85,14 @@ int main (int argc, char *argv[]) {
}
case ('o'): {
if (freopen(optarg, "w", stdout) == NULL) {
ERROR(errno, "%s: reopen\n", optarg);
PRINT_ERROR(errno, "%s: reopen\n", optarg);
goto error;
}
break;
}
case ('r'): {
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;
}
set_seed = true;
......@@ -96,7 +100,7 @@ int main (int argc, char *argv[]) {
}
case ('m'): {
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;
}
set_lengthmin = true;
......@@ -104,7 +108,7 @@ int main (int argc, char *argv[]) {
}
case ('M'): {
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;
}
set_lengthlimit = true;
......@@ -112,7 +116,7 @@ int main (int argc, char *argv[]) {
}
case ('n'): {
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;
}
set_numkeys = true;
......@@ -141,12 +145,12 @@ int main (int argc, char *argv[]) {
case ('d'): {
int temp = get_delimiter(optarg);
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);
goto error;
}
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);
goto error;
}
......@@ -156,12 +160,12 @@ int main (int argc, char *argv[]) {
case ('s'): {
int temp = get_delimiter(optarg);
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);
goto error;
}
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);
goto error;
}
......@@ -185,55 +189,55 @@ int main (int argc, char *argv[]) {
argv += optind;
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;
}
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;
}
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;
}
if (justfooter && header) {
ERRORX("-F implies -h\n");
PRINT_ERRORX("-F implies -h\n");
header = false;
}
if (justheader && footer) {
ERRORX("-H implies -f\n");
PRINT_ERRORX("-H implies -f\n");
footer = false;
}
if (!leadingspace) {
if (footer) {
ERRORX("-p implies -f\n");
PRINT_ERRORX("-p implies -f\n");
footer = false;
}
if (header) {
ERRORX("-p implies -h\n");
PRINT_ERRORX("-p implies -h\n");
header = false;
}
}
if (justfooter || justheader) outputkeys = false;
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;
}
if (outputkeys && !set_seed) {
ERRORX("Using default seed. (-r 1).\n");
PRINT_ERRORX("Using default seed. (-r 1).\n");
seed = 1;
}
if (outputkeys && !set_lengthmin) {
ERRORX("Using default lengthmin. (-m 0).\n");
PRINT_ERRORX("Using default lengthmin. (-m 0).\n");
lengthmin = 0;
}
if (outputkeys && !set_lengthlimit) {
ERRORX("Using default lengthlimit. (-M 1024).\n");
PRINT_ERRORX("Using default lengthlimit. (-M 1024).\n");
lengthlimit = 1024;
}
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;
}
......@@ -260,7 +264,7 @@ int main (int argc, char *argv[]) {
return EXIT_FAILURE;
}
int usage()
static int usage()
{
fprintf(stderr,
"usage: %s [-PpTuVhHfFDS] [-o output] [-r seed] [-m minsize] [-M limitsize]\n"
......@@ -269,7 +273,7 @@ int usage()
return EXIT_FAILURE;
}
u_int8_t randbyte()
static u_int8_t randbyte()
{
static u_int32_t numsavedbits = 0;
static u_int64_t savedbits = 0;
......@@ -286,13 +290,13 @@ u_int8_t randbyte()
}
/* 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);
return random() % limit;
}
void generate_keys()
static void generate_keys()
{
bool usedemptykey = false;
u_int64_t numgenerated = 0;
......@@ -361,7 +365,9 @@ int get_delimiter(char* str)
switch (str[1]) {
case ('a'): return '\a';
case ('b'): return '\b';
#ifndef __ICL
case ('e'): return '\e';
#endif
case ('f'): return '\f';
case ('n'): return '\n';
case ('r'): return '\r';
......
This diff is collapsed.
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