70 if (strcmp(oldname, newname) == 0)
return NULp;
72 #if defined(DEBUG) && 1
73 if (isdigit(oldname[0])) {
74 printf(
"oldname='%s' newname='%s'\n", oldname, newname);
89 if (gb_found_species && gb_species != gb_found_species) {
95 return GBS_global_string(
"Expected that a species named '%s' exists (maybe there are duplicate species, database might be corrupt)", oldname);
98 gb_name =
GB_entry(gb_species,
"name");
110 strcpy(&rns->
data[0], newname);
141 if (rns->
used_by == tree_index) {
145 sprintf(buffer,
"%s_%i", rns->
data, counter++);
146 GB_warningf(
"Species '%s' more than once in '%s', creating zombie '%s'",
147 tree->
name, currentTreeName, buffer);
151 newname = &rns->
data[0];
153 freedup(tree->
name, newname);
168 arb_progress commit_progress(
"Correcting name references",
long(3+is_genome_db));
178 if (!tree_names.
empty()) {
179 size_t tree_count = tree_names.
size();
182 for (
size_t count = 0; count<tree_count && !
error; ++count) {
183 const char *tname = tree_names[count];
188 currentTreeName = tname;
190 currentTreeName =
NULp;
202 "Please note that this tree is useless now!",
216 if (!config_names.
empty()) {
217 size_t config_count = config_names.
size();
220 for (
size_t count = 0; !error && count<config_count; ++count) {
247 error =
GBS_global_string(
"Failed to parse configuration '%s' (Reason: %s)", config_names[count], error);
251 if (!error && need_save) {
264 if (gb_species_colorset_root) {
268 size_t colorset_count = colorset_names.
size();
269 if (colorset_count>0) {
272 for (
size_t c = 0; c<colorset_count && !
error; ++c) {
279 StrArray modifiedDefs;
280 bool changed =
false;
282 for (
int d = colorDefs.
size()-1; d>=0; --d) {
283 const char *def = colorDefs[d];
284 const char *equal = strchr(def,
'=');
287 if (strcmp(equal+1,
"0") == 0) {
300 modifiedDefs.put(newDef);
319 if (!error && is_genome_db) {
321 arb_progress progress(
"Correcting names of organism references");
328 GBDATA *gb_origin_organism =
GB_entry(gb_pseudo,
"ARB_origin_species");
329 if (gb_origin_organism) {
333 const char *newname = &rns->
data[0];
357 void TEST_SLOW_rename_session() {
358 const char *inputname =
"TEST_opti_ascii_in.arb";
359 const char *outputname =
"TEST_opti_ascii_renamed.arb";
360 const char *expectedname =
"TEST_opti_ascii_renamed_expected.arb";
365 TEST_EXPECT_RESULT__NOERROREXPORTED(gb_main =
GB_open(inputname,
"rw"));
367 for (
int session = 1; session <= 2; ++session) {
386 #if defined(TEST_AUTO_UPDATE)
387 TEST_COPY_FILE(outputname, expectedname);
GBDATA * GB_open(const char *path, const char *opent)
GBDATA * GBT_colorset_root(GBDATA *gb_main, const char *itemsname)
GB_ERROR GBT_abort_rename_session()
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
GB_HASH * old_species_hash
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
static const int MIDDLE_AREA
size_t hash_size(size_t estimated_elements)
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
TreeNode * GBT_read_tree(GBDATA *gb_main, const char *tree_name, TreeRoot *troot)
static const int TOP_AREA
const char * GBS_global_string(const char *templat,...)
GB_ERROR GBT_rename_species(const char *oldname, const char *newname, bool ignore_protection)
GB_ERROR GBT_begin_rename_session(GBDATA *gb_main, int all_flag)
GB_HASH * GBS_create_dynaval_hash(long estimated_elements, GB_CASE case_sens, void(*freefun)(long))
static GB_ERROR gbt_rename_tree_rek(TreeNode *tree, int tree_index)
void GBS_free_hash(GB_HASH *hs)
GB_HASH * GBT_create_species_hash(GBDATA *gb_main)
int GB_unlink(const char *path)
char buffer[MESSAGE_BUFFERSIZE]
GB_ERROR GB_push_transaction(GBDATA *gbd)
void append_to_config_string(GBS_strstruct &out) const
#define TEST_PUBLISH(testfunction)
GB_ERROR GB_await_error()
GBDATA * GEN_first_pseudo_species(GBDATA *gb_main)
void GB_warningf(const char *templat,...)
GB_ERROR GBT_commit_rename_session()
GBT_CONFIG_ITEM_TYPE type
GB_ERROR GB_save_as(GBDATA *gbd, const char *path, const char *savetype)
GB_ERROR GBT_write_tree(GBDATA *gb_main, const char *tree_name, TreeNode *tree)
static void error(const char *msg)
GB_ERROR GB_abort_transaction(GBDATA *gbd)
GB_ERROR save(GBDATA *gb_main, const char *name, bool warnIfSavingDefault) const
GB_ERROR GBT_save_colorset(GBDATA *gb_colorset, CharPtrArray &colorsetDefs)
GB_ERROR GBT_load_colorset(GBDATA *gb_colorset, ConstStrArray &colorsetDefs)
#define TEST_EXPECT_ZERO_OR_SHOW_ERRNO(iocond)
void GBS_dynaval_free(long val)
GBDATA * GBT_find_species_rel_species_data(GBDATA *gb_species_data, const char *name)
GBDATA * GEN_next_pseudo_species(GBDATA *gb_species)
const GBT_config_item & nextItem(GB_ERROR &error)
static const char * currentTreeName
void GBT_get_tree_names(ConstStrArray &names, GBDATA *gb_main, bool sorted)
void GBT_message(GBDATA *gb_main, const char *msg)
#define TEST_EXPECT_NO_ERROR(call)
GBDATA * GBT_find_colorset(GBDATA *gb_colorset_root, const char *name)
void GBT_get_configuration_names(ConstStrArray &configNames, GBDATA *gb_main)
#define TEST_EXPECT_TEXTFILE_DIFFLINES(fgot, fwant, diff)
void GBT_get_colorset_names(ConstStrArray &colorsetNames, GBDATA *gb_colorset_root)
long GBT_get_species_count(GBDATA *gb_main)
void destroy(TreeNode *that)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
static struct @4 NameSession
bool GEN_is_genome_db(GBDATA *gb_main, int default_value)
const char * replace(int i, const char *elem)
static void gbt_free_rename_session_data()
char * release_memfriendly()
long GBS_read_hash(const GB_HASH *hs, const char *key)
GBDATA * GB_entry(GBDATA *father, const char *key)
void inc_and_check_user_abort(GB_ERROR &error)
char * GBS_global_string_copy(const char *templat,...)
void GB_close(GBDATA *gbd)
void set_definition(int area, char *new_def)
GBDATA * GBT_get_species_data(GBDATA *gb_main)