30 #define nds_assert(cond) arb_assert(cond)
32 #define NDS_PER_PAGE 10 // number of NDS definitions on each config-page
33 #define NDS_PAGES 6 // how many config-pages (each has NDS_PER_PAGE definitions)
35 #define NDS_COUNT (NDS_PER_PAGE*NDS_PAGES) // overall number of NDS definitions
37 #define AWAR_NDS_USE_ALL "arb_presets/all"
38 #define AWAR_NDS_PAGE "arb_presets/page"
53 void append(
const char *
str,
int length = -1) {
92 if (string_awar) awar = aw_root->
awar_string(awar_name,
"", awdef);
93 else awar = aw_root->
awar_int(awar_name, 0, awdef);
97 #define VIEWKEY_LENGTH_MAX 1000000 // do not change (will break backward compatibility!)
129 Awar =
viewkeyAwar(aw_root, awdef, i,
"key_text",
true); Awar->
map(gb_key_text);
130 Awar =
viewkeyAwar(aw_root, awdef, i,
"pars",
true); Awar->
map(gb_pars);
131 Awar =
viewkeyAwar(aw_root, awdef, i,
"group",
false); Awar->
map(gb_group);
132 Awar =
viewkeyAwar(aw_root, awdef, i,
"leaf",
false); Awar->
map(gb_leaf);
156 int page = awar_selected_page->
read_int();
164 int i2 = i1+NDS_PER_PAGE-1;
166 for (
int i = 0; i <= i2; i++) {
170 if (i >= i1)
map_viewkey(aw_root, awdef, i-i1, gb_viewkey, !initialized);
182 if (gb_arb_presets) {
195 else if (current_page == page_to_reset) {
201 if (only_delete_len2_entries) {
203 bool is_len2 = key && strcmp(key,
"len2") == 0;
208 gb_child = gb_next_child;
214 return ta.
close(error);
237 bool was_group_name =
false;
244 const char *wanted =
"";
246 case 0: wanted =
"name"; leaf = 1;
break;
247 case 1: wanted =
"full_name"; leaf = 1;
break;
248 case 2: wanted =
""; was_group_name =
true;
break;
249 case 3: wanted =
"acc"; leaf = 1;
break;
250 case 4: wanted =
"date";
break;
258 was_group_name =
true;
264 else if (was_group_name) {
270 if (pars[0] == 0) pars =
"taxonomy(1)";
292 if (was_group_name &&
GB_read_int(gb_inherit)) leaf = 1;
314 long DEFAULT_LEN = 0;
321 bool userWantedUnlimited = arb7value >= 999;
322 bool isDefaultAndUnused = arb7value == 30 && !leaf && !
group;
323 if (userWantedUnlimited || isDefaultAndUnused) {
327 DEFAULT_LEN = arb7value;
354 return ta.
close(error);
363 return ta.
close(error);
371 const char *numsign = strchr(predef_entry,
'#');
372 return numsign ? numsign+1 : predef_entry;
390 const char *foundPredef = NULL;
393 const char *predef = piter.get_value()->get_string();
396 if (strcmp(script, currScript) == 0) {
397 foundPredef = predef;
415 AW_window_simple *aws =
new AW_window_simple;
416 aws->init(aw_root,
"SRT_ACI_SELECT",
"SRT_ACI_SELECT");
417 aws->load_xfig(
"awt/srt_select.fig");
419 aws->button_length(13);
422 aws->create_button(
"CLOSE",
"CLOSE",
"C");
426 aws->create_button(
"HELP",
"HELP",
"H");
477 aw_message(
"Converting stored config to new NDS format -- consider saving it again.");
482 for (
int i = 0; !error && i<
NDS_COUNT; ++i) {
483 bool was_group_name =
false;
486 const char *key_text = parsedCfg.
get_entry(key_text_key);
487 if (strcmp(key_text,
"group_name") == 0) {
488 was_group_name =
true;
499 const char *inherit_value = parsedCfg.
get_entry(inherit_key);
502 inherit = atoi(inherit_value);
506 error =
GB_export_errorf(
"Expected entry '%s' in saved config", inherit_key);
510 if (was_group_name) {
516 const char *aci = parsedCfg.
get_entry(aci_key);
517 char *new_aci =
NULp;
519 if (aci[0] == 0) { new_aci = strdup(
"taxonomy(1)"); }
535 const char *flag1_value = parsedCfg.
get_entry(flag1_key);
537 int flag1 = atoi(flag1_value);
538 if (flag1 == 0) { leaf = group =
false; }
556 cdef.
write(converted_cfg_str);
557 free(converted_cfg_str);
570 error = ta.
close(error);
581 error = ta.
close(error);
587 static AW_window_simple *aws =
NULp;
589 aws =
new AW_window_simple;
590 aws->init(aw_root,
"NDS_PROPS",
"NDS");
591 aws->load_xfig(
"awt/nds.fig");
592 aws->auto_space(10, 5);
596 aws->create_button(
"CLOSE",
"CLOSE",
"C");
600 aws->create_button(
"HELP",
"HELP",
"H");
606 aws->insert_option(text,
"", p);
608 aws->update_option_menu();
612 aws->insert_default_option(
"Use all entries",
"", 1);
613 aws->insert_option (
"Only use visible entries",
"", 0);
614 aws->update_option_menu();
621 aws->button_length(13);
624 aws->get_at_position(&dummy, &closey);
626 aws->create_button(
NULp,
"K");
630 int leafx, groupx, fieldx, columnx, srtx, srtux;
632 aws->auto_space(10, 0);
636 aws->get_at_position(&leafx, &dummy);
639 aws->get_at_position(&groupx, &dummy);
642 aws->get_at_position(&fieldx, &dummy);
648 aws->get_at_position(&columnx, &dummy);
651 aws->get_at_position(&srtx, &dummy);
655 aws->button_length(0);
659 aws->create_button(button_id,
"S");
663 aws->get_at_position(&srtux, &dummy);
664 aws->at_attach_to(
true,
false, -7, 30);
665 aws->create_input_field(awar_name, 40);
672 aws->at(leafx, closey);
675 aws->create_button(
NULp,
"LEAF");
677 aws->create_button(
NULp,
"GRP.");
680 aws->create_button(
NULp,
"FIELD");
683 aws->create_button(
NULp,
"WIDTH");
686 aws->create_button(
NULp,
"SRT");
689 aws->create_button(
NULp,
"ACI/SRT PROGRAM");
699 bool only_visible_page =
false;
705 only_visible_page =
true;
712 bool use = !only_visible_page || (idx/
NDS_PER_PAGE) == page;
718 if (atLeaf || atGroup) {
723 freeset(keyname, strdup(
""));
725 freeset(fieldname[count], keyname);
729 at_leaf[count] = atLeaf;
730 at_group[count] = atGroup;
733 freenull(parsing[count]);
744 for (
int i = 0; i<count; ++i) {
745 freenull(fieldname[i]);
746 freenull(parsing[i]);
751 bool contains_separator = strchr(text, separator);
752 if (!contains_separator)
return NULp;
763 if (!species)
return "<internal error: no tree-node, no db-entry>";
764 if (!species->
name)
return "<internal error: species w/o name>";
765 appendf(
"<%s>", species->
name);
768 bool field_was_printed =
false;
769 bool is_leaf = !forceGroup && (species ? species->
is_leaf() :
true);
771 for (
int i = 0; i < count; i++) {
772 if (is_leaf) {
if (!at_leaf[i])
continue; }
773 else {
if (!at_group[i])
continue; }
776 bool apply_aci =
false;
779 const char *field_output =
"";
780 const char *field_name = fieldname[i];
782 if (field_name[0] == 0) {
802 const char *
format =
"%5.4f";
805 char *
dot = strchr(dotted,
'.');
817 if (!field_output) field_output=
"<read error>";
833 str = strdup(field_output);
840 const char *aci = parsing[i];
842 GBL_env env(gb_main, tree_name);
847 freeset(str, aci_result);
870 if (quoted) freeset(str, quoted);
879 if (!field_was_printed)
break;
885 if (i != 0) out.
put(
',');
889 if (i != 0) out.
put(
'\t');
893 field_was_printed =
true;
895 int str_len = strlen(str);
900 append(str, str_len);
904 int nds_len = lengths[i];
905 if (str_len>nds_len && nds_len != 0) {
909 append(str, str_len);
915 if (error && show_errors>0) {
931 builder->
init(gb_main);
936 NDS_Labeler::NDS_Labeler(
NDS_Type type_) :
941 NDS_Labeler::~NDS_Labeler() {
947 long NDS_Labeler::max_columns(
GBDATA *gb_main)
const {
948 return theBuilder(gb_main).max_columns();
951 const char *NDS_Labeler::speciesLabel(
GBDATA *gb_main,
GBDATA *gb_species,
TreeNode *species,
const char *tree_name)
const {
952 return theBuilder(gb_main).work(gb_main, gb_species, get_NDS_Type(), species, tree_name,
false);
954 const char *NDS_Labeler::groupLabel(
GBDATA *gb_main,
GBDATA *gb_group,
TreeNode *species,
const char *tree_name)
const {
956 return theBuilder(gb_main).work(gb_main, gb_group, get_NDS_Type(), species, tree_name,
true);
960 static char replaceTable[256];
962 for (
int i = 0; i<32; ++i) replaceTable[i] =
'?';
963 for (
int i = 32; i<256; ++i) replaceTable[i] = i;
965 const char LFREP =
'#';
967 replaceTable[
'\n'] = LFREP;
968 replaceTable[
'\r'] = LFREP;
969 replaceTable[
'\t'] =
' ';
983 for (
int i = 0; str[i]; ++i) {
996 #define TEST_EXPECT_MASK_NONPRINTABLE(i,o) do { \
997 char *masked = strdup(i); \
998 NDS_mask_nonprintable_chars(masked); \
999 TEST_EXPECT_EQUAL(masked,o); \
1003 void TEST_mask_nds() {
1004 TEST_EXPECT_MASK_NONPRINTABLE(
"plain text",
"plain text");
1005 TEST_EXPECT_MASK_NONPRINTABLE(
"with\nLF",
"with#LF");
1006 TEST_EXPECT_MASK_NONPRINTABLE(
"with\rLF",
"with#LF");
1007 TEST_EXPECT_MASK_NONPRINTABLE(
"with\r\nLF",
"with##LF");
1008 TEST_EXPECT_MASK_NONPRINTABLE(
"tab\tseparated",
"tab separated");
1009 TEST_EXPECT_MASK_NONPRINTABLE(
"\t\n\t\n",
" # #");
1012 #define TEST_EXPECT_NDS_EQUALS(specName,labeler,expected_NDS) do { \
1013 GBDATA *gb_species = GBT_find_species(gb_main, specName); \
1014 TEST_REJECT_NULL(gb_species); \
1016 const char *nds = labeler.speciesLabel(gb_main, gb_species, NULp, NULp); \
1017 TEST_EXPECT_EQUAL(nds, expected_NDS); \
1020 #define TEST_EXPECT_NDS_EQUALS__BROKEN(specName,labeler,expected_NDS) do { \
1021 GBDATA *gb_species = GBT_find_species(gb_main, specName); \
1022 TEST_REJECT_NULL(gb_species); \
1024 const char *nds = labeler.speciesLabel(gb_main, gb_species, NULp, NULp); \
1025 TEST_EXPECT_EQUAL__BROKEN(nds, expected_NDS); \
1030 const char *testDB =
"display/nds.arb";
1043 TEST_EXPECT_NDS_EQUALS(
"MycChlor", leaftext_labeler,
"'MycChlor', Mycobacterium #phenolicus, acc=X79094");
1044 TEST_EXPECT_NDS_EQUALS(
"MycChlor", leaftext_unlimited,
"'MycChlor', Mycobacterium #phenolicus, acc=X79094");
1045 TEST_EXPECT_NDS_EQUALS(
"MycChlor", tab_separated_labeler,
"'MycChlor'\tMycobacterium #phenolicus\tacc=X79094\t");
1046 TEST_EXPECT_NDS_EQUALS(
"MycChlor", comma_separated_labeler,
"'MycChlor',Mycobacterium #phenolicus,acc=X79094,");
1048 TEST_EXPECT_NDS_EQUALS(
"ActUtahe", leaftext_labeler,
"'ActUtahe', Act;ino planes uta,hen.sis#, acc=X80823, comment");
1049 TEST_EXPECT_NDS_EQUALS(
"ActUtahe", leaftext_unlimited,
"'ActUtahe', Act;ino planes uta,hen.sis#, acc=X80823, comment");
1050 TEST_EXPECT_NDS_EQUALS(
"ActUtahe", tab_separated_labeler,
"'ActUtahe'\tAct;ino planes uta,hen.sis#\tacc=X80823\tcomment");
1051 TEST_EXPECT_NDS_EQUALS(
"ActUtahe", comma_separated_labeler,
"'ActUtahe',\"Act;ino planes uta,hen.sis#\",acc=X80823,comment");
1053 TEST_EXPECT_NDS_EQUALS(
"StpGrise", leaftext_labeler,
"'StpGrise', Strepto s griseus, acc=M76388 X55435 X6");
1054 TEST_EXPECT_NDS_EQUALS(
"StpGrise", leaftext_unlimited,
"'StpGrise', Strepto s griseus, acc=M76388 X55435 X61478");
1055 TEST_EXPECT_NDS_EQUALS(
"StpGrise", tab_separated_labeler,
"'StpGrise'\tStrepto s griseus\tacc=M76388 X55435 X61478\t");
1056 TEST_EXPECT_NDS_EQUALS(
"StpGrise", comma_separated_labeler,
"'StpGrise',Strepto s griseus,acc=M76388 X55435 X61478,");
1058 TEST_EXPECT_NDS_EQUALS(
"StpAmbof", leaftext_labeler,
"'StpAmbof', Strepto s ambofaciens nomen fa, acc=M27245, This is the comment for StpAmbof :-)");
1059 TEST_EXPECT_NDS_EQUALS(
"StpAmbof", leaftext_unlimited,
"'StpAmbof', Strepto s ambofaciens nomen falsus longus abscindere, acc=M27245, This is the comment for StpAmbof :-)");
1060 TEST_EXPECT_NDS_EQUALS(
"StpAmbof", tab_separated_labeler,
"'StpAmbof'\tStrepto s ambofaciens nomen falsus longus abscindere\tacc=M27245\tThis is the comment for StpAmbof :-)");
1061 TEST_EXPECT_NDS_EQUALS(
"StpAmbof", comma_separated_labeler,
"'StpAmbof',Strepto s ambofaciens nomen falsus longus abscindere,acc=M27245,This is the comment for StpAmbof :-)");
1067 #endif // UNIT_TESTS
GBDATA * GB_open(const char *path, const char *opent)
void delete_entry(const char *entry)
void add(const char *awar_name, const char *config_name)
bool has_entry(const char *entry) const
AliDataPtr format(AliDataPtr data, const size_t wanted_len, GB_ERROR &error)
long GB_read_int(GBDATA *gbd)
GBDATA * GB_child(GBDATA *father)
static void dot(double **i, double **j, double **k)
CONSTEXPR_INLINE unsigned char safeCharIndex(char c)
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
GBDATA * GB_searchOrCreate_string(GBDATA *gb_container, const char *fieldpath, const char *default_value)
GBDATA * GB_nextEntry(GBDATA *entry)
void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const StoreConfigCallback &store_cb, const RestoreConfigCallback &load_or_reset_cb, const char *macro_id, const AWT_predefined_config *predef)
char * GB_read_as_string(GBDATA *gbd)
const char * viewkeyAwarName(int i, const char *name)
NOT4PERL long * GBT_readOrCreate_int(GBDATA *gb_container, const char *fieldpath, long default_value)
const char * GBS_global_string(const char *templat,...)
#define FORWARD_FORMATTED(receiver, format)
void AW_POPDOWN(AW_window *window)
static void nds_length_changed_cb(AW_root *, AW_awar *Awar_len1, AW_awar *Awar_len2)
static const char * script_part_of(const char *predef_entry)
CONSTEXPR long FIELD_FILTER_NDS
#define NO_FIELD_SELECTED
AW_awar * add_callback(const RootCallback &cb)
GB_ERROR GB_delete(GBDATA *&source)
void create_itemfield_selection_button(AW_window *aws, const FieldSelDef &selDef, const char *at)
static __ATTR__USERESULT GB_ERROR nds_create_vars(AW_root *aw_root, AW_default awdef, GBDATA *gb_main)
const char * work(GBDATA *gb_main, GBDATA *gbd, NDS_Type mode, TreeNode *species, const char *tree_name, bool forceGroup)
const char * read_char_pntr() const
size_t GB_read_string_count(GBDATA *gbd)
GB_ERROR GB_await_error()
static AW_root * SINGLETON
NOT4PERL long * GBT_read_int(GBDATA *gb_container, const char *fieldpath)
GBDATA * GB_create_container(GBDATA *father, const char *key)
WindowCallback makeHelpCallback(const char *helpfile)
AW_awar * viewkeyAwar(AW_root *aw_root, AW_default awdef, int i, const char *name, bool string_awar)
GB_TYPES GB_read_type(GBDATA *gbd)
void NDS_popup_select_srtaci_window(AW_window *aww, const char *acisrt_awarname)
GB_CSTR GB_read_key_pntr(GBDATA *gbd)
static void nds_restore_config(const char *stored, GBDATA *gb_main)
GBDATA * GB_create(GBDATA *father, const char *key, GB_TYPES type)
const char * GB_first_non_key_char(const char *str)
static const char * createReplaceTable()
static void awt_select_pre_from_view(AW_root *aw_root, AW_selection_list *programs)
#define TEST_REJECT_NULL(n)
#define AWAR_SELECT_ACISRT
static void error(const char *msg)
GBDATA * GB_searchOrCreate_int(GBDATA *gb_container, const char *fieldpath, long default_value)
float GB_read_float(GBDATA *gbd)
GB_CSTR GB_path_in_ARBLIB(const char *relative_path)
#define VIEWKEY_LENGTH_MAX
AW_awar * awar(const char *awar)
char * NDS_mask_nonprintable_chars(char *const str)
GB_ERROR GB_write_int(GBDATA *gbd, long i)
static char * quoted_if_containing_separator(const char *text, char separator)
static void map_viewkeys(AW_root *aw_root, GBDATA *awdef, GBDATA *gb_main)
GB_ERROR GB_export_errorf(const char *templat,...)
void ncat(const char *from, size_t count)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
static char * nds_store_config()
GB_ERROR close(GB_ERROR error)
AW_window * NDS_create_window(AW_root *aw_root, GBDATA *gb_main)
static __ATTR__USERESULT GB_ERROR nds_maintain_viewkeys(GBDATA *gb_main)
#define __ATTR__USERESULT
int GB_read_byte(GBDATA *gbd)
AW_awar * map(const char *awarn)
char * GB_read_string(GBDATA *gbd)
ItemSelector & SPECIES_get_selector()
void set_entry(const char *entry, const char *value)
const char * GBS_static_string(const char *str)
void aw_message(const char *msg)
static void map_viewkey(AW_root *aw_root, AW_default awdef, int i, GBDATA *gb_viewkey, bool initialize)
static bool in_pre_update
GB_ERROR write_string(const char *aw_string)
static void nds_init_config(AWT_config_definition &cdef)
static __ATTR__USERESULT GB_ERROR nds_delete_database_entries(GBDATA *gb_main, int page_to_reset, bool only_delete_len2_entries)
const char * get_data() const
NOT4PERL char * GB_command_interpreter_in_env(const char *str, const char *commands, const GBL_call_env &callEnv)
GBDATA * GB_nextChild(GBDATA *child)
GB_ERROR load(const char *filemask, bool append) const
GB_transaction ta(gb_var)
const char * get_entry(const char *entry) const
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
static void awt_pre_to_view(AW_root *aw_root)
void init(GBDATA *gb_main)
#define AWAR_SELECT_ACISRT_PRE
char * config_string() const
void NDS_create_vars(AW_root *aw_root, AW_default awdef, GBDATA *gb_main)
GB_ERROR write_int(long aw_int)
GBDATA * GB_entry(GBDATA *father, const char *key)
void aw_message_if(GB_ERROR error)
char * GBS_global_string_copy(const char *templat,...)
void GB_close(GBDATA *gbd)
void write(const char *cfgStr) const