Commit dc4f6e5f authored by Yoni Fogel's avatar Yoni Fogel

Modifications to be compatible with tokudb

git-svn-id: file:///svn/tokudb@439 c7de825b-a66e-492c-adef-691d508d4ae1
parent dfba18ce
...@@ -18,10 +18,10 @@ typedef uint8_t bool; ...@@ -18,10 +18,10 @@ typedef uint8_t bool;
#define IS_POWER_OF_2(num) ((num) > 0 && ((num) & ((num) - 1)) == 0) #define IS_POWER_OF_2(num) ((num) > 0 && ((num) & ((num) - 1)) == 0)
int strtoint32 (DB* db, char* progname, char* str, int32_t* num, int32_t min, int32_t max, int base); int strtoint32 (DB_ENV* dbenv, char* progname, char* str, int32_t* num, int32_t min, int32_t max, int base);
int strtouint32 (DB* db, char* progname, char* str, uint32_t* num, uint32_t min, uint32_t max, int base); int strtouint32 (DB_ENV* dbenv, char* progname, char* str, uint32_t* num, uint32_t min, uint32_t max, int base);
int strtoint64 (DB* db, char* progname, char* str, int64_t* num, int64_t min, int64_t max, int base); int strtoint64 (DB_ENV* dbenv, char* progname, char* str, int64_t* num, int64_t min, int64_t max, int base);
int strtouint64 (DB* db, char* progname, char* str, uint64_t* num, uint64_t min, uint64_t max, int base); int strtouint64 (DB_ENV* dbenv, char* progname, char* str, uint64_t* num, uint64_t min, uint64_t max, int base);
/* /*
* Convert a string to an integer of type "type". * Convert a string to an integer of type "type".
...@@ -36,7 +36,7 @@ int strtouint64 (DB* db, char* progname, char* str, uint64_t* num, uint64_t mi ...@@ -36,7 +36,7 @@ int strtouint64 (DB* db, char* progname, char* str, uint64_t* num, uint64_t mi
* *
*/ */
#define DEF_STR_TO(name, type, bigtype, strtofunc, frmt) \ #define DEF_STR_TO(name, type, bigtype, strtofunc, frmt) \
int name(DB* db, char* progname, char* str, type* num, type min, type max, int base) \ int name(DB_ENV* dbenv, char* progname, char* str, type* num, type min, type max, int base) \
{ \ { \
char* test; \ char* test; \
bigtype value; \ bigtype value; \
...@@ -44,31 +44,31 @@ int name(DB* db, char* progname, char* str, type* num, type min, type max, int b ...@@ -44,31 +44,31 @@ int name(DB* db, char* progname, char* str, type* num, type min, type max, int b
assert(str); \ assert(str); \
assert(num); \ assert(num); \
assert(min <= max); \ assert(min <= max); \
assert(db || progname); \ assert(dbenv || progname); \
assert(base == 0 || (base >= 2 && base <= 36)); \ assert(base == 0 || (base >= 2 && base <= 36)); \
\ \
errno = 0; \ errno = 0; \
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) { \
if (db == NULL) fprintf(stderr, "%s: %s: Invalid numeric argument\n", progname, str); \ if (dbenv == NULL) fprintf(stderr, "%s: %s: Invalid numeric argument\n", progname, str); \
else db->errx(db, "%s: Invalid numeric argument", str); \ else dbenv->err(dbenv, 0, "%s: Invalid numeric argument", str); \
errno = EINVAL; \ errno = EINVAL; \
goto error; \ goto error; \
} \ } \
if (errno != 0) { \ if (errno != 0) { \
if (db == NULL) fprintf(stderr, "%s: %s: %s\n", progname, str, strerror(errno)); \ if (dbenv == NULL) fprintf(stderr, "%s: %s: %s\n", progname, str, strerror(errno)); \
else db->err(db, errno, "%s", str); \ else dbenv->err(dbenv, errno, "%s", str); \
goto error; \ goto error; \
} \ } \
if (value < min) { \ if (value < min) { \
if (db == NULL) fprintf(stderr, "%s: %s: Less than minimum value (%" frmt ")\n", progname, str, min); \ if (dbenv == NULL) fprintf(stderr, "%s: %s: Less than minimum value (%" frmt ")\n", progname, str, min); \
else db->errx(db, "%s: Less than minimum value (%" frmt ")", str, min); \ else dbenv->err(dbenv, 0, "%s: Less than minimum value (%" frmt ")", str, min); \
goto error; \ goto error; \
} \ } \
if (value > max) { \ if (value > max) { \
if (db == NULL) fprintf(stderr, "%s: %s: Greater than maximum value (%" frmt ")\n", progname, str, max); \ if (dbenv == NULL) fprintf(stderr, "%s: %s: Greater than maximum value (%" frmt ")\n", progname, str, max); \
else db->errx(db, "%s: Greater than maximum value (%" frmt ")", str, max); \ else dbenv->err(dbenv, 0, "%s: Greater than maximum value (%" frmt ")", str, max); \
goto error; \ goto error; \
} \ } \
*num = value; \ *num = value; \
......
...@@ -189,7 +189,6 @@ int main(int argc, char *argv[]) { ...@@ -189,7 +189,6 @@ int main(int argc, char *argv[]) {
int load_database() int load_database()
{ {
DB_ENV* dbenv = g.dbenv; DB_ENV* dbenv = g.dbenv;
DB* db;
int retval; int retval;
/* Create a database handle. */ /* Create a database handle. */
...@@ -198,7 +197,6 @@ int load_database() ...@@ -198,7 +197,6 @@ int load_database()
dbenv->err(dbenv, retval, "db_create"); dbenv->err(dbenv, retval, "db_create");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
db = g.db;
if (g.header && read_header() != 0) goto error; if (g.header && read_header() != 0) goto error;
if (g.eof) goto cleanup; if (g.eof) goto cleanup;
...@@ -207,13 +205,13 @@ int load_database() ...@@ -207,13 +205,13 @@ int load_database()
//TODO: Only quit out if DB does NOT EXIST. //TODO: Only quit out if DB does NOT EXIST.
if (g.dbtype == DB_UNKNOWN) { if (g.dbtype == DB_UNKNOWN) {
dbenv->errx(dbenv, "no database type specified"); dbenv->err(dbenv, 0, "no database type specified");
goto error; goto error;
} }
/* /*
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))) {
db->err(db, ret, "DB->set_flags: DB_ENCRYPT"); dbenv->err(dbenv, ret, "DB->set_flags: DB_ENCRYPT");
goto error; goto error;
} }
*/ */
...@@ -340,21 +338,21 @@ int printabletocstring(char* inputstr, char** poutputstr) ...@@ -340,21 +338,21 @@ int printabletocstring(char* inputstr, char** poutputstr)
continue; continue;
} }
if (highch == '\0' || (lowch = *++inputstr) == '\0') { if (highch == '\0' || (lowch = *++inputstr) == '\0') {
dbenv->errx(dbenv, "unexpected end of input data or key/data pair"); dbenv->err(dbenv, 0, "unexpected end of input data or key/data pair");
goto error; goto error;
} }
if (!isxdigit(highch)) { if (!isxdigit(highch)) {
dbenv->errx(dbenv, "Unexpected '%c' (non-hex) input.\n", highch); dbenv->err(dbenv, 0, "Unexpected '%c' (non-hex) input.\n", highch);
goto error; goto error;
} }
if (!isxdigit(lowch)) { if (!isxdigit(lowch)) {
dbenv->errx(dbenv, "Unexpected '%c' (non-hex) input.\n", lowch); dbenv->err(dbenv, 0, "Unexpected '%c' (non-hex) input.\n", lowch);
goto error; goto error;
} }
nextch = (hextoint(highch) << 4) | hextoint(lowch); nextch = (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. */
dbenv->errx(dbenv, "Unexpected '\\00' in input.\n"); dbenv->err(dbenv, 0, "Unexpected '\\00' in input.\n");
goto error; goto error;
} }
*cstring++ = nextch; *cstring++ = nextch;
...@@ -366,14 +364,14 @@ int printabletocstring(char* inputstr, char** poutputstr) ...@@ -366,14 +364,14 @@ int printabletocstring(char* inputstr, char** poutputstr)
return EXIT_SUCCESS; return EXIT_SUCCESS;
error: error:
dbenv->errx(dbenv, "Quitting out due to errors.\n"); dbenv->err(dbenv, 0, "Quitting out due to errors.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
///TODO: IMPLEMENT/Replace original line. ///TODO: IMPLEMENT/Replace original line.
#define PARSE_NUMBER(match, dbfunction) \ #define PARSE_NUMBER(match, dbfunction) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strtoint32(db, NULL, value, &num, 1, INT32_MAX, 10)) goto error; \ if (strtoint32(dbenv, NULL, value, &num, 1, INT32_MAX, 10)) goto error; \
/*if ((retval = dbfunction(db, num)) != 0) goto printerror;*/ \ /*if ((retval = dbfunction(db, num)) != 0) goto printerror;*/ \
continue; \ continue; \
} }
...@@ -381,21 +379,21 @@ if (!strcmp(field, match)) { \ ...@@ -381,21 +379,21 @@ if (!strcmp(field, match)) { \
///TODO: IMPLEMENT/Replace original line. ///TODO: IMPLEMENT/Replace original line.
#define PARSE_UNSUPPORTEDNUMBER(match, dbfunction) \ #define PARSE_UNSUPPORTEDNUMBER(match, dbfunction) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strtoint32(db, NULL, value, &num, 1, INT32_MAX, 10)) goto error; \ if (strtoint32(dbenv, NULL, value, &num, 1, INT32_MAX, 10)) goto error; \
db->errx(db, "%s option not supported.\n", field); \ dbenv->err(dbenv, 0, "%s option not supported.\n", field); \
goto error; \ goto error; \
} }
#define PARSE_FLAG(match, flag) \ #define PARSE_FLAG(match, flag) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strtoint32(db, NULL, value, &num, 0, 1, 10)) { \ if (strtoint32(dbenv, NULL, value, &num, 0, 1, 10)) { \
db->errx(db, \ dbenv->err(dbenv, 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; \
} \ } \
if ((retval = db->set_flags(db, flag)) != 0) { \ if ((retval = db->set_flags(db, flag)) != 0) { \
db->err(db, retval, \ dbenv->err(dbenv, retval, \
"set_flags: %s", \ "set_flags: %s", \
field); \ field); \
goto error; \ goto error; \
...@@ -405,21 +403,21 @@ if (!strcmp(field, match)) { \ ...@@ -405,21 +403,21 @@ if (!strcmp(field, match)) { \
#define PARSE_UNSUPPORTEDFLAG(match, flag) \ #define PARSE_UNSUPPORTEDFLAG(match, flag) \
if (!strcmp(field, match)) { \ if (!strcmp(field, match)) { \
if (strtoint32(db, NULL, value, &num, 0, 1, 10)) { \ if (strtoint32(dbenv, NULL, value, &num, 0, 1, 10)) { \
db->errx(db, \ dbenv->err(dbenv, 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; \
} \ } \
db->errx(db, "%s option not supported.\n", field); \ dbenv->err(dbenv, 0, "%s option not supported.\n", field); \
goto error; \ goto error; \
} }
#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) { \
db->errx(db, \ dbenv->err(dbenv, 0, \
"%s=%s: Expected 1-byte value", \ "%s=%s: Expected 1-byte value", \
field, value); \ field, value); \
goto error; \ goto error; \
} \ } \
...@@ -478,9 +476,9 @@ int read_header() ...@@ -478,9 +476,9 @@ int read_header()
if (!strcmp(field, "HEADER")) break; if (!strcmp(field, "HEADER")) break;
if (!strcmp(field, "VERSION")) { if (!strcmp(field, "VERSION")) {
if (strtoint32(db, NULL, value, &g.version, 1, INT32_MAX, 10)) goto error; if (strtoint32(dbenv, NULL, value, &g.version, 1, INT32_MAX, 10)) goto error;
if (g.version != 3) { if (g.version != 3) {
db->errx(db, "line %lu: VERSION %d is unsupported", g.linenumber, g.version); dbenv->err(dbenv, 0, "line %lu: VERSION %d is unsupported", g.linenumber, g.version);
goto error; goto error;
} }
continue; continue;
...@@ -502,10 +500,10 @@ int read_header() ...@@ -502,10 +500,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")) {
db->errx(db, "db type %s not supported.\n", value); dbenv->err(dbenv, 0, "db type %s not supported.\n", value);
goto error; goto error;
} }
db->errx(db, "line %lu: unknown type %s", g.linenumber, value); dbenv->err(dbenv, 0, "line %lu: unknown type %s", g.linenumber, value);
goto error; goto error;
} }
if (!strcmp(field, "database") || !strcmp(field, "subdatabase")) { if (!strcmp(field, "database") || !strcmp(field, "subdatabase")) {
...@@ -515,22 +513,22 @@ int read_header() ...@@ -515,22 +513,22 @@ int read_header()
g.subdatabase = NULL; g.subdatabase = NULL;
} }
if ((retval = printabletocstring(value, &g.subdatabase))) { if ((retval = printabletocstring(value, &g.subdatabase))) {
db->err(db, retval, "error reading db name"); dbenv->err(dbenv, retval, "error reading db name");
goto error; goto error;
} }
continue; continue;
} }
if (!strcmp(field, "keys")) { if (!strcmp(field, "keys")) {
int32_t temp; int32_t temp;
if (strtoint32(db, NULL, value, &temp, 0, 1, 10)) { if (strtoint32(dbenv, NULL, value, &temp, 0, 1, 10)) {
db->errx(db, dbenv->err(dbenv, 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 = temp;
if (!g.keys) { if (!g.keys) {
db->errx(db, "keys=0 not supported", field); dbenv->err(dbenv, 0, "keys=0 not supported", field);
goto error; goto error;
} }
continue; continue;
...@@ -549,7 +547,7 @@ int read_header() ...@@ -549,7 +547,7 @@ int read_header()
PARSE_FLAG( "recnum", DB_RECNUM); PARSE_FLAG( "recnum", DB_RECNUM);
PARSE_UNSUPPORTEDFLAG( "renumber", DB_RENUMBER); PARSE_UNSUPPORTEDFLAG( "renumber", DB_RENUMBER);
db->errx(db, "unknown input-file header configuration keyword \"%s\"", field); dbenv->err(dbenv, 0, "unknown input-file header configuration keyword \"%s\"", field);
goto error; goto error;
} }
success: success:
...@@ -557,11 +555,11 @@ int read_header() ...@@ -557,11 +555,11 @@ int read_header()
if (false) { if (false) {
printerror: printerror:
db->err(db, retval, "%s=%s", field, value); dbenv->err(dbenv, retval, "%s=%s", field, value);
} }
if (false) { if (false) {
formaterror: formaterror:
db->errx(db, "line %lu: unexpected format", g.linenumber); dbenv->err(dbenv, 0, "line %lu: unexpected format", g.linenumber);
} }
error: error:
return EXIT_FAILURE; return EXIT_FAILURE;
...@@ -591,14 +589,14 @@ int apply_commandline_options() ...@@ -591,14 +589,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) {
db->errx(db, "command-line configuration uses name=value format"); dbenv->err(dbenv, 0, "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') {
db->errx(db, "command-line configuration uses name=value format"); dbenv->err(dbenv, 0, "command-line configuration uses name=value format");
goto error; goto error;
} }
...@@ -608,22 +606,22 @@ int apply_commandline_options() ...@@ -608,22 +606,22 @@ int apply_commandline_options()
g.subdatabase = NULL; g.subdatabase = NULL;
} }
if ((retval = printabletocstring(value, &g.subdatabase))) { if ((retval = printabletocstring(value, &g.subdatabase))) {
db->err(db, retval, "error reading db name"); dbenv->err(dbenv, retval, "error reading db name");
goto error; goto error;
} }
continue; continue;
} }
if (!strcmp(field, "keys")) { if (!strcmp(field, "keys")) {
int32_t temp; int32_t temp;
if (strtoint32(db, NULL, value, &temp, 0, 1, 10)) { if (strtoint32(dbenv, NULL, value, &temp, 0, 1, 10)) {
db->errx(db, dbenv->err(dbenv, 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 = temp;
if (!g.keys) { if (!g.keys) {
db->errx(db, "keys=0 not supported", field); dbenv->err(dbenv, 0, "keys=0 not supported", field);
goto error; goto error;
} }
continue; continue;
...@@ -645,7 +643,7 @@ int apply_commandline_options() ...@@ -645,7 +643,7 @@ int apply_commandline_options()
PARSE_UNSUPPORTEDFLAG( "renumber", DB_RENUMBER); PARSE_UNSUPPORTEDFLAG( "renumber", DB_RENUMBER);
*/ */
db->errx(db, "unknown input-file header configuration keyword \"%s\"", field); dbenv->err(dbenv, 0, "unknown input-file header configuration keyword \"%s\"", field);
goto error; goto error;
} }
if (value) { if (value) {
...@@ -657,7 +655,7 @@ int apply_commandline_options() ...@@ -657,7 +655,7 @@ int apply_commandline_options()
if (false) { if (false) {
printerror: printerror:
db->err(db, retval, "%s=%s", field, value); dbenv->err(dbenv, retval, "%s=%s", field, value);
} }
error: error:
return EXIT_FAILURE; return EXIT_FAILURE;
...@@ -675,7 +673,7 @@ int open_database() ...@@ -675,7 +673,7 @@ int open_database()
//TODO: First see if it exists.. THEN create it? //TODO: First see if it exists.. THEN create it?
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) {
db->err(db, retval, "DB->open: %s", g.database); dbenv->err(dbenv, retval, "DB->open: %s", g.database);
goto error; goto error;
} }
//TODO: Ensure we have enough cache to store some min number of btree pages. //TODO: Ensure we have enough cache to store some min number of btree pages.
...@@ -687,7 +685,7 @@ int open_database() ...@@ -687,7 +685,7 @@ int open_database()
DBTYPE existingtype; DBTYPE existingtype;
retval = db->get_type(db, &existingtype); retval = db->get_type(db, &existingtype);
if (retval != 0) { if (retval != 0) {
db->err(db, retval, "DB->get_type: %s", g.database); dbenv->err(dbenv, retval, "DB->get_type: %s", g.database);
goto error; goto error;
} }
assert(g.dbtype == DB_BTREE); assert(g.dbtype == DB_BTREE);
...@@ -718,7 +716,7 @@ int hextoint(int ch) ...@@ -718,7 +716,7 @@ int hextoint(int ch)
int doublechararray(char** pmem, uint64_t* size) int doublechararray(char** pmem, uint64_t* size)
{ {
DB* db = g.db; DB_ENV* dbenv = g.dbenv;
assert(pmem); assert(pmem);
assert(size); assert(size);
...@@ -727,11 +725,11 @@ int doublechararray(char** pmem, uint64_t* size) ...@@ -727,11 +725,11 @@ int doublechararray(char** pmem, uint64_t* size)
*size <<= 1; *size <<= 1;
if (*size == 0) { if (*size == 0) {
/* Overflowed uint64_t. */ /* Overflowed uint64_t. */
db->errx(db, "Line %llu: Line too long.\n", g.linenumber); dbenv->err(dbenv, 0, "Line %llu: Line too long.\n", g.linenumber);
goto error; goto error;
} }
if ((*pmem = (char*)realloc(*pmem, *size)) == NULL) { if ((*pmem = (char*)realloc(*pmem, *size)) == NULL) {
db->err(db, errno, ""); dbenv->err(dbenv, errno, "");
goto error; goto error;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -742,6 +740,7 @@ int doublechararray(char** pmem, uint64_t* size) ...@@ -742,6 +740,7 @@ int doublechararray(char** pmem, uint64_t* size)
int get_dbt(DBT* pdbt) int get_dbt(DBT* pdbt)
{ {
DB_ENV* dbenv = g.dbenv;
/* Need to store a key and value. */ /* Need to store a key and value. */
static uint64_t datasize[2] = {1 << 10, 1 << 10}; static uint64_t datasize[2] = {1 << 10, 1 << 10};
static int which = 0; static int which = 0;
...@@ -755,7 +754,7 @@ int get_dbt(DBT* pdbt) ...@@ -755,7 +754,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) {
db->err(db, errno, ""); dbenv->err(dbenv, errno, "");
goto error; goto error;
} }
...@@ -781,22 +780,22 @@ int get_dbt(DBT* pdbt) ...@@ -781,22 +780,22 @@ int get_dbt(DBT* pdbt)
} }
else if (highch == EOF) { else if (highch == EOF) {
g.eof = true; g.eof = true;
db->errx(db, "Line %llu: Unexpected end of file (2 hex digits per byte).\n", g.linenumber); dbenv->err(dbenv, 0, "Line %llu: Unexpected end of file (2 hex digits per byte).\n", g.linenumber);
goto error; goto error;
} }
else if (!isxdigit(highch)) { else if (!isxdigit(highch)) {
db->errx(db, "Line %llu: Unexpected '%c' (non-hex) input.\n", g.linenumber, highch); dbenv->err(dbenv, 0, "Line %llu: 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;
db->errx(db, "Line %llu: Unexpected end of file (2 hex digits per byte).\n", g.linenumber); dbenv->err(dbenv, 0, "Line %llu: Unexpected end of file (2 hex digits per byte).\n", g.linenumber);
goto error; goto error;
} }
else if (!isxdigit(lowch)) { else if (!isxdigit(lowch)) {
db->errx(db, "Line %llu: Unexpected '%c' (non-hex) input.\n", g.linenumber, lowch); dbenv->err(dbenv, 0, "Line %llu: Unexpected '%c' (non-hex) input.\n", g.linenumber, lowch);
goto error; goto error;
} }
...@@ -808,7 +807,7 @@ int get_dbt(DBT* pdbt) ...@@ -808,7 +807,7 @@ int get_dbt(DBT* pdbt)
nextch = firstch; nextch = firstch;
break; break;
} }
db->errx(db, "Line %llu: Nonprintable character found.", g.linenumber); dbenv->err(dbenv, 0, "Line %llu: Nonprintable character found.", g.linenumber);
goto error; goto error;
} }
} }
...@@ -835,15 +834,15 @@ int get_dbt(DBT* pdbt) ...@@ -835,15 +834,15 @@ int get_dbt(DBT* pdbt)
lowch = getchar(); lowch = getchar();
if (lowch == EOF) { if (lowch == EOF) {
g.eof = true; g.eof = true;
db->errx(db, "Line %llu: Unexpected end of file (2 hex digits per byte).\n", g.linenumber); dbenv->err(dbenv, 0, "Line %llu: Unexpected end of file (2 hex digits per byte).\n", g.linenumber);
goto error; goto error;
} }
if (!isxdigit(highch)) { if (!isxdigit(highch)) {
db->errx(db, "Line %llu: Unexpected '%c' (non-hex) input.\n", g.linenumber, highch); dbenv->err(dbenv, 0, "Line %llu: Unexpected '%c' (non-hex) input.\n", g.linenumber, highch);
goto error; goto error;
} }
if (!isxdigit(lowch)) { if (!isxdigit(lowch)) {
db->errx(db, "Line %llu: Unexpected '%c' (non-hex) input.\n", g.linenumber, lowch); dbenv->err(dbenv, 0, "Line %llu: Unexpected '%c' (non-hex) input.\n", g.linenumber, lowch);
goto error; goto error;
} }
if (index == datasize[which]) { if (index == datasize[which]) {
...@@ -867,12 +866,13 @@ int get_dbt(DBT* pdbt) ...@@ -867,12 +866,13 @@ int get_dbt(DBT* pdbt)
int insert_pair(DBT* key, DBT* data) int insert_pair(DBT* key, DBT* data)
{ {
DB_ENV* dbenv = g.dbenv;
DB* db = g.db; DB* db = g.db;
int retval = db->put(db, NULL, key, data, g.overwritekeys ? 0 : DB_NOOVERWRITE); int retval = db->put(db, NULL, key, data, g.overwritekeys ? 0 : 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.
db->err(db, retval, "DB->put"); dbenv->err(dbenv, retval, "DB->put");
goto error; goto error;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -904,7 +904,7 @@ int read_keys() ...@@ -904,7 +904,7 @@ int read_keys()
g.linenumber++; g.linenumber++;
if (get_dbt(&key) != 0) goto error; if (get_dbt(&key) != 0) goto error;
if (g.eof) { if (g.eof) {
db->errx(db, "Line %llu: Key exists but value missing.", g.linenumber); dbenv->err(dbenv, 0, "Line %llu: Key exists but value missing.", g.linenumber);
goto error; goto error;
} }
g.linenumber++; g.linenumber++;
...@@ -936,13 +936,13 @@ int read_keys() ...@@ -936,13 +936,13 @@ int read_keys()
} }
default: { default: {
unexpectedinput: unexpectedinput:
db->errx(db, "Line %llu: Unexpected input while reading key.\n", g.linenumber); dbenv->err(dbenv, 0, "Line %llu: Unexpected input while reading key.\n", g.linenumber);
goto error; goto error;
} }
} }
if (g.eof) { if (g.eof) {
db->errx(db, "Line %llu: Key exists but value missing.", g.linenumber); dbenv->err(dbenv, 0, "Line %llu: Key exists but value missing.", g.linenumber);
goto error; goto error;
} }
g.linenumber++; g.linenumber++;
...@@ -950,7 +950,7 @@ int read_keys() ...@@ -950,7 +950,7 @@ int read_keys()
switch (spacech) { switch (spacech) {
case (EOF): { case (EOF): {
g.eof = true; g.eof = true;
db->errx(db, "Line %llu: Unexpected end of file while reading value.\n", g.linenumber); dbenv->err(dbenv, 0, "Line %llu: Unexpected end of file while reading value.\n", g.linenumber);
goto error; goto error;
} }
case (' '): { case (' '): {
...@@ -959,7 +959,7 @@ int read_keys() ...@@ -959,7 +959,7 @@ int read_keys()
break; break;
} }
default: { default: {
db->errx(db, "Line %llu: Unexpected input while reading value.\n", g.linenumber); dbenv->err(dbenv, 0, "Line %llu: Unexpected input while reading value.\n", g.linenumber);
goto error; goto error;
} }
} }
......
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