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 @@ ...@@ -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';
......
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