+ extract_token(record_type, line, 0, '|', sizeof record_type);
+
+ if (!strcasecmp(record_type, "msgtext")) current_cdb = CDB_MSGMAIN;
+ else if (!strcasecmp(record_type, "msgmeta")) current_cdb = CDB_MSGMAIN;
+ else if (!strcasecmp(record_type, "user")) current_cdb = CDB_USERS;
+ else if (!strcasecmp(record_type, "room")) current_cdb = CDB_ROOMS;
+ else if (!strcasecmp(record_type, "floor")) current_cdb = CDB_FLOORTAB;
+ else if (!strcasecmp(record_type, "msglist")) current_cdb = CDB_MSGLISTS;
+ else if (!strcasecmp(record_type, "visit")) current_cdb = CDB_VISIT;
+ else if (!strcasecmp(record_type, "dir")) current_cdb = CDB_DIRECTORY;
+ else if (!strcasecmp(record_type, "use")) current_cdb = CDB_USETABLE;
+ else if (!strcasecmp(record_type, "bigmsg")) current_cdb = CDB_BIGMSGS;
+ else if (!strcasecmp(record_type, "euidindex")) current_cdb = CDB_EUIDINDEX;
+ else if (!strcasecmp(record_type, "usersbynumber")) current_cdb = CDB_USERSBYNUMBER;
+ else if (!strcasecmp(record_type, "config")) current_cdb = CDB_CONFIG;
+ else current_cdb = -1 ;
+
+
+ if (current_cdb != previous_cdb) {
+
+ if (previous_cdb >= 0) {
+ fprintf(stderr, "Close %d\n", previous_cdb);
+ ret = dst_dbp->close(dst_dbp, 0);
+ if (ret) {
+ fprintf(stderr, "db: db_close: %s\n", db_strerror(ret));
+ }
+ }
+
+ if (current_cdb >= 0) {
+ fprintf(stderr, " Open %d\n", current_cdb);
+ snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", current_cdb);
+
+ // create a database handle for the destination table
+ ret = db_create(&dst_dbp, dst_dbenv, 0);
+ if (ret) {
+ fprintf(stderr, "db: db_create: %s\n", db_strerror(ret));
+ fprintf(stderr, "db: exit code %d\n", ret);
+ exit(CTDLEXIT_DB);
+ }
+
+ // open the file containing the destination table
+ ret = dst_dbp->open(dst_dbp, NULL, dbfilename, NULL, DB_BTREE, (DB_CREATE | DB_TRUNCATE), 0600);
+ if (ret) {
+ fprintf(stderr, "db: db_open: %s\n", db_strerror(ret));
+ fprintf(stderr, "db: exit code %d\n", ret);
+ exit(CTDLEXIT_DB);
+ }
+ }