+
+ // Call the convert function registered to this table
+ convert_functions[which_cdb](which_cdb, &in_key, (compressed ? &uncomp_data : &in_data), &out_key, &out_data);
+
+ // The logic here is that if the source data was compressed, we compress the output too
+ if (compressed) {
+ struct CtdlCompressHeader zheader;
+ memset(&zheader, 0, sizeof(struct CtdlCompressHeader));
+ zheader.magic = COMPRESS_MAGIC;
+ zheader.uncompressed_len = out_data.size;
+ recomp_data.data = realloc(recomp_data.data, ((out_data.size * 101) / 100) + 100 + sizeof(struct CtdlCompressHeader));
+
+ if (compress2((Bytef *)(recomp_data.data + sizeof(struct CtdlCompressHeader)), &destLen, (Bytef *)out_data.data, (uLongf) out_data.size, 1) != Z_OK) {
+ printf("db: compress() error\n");
+ exit(CTDLEXIT_DB);
+ }
+ recomp_data.size = destLen;
+ }
+
+ // write the converted record to the target database
+ if (out_key.size > 0) {
+
+ // If we compressed the output, write recomp_data instead of out_data
+ if (compressed) {
+ // printf("DB: %02x , out_keylen: %-3d , out_datalen: %-10d , dataptr: %012lx \033[31m(compressed)\033[0m\n", which_cdb, (int)out_key.size, (int)recomp_data.size, (long unsigned int)recomp_data.data);
+ ret = dst_dbp->put(dst_dbp, NULL, &out_key, &recomp_data, 0);
+ }
+ else {
+ // printf("DB: %02x , out_keylen: %-3d , out_datalen: %-10d , dataptr: %012lx\n", which_cdb, (int)out_key.size, (int)out_data.size, (long unsigned int)out_data.data);
+ ret = dst_dbp->put(dst_dbp, NULL, &out_key, &out_data, 0);
+ }
+
+ if (ret) {
+ printf("db: cdb_put(%d): %s", which_cdb, db_strerror(ret));
+ exit(CTDLEXIT_DB);
+ }
+
+ // Knowing the total number of rows isn't critical to the program. It's just for the user to know.
+ ++num_rows;
+ printf(" \033[32m%d\033[0m\r", num_rows);
+ fflush(stdout);