|
|
@ -32,12 +32,18 @@ static int flags; |
|
|
|
|
|
|
|
|
|
|
|
static char *prog; |
|
|
|
static char *prog; |
|
|
|
|
|
|
|
|
|
|
|
static int eof; |
|
|
|
static int Eof; |
|
|
|
|
|
|
|
|
|
|
|
static MDB_envinfo info; |
|
|
|
static MDB_envinfo info; |
|
|
|
|
|
|
|
|
|
|
|
static MDB_val kbuf, dbuf; |
|
|
|
static MDB_val kbuf, dbuf; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
|
|
|
#define Z "I" |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
#define Z "z" |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#define STRLENOF(s) (sizeof(s)-1) |
|
|
|
#define STRLENOF(s) (sizeof(s)-1) |
|
|
|
|
|
|
|
|
|
|
|
typedef struct flagbit { |
|
|
|
typedef struct flagbit { |
|
|
@ -69,7 +75,7 @@ static void readhdr() |
|
|
|
if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) { |
|
|
|
if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) { |
|
|
|
version=atoi((char *)dbuf.mv_data+STRLENOF("VERSION=")); |
|
|
|
version=atoi((char *)dbuf.mv_data+STRLENOF("VERSION=")); |
|
|
|
if (version > 3) { |
|
|
|
if (version > 3) { |
|
|
|
fprintf(stderr, "%s: line %zd: unsupported VERSION %d\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: unsupported VERSION %d\n", |
|
|
|
prog, lineno, version); |
|
|
|
prog, lineno, version); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
@ -79,7 +85,7 @@ static void readhdr() |
|
|
|
if (!strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "print", STRLENOF("print"))) |
|
|
|
if (!strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "print", STRLENOF("print"))) |
|
|
|
mode |= PRINT; |
|
|
|
mode |= PRINT; |
|
|
|
else if (strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "bytevalue", STRLENOF("bytevalue"))) { |
|
|
|
else if (strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "bytevalue", STRLENOF("bytevalue"))) { |
|
|
|
fprintf(stderr, "%s: line %zd: unsupported FORMAT %s\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: unsupported FORMAT %s\n", |
|
|
|
prog, lineno, (char *)dbuf.mv_data+STRLENOF("FORMAT=")); |
|
|
|
prog, lineno, (char *)dbuf.mv_data+STRLENOF("FORMAT=")); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
@ -90,7 +96,7 @@ static void readhdr() |
|
|
|
subname = strdup((char *)dbuf.mv_data+STRLENOF("database=")); |
|
|
|
subname = strdup((char *)dbuf.mv_data+STRLENOF("database=")); |
|
|
|
} else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) { |
|
|
|
} else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) { |
|
|
|
if (strncmp((char *)dbuf.mv_data+STRLENOF("type="), "btree", STRLENOF("btree"))) { |
|
|
|
if (strncmp((char *)dbuf.mv_data+STRLENOF("type="), "btree", STRLENOF("btree"))) { |
|
|
|
fprintf(stderr, "%s: line %zd: unsupported type %s\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: unsupported type %s\n", |
|
|
|
prog, lineno, (char *)dbuf.mv_data+STRLENOF("type=")); |
|
|
|
prog, lineno, (char *)dbuf.mv_data+STRLENOF("type=")); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
@ -100,7 +106,7 @@ static void readhdr() |
|
|
|
if (ptr) *ptr = '\0'; |
|
|
|
if (ptr) *ptr = '\0'; |
|
|
|
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapaddr="), "%p", &info.me_mapaddr); |
|
|
|
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapaddr="), "%p", &info.me_mapaddr); |
|
|
|
if (i != 1) { |
|
|
|
if (i != 1) { |
|
|
|
fprintf(stderr, "%s: line %zd: invalid mapaddr %s\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: invalid mapaddr %s\n", |
|
|
|
prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapaddr=")); |
|
|
|
prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapaddr=")); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
@ -108,9 +114,9 @@ static void readhdr() |
|
|
|
int i; |
|
|
|
int i; |
|
|
|
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size); |
|
|
|
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size); |
|
|
|
if (ptr) *ptr = '\0'; |
|
|
|
if (ptr) *ptr = '\0'; |
|
|
|
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapsize="), "%zu", &info.me_mapsize); |
|
|
|
i = sscanf((char *)dbuf.mv_data+STRLENOF("mapsize="), "%" Z "u", &info.me_mapsize); |
|
|
|
if (i != 1) { |
|
|
|
if (i != 1) { |
|
|
|
fprintf(stderr, "%s: line %zd: invalid mapsize %s\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: invalid mapsize %s\n", |
|
|
|
prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapsize=")); |
|
|
|
prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapsize=")); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
@ -120,7 +126,7 @@ static void readhdr() |
|
|
|
if (ptr) *ptr = '\0'; |
|
|
|
if (ptr) *ptr = '\0'; |
|
|
|
i = sscanf((char *)dbuf.mv_data+STRLENOF("maxreaders="), "%u", &info.me_maxreaders); |
|
|
|
i = sscanf((char *)dbuf.mv_data+STRLENOF("maxreaders="), "%u", &info.me_maxreaders); |
|
|
|
if (i != 1) { |
|
|
|
if (i != 1) { |
|
|
|
fprintf(stderr, "%s: line %zd: invalid maxreaders %s\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: invalid maxreaders %s\n", |
|
|
|
prog, lineno, (char *)dbuf.mv_data+STRLENOF("maxreaders=")); |
|
|
|
prog, lineno, (char *)dbuf.mv_data+STRLENOF("maxreaders=")); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
@ -136,12 +142,12 @@ static void readhdr() |
|
|
|
if (!dbflags[i].bit) { |
|
|
|
if (!dbflags[i].bit) { |
|
|
|
ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size); |
|
|
|
ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size); |
|
|
|
if (!ptr) { |
|
|
|
if (!ptr) { |
|
|
|
fprintf(stderr, "%s: line %zd: unexpected format\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: unexpected format\n", |
|
|
|
prog, lineno); |
|
|
|
prog, lineno); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
*ptr = '\0'; |
|
|
|
*ptr = '\0'; |
|
|
|
fprintf(stderr, "%s: line %zd: unrecognized keyword ignored: %s\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: unrecognized keyword ignored: %s\n", |
|
|
|
prog, lineno, (char *)dbuf.mv_data); |
|
|
|
prog, lineno, (char *)dbuf.mv_data); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -151,7 +157,7 @@ static void readhdr() |
|
|
|
|
|
|
|
|
|
|
|
static void badend() |
|
|
|
static void badend() |
|
|
|
{ |
|
|
|
{ |
|
|
|
fprintf(stderr, "%s: line %zd: unexpected end of input\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: unexpected end of input\n", |
|
|
|
prog, lineno); |
|
|
|
prog, lineno); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -178,14 +184,14 @@ static int readline(MDB_val *out, MDB_val *buf) |
|
|
|
if (!(mode & NOHDR)) { |
|
|
|
if (!(mode & NOHDR)) { |
|
|
|
c = fgetc(stdin); |
|
|
|
c = fgetc(stdin); |
|
|
|
if (c == EOF) { |
|
|
|
if (c == EOF) { |
|
|
|
eof = 1; |
|
|
|
Eof = 1; |
|
|
|
return EOF; |
|
|
|
return EOF; |
|
|
|
} |
|
|
|
} |
|
|
|
if (c != ' ') { |
|
|
|
if (c != ' ') { |
|
|
|
lineno++; |
|
|
|
lineno++; |
|
|
|
if (fgets(buf->mv_data, buf->mv_size, stdin) == NULL) { |
|
|
|
if (fgets(buf->mv_data, buf->mv_size, stdin) == NULL) { |
|
|
|
badend: |
|
|
|
badend: |
|
|
|
eof = 1; |
|
|
|
Eof = 1; |
|
|
|
badend(); |
|
|
|
badend(); |
|
|
|
return EOF; |
|
|
|
return EOF; |
|
|
|
} |
|
|
|
} |
|
|
@ -195,7 +201,7 @@ badend: |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (fgets(buf->mv_data, buf->mv_size, stdin) == NULL) { |
|
|
|
if (fgets(buf->mv_data, buf->mv_size, stdin) == NULL) { |
|
|
|
eof = 1; |
|
|
|
Eof = 1; |
|
|
|
return EOF; |
|
|
|
return EOF; |
|
|
|
} |
|
|
|
} |
|
|
|
lineno++; |
|
|
|
lineno++; |
|
|
@ -207,15 +213,15 @@ badend: |
|
|
|
while (c1[len-1] != '\n') { |
|
|
|
while (c1[len-1] != '\n') { |
|
|
|
buf->mv_data = realloc(buf->mv_data, buf->mv_size*2); |
|
|
|
buf->mv_data = realloc(buf->mv_data, buf->mv_size*2); |
|
|
|
if (!buf->mv_data) { |
|
|
|
if (!buf->mv_data) { |
|
|
|
eof = 1; |
|
|
|
Eof = 1; |
|
|
|
fprintf(stderr, "%s: line %zd: out of memory, line too long\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: out of memory, line too long\n", |
|
|
|
prog, lineno); |
|
|
|
prog, lineno); |
|
|
|
return EOF; |
|
|
|
return EOF; |
|
|
|
} |
|
|
|
} |
|
|
|
c1 = buf->mv_data; |
|
|
|
c1 = buf->mv_data; |
|
|
|
c1 += buf->mv_size; |
|
|
|
c1 += buf->mv_size; |
|
|
|
if (fgets((char *)c1, buf->mv_size, stdin) == NULL) { |
|
|
|
if (fgets((char *)c1, buf->mv_size, stdin) == NULL) { |
|
|
|
eof = 1; |
|
|
|
Eof = 1; |
|
|
|
badend(); |
|
|
|
badend(); |
|
|
|
return EOF; |
|
|
|
return EOF; |
|
|
|
} |
|
|
|
} |
|
|
@ -234,7 +240,7 @@ badend: |
|
|
|
c1++; c2 += 2; |
|
|
|
c1++; c2 += 2; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (c2+3 >= end || !isxdigit(c2[1]) || !isxdigit(c2[2])) { |
|
|
|
if (c2+3 >= end || !isxdigit(c2[1]) || !isxdigit(c2[2])) { |
|
|
|
eof = 1; |
|
|
|
Eof = 1; |
|
|
|
badend(); |
|
|
|
badend(); |
|
|
|
return EOF; |
|
|
|
return EOF; |
|
|
|
} |
|
|
|
} |
|
|
@ -248,13 +254,13 @@ badend: |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
/* odd length not allowed */ |
|
|
|
/* odd length not allowed */ |
|
|
|
if (len & 1) { |
|
|
|
if (len & 1) { |
|
|
|
eof = 1; |
|
|
|
Eof = 1; |
|
|
|
badend(); |
|
|
|
badend(); |
|
|
|
return EOF; |
|
|
|
return EOF; |
|
|
|
} |
|
|
|
} |
|
|
|
while (c2 < end) { |
|
|
|
while (c2 < end) { |
|
|
|
if (!isxdigit(*c2) || !isxdigit(c2[1])) { |
|
|
|
if (!isxdigit(*c2) || !isxdigit(c2[1])) { |
|
|
|
eof = 1; |
|
|
|
Eof = 1; |
|
|
|
badend(); |
|
|
|
badend(); |
|
|
|
return EOF; |
|
|
|
return EOF; |
|
|
|
} |
|
|
|
} |
|
|
@ -360,7 +366,7 @@ int main(int argc, char *argv[]) |
|
|
|
kbuf.mv_size = mdb_env_get_maxkeysize(env) * 2 + 2; |
|
|
|
kbuf.mv_size = mdb_env_get_maxkeysize(env) * 2 + 2; |
|
|
|
kbuf.mv_data = malloc(kbuf.mv_size); |
|
|
|
kbuf.mv_data = malloc(kbuf.mv_size); |
|
|
|
|
|
|
|
|
|
|
|
while(!eof) { |
|
|
|
while(!Eof) { |
|
|
|
MDB_val key, data; |
|
|
|
MDB_val key, data; |
|
|
|
int batch = 0; |
|
|
|
int batch = 0; |
|
|
|
flags = 0; |
|
|
|
flags = 0; |
|
|
@ -408,7 +414,7 @@ int main(int argc, char *argv[]) |
|
|
|
if (batch == 100) { |
|
|
|
if (batch == 100) { |
|
|
|
rc = mdb_txn_commit(txn); |
|
|
|
rc = mdb_txn_commit(txn); |
|
|
|
if (rc) { |
|
|
|
if (rc) { |
|
|
|
fprintf(stderr, "%s: line %zd: txn_commit: %s\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: txn_commit: %s\n", |
|
|
|
prog, lineno, mdb_strerror(rc)); |
|
|
|
prog, lineno, mdb_strerror(rc)); |
|
|
|
goto env_close; |
|
|
|
goto env_close; |
|
|
|
} |
|
|
|
} |
|
|
@ -428,7 +434,7 @@ int main(int argc, char *argv[]) |
|
|
|
rc = mdb_txn_commit(txn); |
|
|
|
rc = mdb_txn_commit(txn); |
|
|
|
txn = NULL; |
|
|
|
txn = NULL; |
|
|
|
if (rc) { |
|
|
|
if (rc) { |
|
|
|
fprintf(stderr, "%s: line %zd: txn_commit: %s\n", |
|
|
|
fprintf(stderr, "%s: line %" Z "d: txn_commit: %s\n", |
|
|
|
prog, lineno, mdb_strerror(rc)); |
|
|
|
prog, lineno, mdb_strerror(rc)); |
|
|
|
goto env_close; |
|
|
|
goto env_close; |
|
|
|
} |
|
|
|
} |
|
|
|