ARB
db_query.cxx
Go to the documentation of this file.
1 // ============================================================ //
2 // //
3 // File : db_query.cxx //
4 // Purpose : Database queries //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ============================================================ //
10 
11 #include "db_query.h"
12 #include "db_query_local.h"
13 #include "query_expr.h"
14 
15 #include <dbui.h>
16 #include <item_sel_list.h>
17 #include <awt_config_manager.hxx>
18 #include <awt_sel_boxes.hxx>
19 
20 #include <aw_advice.hxx>
21 #include <aw_color_groups.hxx>
22 #include <aw_file.hxx>
23 #include <aw_msg.hxx>
24 #include <aw_awar.hxx>
25 #include <arb_progress.h>
26 #include <aw_root.hxx>
27 #include <aw_question.hxx>
28 #include <rootAsWin.h>
29 
30 #include <ad_cb.h>
31 
32 #include <arb_strbuf.h>
33 #include <arb_sort.h>
34 #include <arb_global_defs.h>
35 #include <Keeper.h>
36 
37 #include <list>
38 #include <stack>
39 
40 using namespace std;
41 using namespace QUERY;
42 
43 #define MAX_QUERY_LIST_LEN 100000
44 
45 #define AWAR_COLORIZE "tmp/dbquery_all/colorize"
46 
47 static void free_hit_description(long info) {
48  free(reinterpret_cast<char*>(info));
49 }
50 
51 inline void SET_QUERIED(GBDATA *gb_species, DbQuery *query, const char *hitInfo, size_t hitInfoLen = 0) {
52  dbq_assert(hitInfo);
53 
54  GB_raise_user_flag(gb_species, query->select_bit);
55 
56  char *name = query->selector.generate_item_id(query->gb_main, gb_species);
57  char *info;
58 
59  if (hitInfoLen == 0) hitInfoLen = strlen(hitInfo);
60  if (hitInfoLen>MAX_SHOWN_DATA_SIZE) {
61  char *dupInfo = strdup(hitInfo);
62  hitInfoLen = GBS_shorten_repeated_data(dupInfo);
63  if (hitInfoLen>MAX_SHOWN_DATA_SIZE) {
64  strcpy(dupInfo+hitInfoLen-5, "[...]");
65  }
66  info = strdup(dupInfo);
67  free(dupInfo);
68  }
69  else {
70  info = strdup(hitInfo);
71  }
72 
73  GBS_write_hash(query->hit_description, name, reinterpret_cast<long>(info)); // overwrite hit info (also deallocates)
74  free(name);
75 }
76 
77 inline void CLEAR_QUERIED(GBDATA *gb_species, DbQuery *query) {
78  GB_clear_user_flag(gb_species, query->select_bit);
79 
80  char *name = query->selector.generate_item_id(query->gb_main, gb_species);
81  GBS_write_hash(query->hit_description, name, 0); // delete hit info (also deallocates)
82  free(name);
83 }
84 
85 inline const char *getHitInfo(const char *item_id, DbQuery *query) {
86  long info = GBS_read_hash(query->hit_description, item_id);
87  return reinterpret_cast<const char*>(info);
88 }
89 inline const char *getHitInfo(GBDATA *gb_species, DbQuery *query) {
90  char *name = query->selector.generate_item_id(query->gb_main, gb_species);
91  const char *result = getHitInfo(name, query);
92  free(name);
93  return result;
94 }
95 inline string keptHitReason(const string& currentHitReason, GBDATA *gb_item, DbQuery *query) {
96  string reason = string("kept because ")+currentHitReason;
97  const char *hitinfo = getHitInfo(gb_item, query);
98  if (hitinfo) reason = string(hitinfo)+" ("+reason+')';
99  return reason;
100 }
101 
102 static void create_query_independent_awars(AW_root *aw_root, AW_default aw_def) {
103  aw_root->awar_int(AWAR_COLORIZE, 0, aw_def);
104 }
105 
107  return query->gb_main;
108 }
109 
111  return query->selector;
112 }
113 
118 };
119 
120 query_spec::query_spec(ItemSelector& selector_)
121  : selector(selector_),
122  gb_main(NULp),
123  gb_ref(NULp),
124  expect_hit_in_ref_list(false),
125  species_name(NULp),
126  tree_name(NULp),
127  select_bit(GB_USERFLAG_QUERY), // always == GB_USERFLAG_QUERY atm (nevertheless DO NOT hardcode)
128  use_menu(0),
129  ere_pos_fig(NULp),
130  where_pos_fig(NULp),
131  by_pos_fig(NULp),
132  qbox_pos_fig(NULp),
133  key_pos_fig(NULp),
134  query_pos_fig(NULp),
135  result_pos_fig(NULp),
136  count_pos_fig(NULp),
137  do_query_pos_fig(NULp),
138  config_pos_fig(NULp),
139  do_mark_pos_fig(NULp),
140  do_unmark_pos_fig(NULp),
141  do_delete_pos_fig(NULp),
142  do_set_pos_fig(NULp),
143  open_parser_pos_fig(NULp),
144  do_refresh_pos_fig(NULp),
145  popup_info_window(NULp),
146  info_box_pos_fig(NULp)
147 {
148  dbq_assert(&selector);
149 }
150 
151 bool query_spec::is_queried(GBDATA *gb_item) const {
152  return GB_user_flag(gb_item, select_bit);
153 }
154 
155 bool QUERY::IS_QUERIED(GBDATA *gb_item, const DbQuery *query) {
156  return query->is_queried(gb_item);
157 }
158 
160  GBDATA *gb_main = query->gb_main;
161  ItemSelector& selector = query->selector;
162 
163  long count = 0;
164 
165  for (GBDATA *gb_item_container = selector.get_first_item_container(gb_main, query->aws->get_root(), range);
166  gb_item_container;
167  gb_item_container = selector.get_next_item_container(gb_item_container, range))
168  {
169  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
170  gb_item;
171  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
172  {
173  if (IS_QUERIED(gb_item, query)) count++;
174  }
175  }
176  return count;
177 }
178 
179 // @@@ replace query_count_items by "method" of selector
180 static int query_count_items(DbQuery *query, QUERY_RANGE range, QUERY_MODES mode) {
181  int count = 0;
182  GBDATA *gb_main = query->gb_main;
183  ItemSelector& selector = query->selector;
184  GB_transaction ta(gb_main);
185 
186  for (GBDATA *gb_item_container = selector.get_first_item_container(gb_main, query->aws->get_root(), range);
187  gb_item_container;
188  gb_item_container = selector.get_next_item_container(gb_item_container, range))
189  {
190  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
191  gb_item;
192  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
193  {
194  switch (mode) {
195  case QUERY_GENERATE: ++count; break;
196  case QUERY_ENLARGE: count += !IS_QUERIED(gb_item, query); break;
197  case QUERY_REDUCE: count += IS_QUERIED(gb_item, query); break;
198  }
199  }
200  }
201  return count;
202 }
203 
204 const int MAX_CRITERIA = int(sizeof(unsigned long)*8/QUERY_SORT_CRITERIA_BITS);
205 
206 static void split_sort_mask(unsigned long sort_mask, QUERY_RESULT_ORDER *order) {
207  // splits the sort order bit mask 'sort_mask' into single sort criteria and write these into 'order'
208  // (order[0] will contain the primary sort criteria, order[1] the secondary, ...)
209 
210  for (int o = 0; o<MAX_CRITERIA; ++o) {
211  order[o] = QUERY_RESULT_ORDER(sort_mask&QUERY_SORT_CRITERIA_MASK);
212  dbq_assert(order[o] == (order[o]&QUERY_SORT_CRITERIA_MASK));
213  sort_mask = sort_mask>>QUERY_SORT_CRITERIA_BITS;
214  }
215 }
216 
218  // Returns the first criteria in 'order' (which has to have MAX_CRITERIA elements)
219  // that matches
220  // - QUERY_SORT_BY_1STFIELD_CONTENT or
221  // - QUERY_SORT_NUM_BY_1STFIELD_CONTENT or
222  // - QUERY_SORT_BY_HIT_DESCRIPTION
223  // (or QUERY_SORT_NONE if none of the above is used)
224 
226  for (int o = 0; o<MAX_CRITERIA && first == QUERY_SORT_NONE; ++o) {
228  first = order[o];
229  }
230  }
231  return first;
232 }
233 
235  // removes all sort-criteria from order which would use the order of the currently selected primary key
236 
237  int n = 0;
238  for (int o = 0; o<MAX_CRITERIA; ++o) {
240  order[n++] = order[o];
241  }
242  }
243  for (; n<MAX_CRITERIA; ++n) {
244  order[n] = QUERY_SORT_NONE;
245  }
246 }
247 
250  split_sort_mask(query->sort_mask, order);
251 
253  if (usedOrder != QUERY_SORT_BY_HIT_DESCRIPTION && usedOrder != QUERY_SORT_NONE) { // do we display values?
254  DbQuery_update_list(query);
255  }
256 }
257 
258 inline bool keep_criteria(QUERY_RESULT_ORDER old_criteria, QUERY_RESULT_ORDER new_criteria) {
259  return
260  old_criteria != QUERY_SORT_NONE && // do not keep 'unsorted' (it is no real criteria)
261  (old_criteria != new_criteria || // do not keep new criteria (added later)
262  old_criteria == QUERY_SORT_REVERSE); // reverse may occur several times -> always keep
263 }
264 
265 static void result_sort_order_changed_cb(AW_root *aw_root, DbQuery *query) {
266  // adds the new selected sort order to the sort order mask
267  // (added order removes itself, if it previously existed in sort order mask)
268  //
269  // if 'unsorted' is selected -> delete sort order
270 
271  QUERY_RESULT_ORDER new_criteria = (QUERY_RESULT_ORDER)aw_root->awar(query->awar_sort)->read_int();
272  if (new_criteria == QUERY_SORT_NONE) {
273  query->sort_mask = QUERY_SORT_NONE; // clear sort_mask
274  }
275  else {
277  split_sort_mask(query->sort_mask, order);
278 
279  int empty_or_same = 0;
280  for (int o = 0; o<MAX_CRITERIA; o++) {
281  if (!keep_criteria(order[o], new_criteria)) {
282  empty_or_same++; // these criteria will be skipped below
283  }
284  }
285 
286  unsigned long new_sort_mask = 0;
287  for (int o = MAX_CRITERIA-(empty_or_same>0 ? 1 : 2); o >= 0; o--) {
288  if (keep_criteria(order[o], new_criteria)) {
289  new_sort_mask = (new_sort_mask<<QUERY_SORT_CRITERIA_BITS)|order[o];
290  }
291  }
292  query->sort_mask = (new_sort_mask<<QUERY_SORT_CRITERIA_BITS)|new_criteria; // add new primary key
293  }
294  DbQuery_update_list(query);
295 }
296 
297 struct hits_sort_params : virtual Noncopyable {
299  char *first_key;
302 
303  hits_sort_params(DbQuery *q, const char *fk)
304  : query(q),
305  first_key(strdup(fk))
306  {
307  first_type = GBT_get_type_of_changekey(query->gb_main, first_key, query->selector.change_key_path);
308  }
309 
311  free(first_key);
312  }
313 };
314 
315 inline int numeric_string_cmp(const char *str1, const char *str2) {
316  const char *end1;
317  const char *end2;
318 
319  double double1 = strtod(str1, const_cast<char**>(&end1));
320  double double2 = strtod(str2, const_cast<char**>(&end2));
321 
322  bool conv1 = !end1[0] && str1[0];
323  bool conv2 = !end2[0] && str2[0];
324 
325  bool both_converted = conv1 && conv2;
326 
327  int cmp;
328  if (both_converted) {
329  cmp = double_cmp(double1, double2);
330  }
331  else {
332  bool conv_partial1 = end1>str1;
333  bool conv_partial2 = end2>str2;
334 
335  if (conv_partial1 && conv_partial2) {
336  cmp = double_cmp(double1, double2);
337  if (!cmp) {
338  cmp = numeric_string_cmp(end1, end2);
339  }
340  }
341  else cmp = strcmp(str1, str2);
342  }
343  return cmp;
344 }
345 
346 static int compare_hits(const void *cl_item1, const void *cl_item2, void *cl_param) {
347  const hits_sort_params *param = static_cast<const hits_sort_params*>(cl_param);
348 
349  GBDATA *gb_item1 = (GBDATA*)cl_item1;
350  GBDATA *gb_item2 = (GBDATA*)cl_item2;
351 
352  DbQuery *query = param->query;
353  ItemSelector& selector = query->selector;
354 
355  int cmp = 0;
356 
357  for (int o = 0; o<MAX_CRITERIA && cmp == 0; o++) {
358  QUERY_RESULT_ORDER criteria = param->order[o];
359 
360  switch (criteria) {
361  case QUERY_SORT_NONE:
362  o = MAX_CRITERIA; // don't sort further
363  break;
364 
366  char *field1 = GBT_read_as_string(gb_item1, param->first_key);
367  char *field2 = GBT_read_as_string(gb_item2, param->first_key);
368 
369  cmp = ARB_strNULLcmp(field1, field2);
370 
371  free(field2);
372  free(field1);
373  break;
374  }
376  switch (param->first_type) {
377  case GB_INT: {
378  long *have1 = GBT_read_int(gb_item1, param->first_key);
379  long L1 = have1 ? *have1 : 0;
380  long *have2 = GBT_read_int(gb_item2, param->first_key);
381  long L2 = have2 ? *have2 : 0;
382 
383  cmp = have1 // use same logic as ARB_strNULLcmp
384  ? (have2 ? long_cmp(L1,L2) : -1)
385  : (have2 ? 1 : 0);
386  break;
387  }
388  case GB_FLOAT: {
389  float *have1 = GBT_read_float(gb_item1, param->first_key);
390  float f1 = have1 ? *have1 : 0;
391  float *have2 = GBT_read_float(gb_item2, param->first_key);
392  float f2 = have2 ? *have2 : 0;
393 
394  cmp = have1
395  ? (have2 ? float_cmp(f1,f2) : -1)
396  : (have2 ? 1 : 0);
397  break;
398  }
399  default: {
400  char *field1 = GBT_read_as_string(gb_item1, param->first_key);
401  char *field2 = GBT_read_as_string(gb_item2, param->first_key);
402 
403  cmp = (field1 && field2)
404  ? numeric_string_cmp(field1, field2)
405  : ARB_strNULLcmp(field1, field2);
406 
407  free(field2);
408  free(field1);
409  }
410  }
411  break;
412  }
414  if (selector.parent_selector) {
415  GBDATA *gb_parent1 = selector.get_parent(gb_item1);
416  GBDATA *gb_parent2 = selector.get_parent(gb_item2);
417 
418  char *pid1 = selector.generate_item_id(query->gb_main, gb_parent1);
419  char *pid2 = selector.generate_item_id(query->gb_main, gb_parent2);
420 
421  cmp = ARB_strNULLcmp(pid1, pid2);
422 
423  free(pid2);
424  free(pid1);
425  }
426  break;
427  }
428  case QUERY_SORT_BY_ID: {
429  const char *id1 = GBT_read_char_pntr(gb_item1, selector.id_field);
430  const char *id2 = GBT_read_char_pntr(gb_item2, selector.id_field);
431 
432  cmp = strcmp(id1, id2);
433  break;
434  }
436  cmp = GB_read_flag(gb_item2)-GB_read_flag(gb_item1);
437  break;
438 
440  const char *id1 = GBT_read_char_pntr(gb_item1, selector.id_field);
441  const char *id2 = GBT_read_char_pntr(gb_item2, selector.id_field);
442  const char *info1 = reinterpret_cast<const char *>(GBS_read_hash(query->hit_description, id1));
443  const char *info2 = reinterpret_cast<const char *>(GBS_read_hash(query->hit_description, id2));
444  cmp = ARB_strNULLcmp(info1, info2);
445  break;
446  }
447  case QUERY_SORT_REVERSE: {
448  GBDATA *tmp = gb_item1; // swap items for following compares (this is a prefix revert!)
449  gb_item1 = gb_item2;
450  gb_item2 = tmp;
451  break;
452  }
453  }
454  }
455 
456  return cmp;
457 }
458 
459 static void detectMaxNameLength(const char *key, long /*val*/, void *cl_len) {
460  int *len = (int*)cl_len;
461  int klen = strlen(key);
462 
463  if (klen>*len) *len = klen;
464 }
465 
466 #if defined(ASSERTION_USED)
467 inline bool SLOW_is_pseudo_key(const char *key) {
468  return
469  strcmp(key, PSEUDO_FIELD_ANY_FIELD) == 0 ||
470  strcmp(key, PSEUDO_FIELD_ALL_FIELDS) == 0 ||
471  strcmp(key, PSEUDO_FIELD_ANY_FIELD_REC) == 0 ||
472  strcmp(key, PSEUDO_FIELD_ALL_FIELDS_REC) == 0;
473 }
474 #endif
475 inline bool is_pseudo_key(const char *key) {
476  // returns true, if 'key' is a pseudo-key
477  bool is_pseudo = key[0] == '[';
478  dbq_assert(is_pseudo == SLOW_is_pseudo_key(key));
479  return is_pseudo;
480 }
481 
484 
485  dbq_assert(query->hitlist);
486  query->hitlist->clear();
487 
488  AW_window *aww = query->aws;
489  AW_root *aw_root = aww->get_root();
490  QUERY_RANGE range = (QUERY_RANGE)aw_root->awar(query->awar_where)->read_int();
491  ItemSelector& selector = query->selector;
492 
493  // create array of hits
494  long count = count_queried_items(query, range);
495  GBDATA **sorted = ARB_alloc<GBDATA*>(count);
496  {
497  long s = 0;
498 
499  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, aw_root, range);
500  gb_item_container;
501  gb_item_container = selector.get_next_item_container(gb_item_container, range))
502  {
503  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
504  gb_item;
505  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
506  {
507  if (IS_QUERIED(gb_item, query)) sorted[s++] = gb_item;
508  }
509  }
510  }
511 
512  // sort hits
513 
514  hits_sort_params param(query, aww->get_root()->awar(query->awar_keys[0])->read_char_pntr());
515 
516  bool is_pseudo = is_pseudo_key(param.first_key);
517  bool show_value = !is_pseudo; // cannot refer to key-value of pseudo key
518 
519  if (query->sort_mask != QUERY_SORT_NONE) { // unsorted -> don't sort
520  split_sort_mask(query->sort_mask, param.order);
521  if (is_pseudo) {
523  }
524  if (show_value && find_display_determining_sort_order(param.order) == QUERY_SORT_BY_HIT_DESCRIPTION) {
525  show_value = false;
526  }
527  GB_sort((void**)sorted, 0, count, compare_hits, &param);
528  }
529 
530  // display hits
531 
532  int name_len = selector.item_name_length;
533  if (name_len == -1) { // if name_len is unknown -> detect
535  }
536 
537  long i;
538  for (i = 0; i<count && i<MAX_QUERY_LIST_LEN; i++) {
539  char *name = selector.generate_item_id(query->gb_main, sorted[i]);
540  if (name) {
541  char *toFree = NULp;
542  const char *info;
543 
544  if (show_value) {
545  toFree = GBT_read_as_string(sorted[i], param.first_key);
546  if (toFree) {
547  if (strlen(toFree)>MAX_SHOWN_DATA_SIZE) {
548  size_t shortened_len = GBS_shorten_repeated_data(toFree);
549  if (shortened_len>MAX_SHOWN_DATA_SIZE) {
550  strcpy(toFree+MAX_SHOWN_DATA_SIZE-5, "[...]");
551  }
552  }
553  }
554  else {
555  toFree = GBS_global_string_copy("<%s has no data>", param.first_key);
556  }
557  info = toFree;
558  }
559  else {
560  info = getHitInfo(name, query);
561  if (!info) info = "<no hit info>";
562  }
563 
564  dbq_assert(info);
565  const char *line = GBS_global_string("%c %-*s :%s",
566  GB_read_flag(sorted[i]) ? '*' : ' ',
567  name_len, name,
568  info);
569 
570  query->hitlist->insert(line, name);
571  free(toFree);
572  free(name);
573  }
574  }
575 
576  if (count>MAX_QUERY_LIST_LEN) {
577  query->hitlist->insert("***** List truncated *****", "");
578  }
579 
580  free(sorted);
581 
582  query->hitlist->insert_default("End of list", "");
583  query->hitlist->update();
584  aww->get_root()->awar(query->awar_count)->write_int((long)count);
585  GB_pop_transaction(query->gb_main);
586 }
587 
588 static void mark_queried_cb(AW_window*, DbQuery *query, int mark) {
589  // Mark listed species
590  // mark = 1 -> mark listed
591  // mark | 8 -> don't change rest
592 
593  ItemSelector& selector = query->selector;
595 
596  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, query->aws->get_root(), QUERY_ALL_ITEMS);
597  gb_item_container;
598  gb_item_container = selector.get_next_item_container(gb_item_container, QUERY_ALL_ITEMS))
599  {
600  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
601  gb_item;
602  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
603  {
604  if (IS_QUERIED(gb_item, query)) {
605  GB_write_flag(gb_item, mark&1);
606  }
607  else if ((mark&8) == 0) {
608  GB_write_flag(gb_item, 1-(mark&1));
609  }
610  }
611  }
612 
613  DbQuery_update_list(query);
614  GB_pop_transaction(query->gb_main);
615 }
616 
617 void QUERY::unquery_all(void *, DbQuery *query) {
619  GBDATA *gb_species;
620  for (gb_species = GBT_first_species(query->gb_main);
621  gb_species;
622  gb_species = GBT_next_species(gb_species)) {
623  CLEAR_QUERIED(gb_species, query);
624  }
625  DbQuery_update_list(query);
626  GB_pop_transaction(query->gb_main);
627 }
628 
630  ItemSelector& selector = query->selector;
632 
633  long cnt = 0;
634  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, query->aws->get_root(), QUERY_ALL_ITEMS);
635  gb_item_container;
636  gb_item_container = selector.get_next_item_container(gb_item_container, QUERY_ALL_ITEMS))
637  {
638  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
639  gb_item;
640  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
641  {
642  if (IS_QUERIED(gb_item, query)) cnt++;
643  }
644  }
645 
646  if (!cnt || !aw_ask_sure("delete_queried_species", GBS_global_string("Are you sure to delete %li %s", cnt, selector.items_name))) {
648  return;
649  }
650 
651  GB_ERROR error = NULp;
652 
653  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, query->aws->get_root(), QUERY_ALL_ITEMS);
654  !error && gb_item_container;
655  gb_item_container = selector.get_next_item_container(gb_item_container, QUERY_ALL_ITEMS))
656  {
657  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
658  !error && gb_item;
659  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
660  {
661  if (IS_QUERIED(gb_item, query)) {
662  error = GB_delete(gb_item);
663  }
664  }
665  }
666 
667  if (error) {
669  aw_message(error);
670  }
671  else {
672  DbQuery_update_list(query);
674  }
675 }
676 
677 static GB_HASH *create_ref_hash(const DbQuery *query, const char *key, bool split_words) {
678  GBDATA *gb_ref = query->gb_ref;
679  bool queried_only = query->expect_hit_in_ref_list;
681 
682  for (GBDATA *gb_species = GBT_first_species(gb_ref);
683  gb_species;
684  gb_species = GBT_next_species(gb_species))
685  {
686  if (!queried_only || IS_QUERIED(gb_species, query)) {
687  GBDATA *gb_name = GB_search(gb_species, key, GB_FIND);
688  if (gb_name) {
689  char *keyas = GB_read_as_string(gb_name);
690  if (keyas && strlen(keyas)) {
691  if (split_words) {
692  char *t;
693  for (t = strtok(keyas, " "); t; t = strtok(NULp, " ")) {
694  if (t[0]) GBS_write_hash(hash, t, (long)gb_species);
695  }
696  }
697  else {
698  GBS_write_hash(hash, keyas, (long)gb_species);
699  }
700  }
701  free(keyas);
702  }
703  }
704  }
705  return hash;
706 }
707 
708 class TargetItem : public QueryTarget {
709  RefPtr<GBDATA> gb_item;
710 public:
711  TargetItem(const DbQuery& query) :
712  QueryTarget(query.gb_main, query.get_tree_name()),
713  gb_item(NULp)
714  {}
715 
716  void aimTo(GBDATA *gb_next_item) {
717  dbq_assert(gb_next_item); // @@@ maybe allow? (to invalidate target)
718  gb_item = gb_next_item;
719  }
720  GBDATA *get_item() const {
721  dbq_assert(gb_item); // you have to call aimTo before!
722  return gb_item;
723  }
724 
725  // QueryTarget interface:
726  GBDATA *get_ACI_item() const OVERRIDE { return get_item(); }
727 };
728 
729 class ItemQueryKey FINAL_TYPE : public QueryKey, virtual Noncopyable {
730  char *key; // search key (=name of DB field or pseudo-field)
731  bool hierarchical; // is 'key' hierarchical?
732  GBQUARK keyquark; // valid only if get_type() == QKEY_EXPLICIT!
733 
734  typedef std::stack<GBDATA*> ParentStack;
735 
736  mutable GBDATA *gb_key; // last read key-entry
737  mutable ParentStack parent; // container(s) descended
738 
739  static query_key_type detect_key_type(const char *field_name) {
740  if (is_pseudo_key(field_name)) {
741  if (strcmp(field_name, PSEUDO_FIELD_ANY_FIELD) == 0) return QKEY_ANY;
742  if (strcmp(field_name, PSEUDO_FIELD_ANY_FIELD_REC) == 0) return QKEY_ANY_REC;
743  if (strcmp(field_name, PSEUDO_FIELD_ALL_FIELDS) == 0) return QKEY_ALL;
744  if (strcmp(field_name, PSEUDO_FIELD_ALL_FIELDS_REC) == 0) return QKEY_ALL_REC;
745  dbq_assert(0);
746  }
747  return QKEY_EXPLICIT;
748  }
749 
750 public:
751  ItemQueryKey(GBDATA *gb_main, const char *field_name) :
752  QueryKey(detect_key_type(field_name)),
753  key(strdup(field_name)),
754  hierarchical(false),
755  keyquark(0), // invalid quark
756  gb_key(NULp)
757  {
758  if (get_type() == QKEY_EXPLICIT) {
759  if (GB_first_non_key_char(key)) {
760  hierarchical = true;
761  }
762  else {
763  keyquark = GB_find_or_create_quark(gb_main, key);
764  }
765  }
766  }
768  free(key);
769  }
770 
771  // QueryKey interface:
772  char *get_target_data(const QueryTarget& target, GB_ERROR& error) const OVERRIDE {
773  // retrieve content of target key
774  if (!gb_key) {
775  const TargetItem& target_item = DOWNCAST_REFERENCE(const TargetItem, target);
776  gb_key = get_first_field(target_item.get_item());
777  }
778 
779  char *data;
780  if (gb_key) {
781  data = GB_read_as_string(gb_key);
782  if (!data) {
783  if (GB_readable_as_string(gb_key)) {
784  error = GB_await_error();
785  }
786  else {
788  error = GBS_global_string("field '%s' has wrong type", GB_read_key_pntr(gb_key));
789  }
790  }
791  }
792  else {
793  data = strdup(""); // non-existing field -> assume "" as default value
794  // (needed to search for missing fields using '!=*' ?)
795  }
796  return data;
797  }
798  const char *get_name() const OVERRIDE {
799  // name of target (e.g. for reports)
800  // - for explicit keys, it simply returns the specified key name
801  // - for iterating keys, it returns the name of the DB field at current iteration position,
802  // showing path to key relative to item (e.g. 'ali_16s/data')
803  // If not yet iterating, it returns the name of the pseudo-field.
804 
805  if (get_type() != QKEY_EXPLICIT && gb_key) {
806  const char *keyname = GB_read_key_pntr(gb_key);
807  if (!parent.empty()) {
808  const char *parent_path = GB_get_db_path(parent.top());
809  dbq_assert(parent.top() == GB_get_father(gb_key));
810  const char *rslash = strrchr(parent_path, '/');
811  for (int nest = parent.size()-1; rslash && nest; --nest) {
812  rslash = strrchr(rslash-1, '/');
813  }
814  return GBS_global_string("%s/%s", rslash ? rslash+1 : "<unknown>", keyname);
815  }
816  return keyname;
817  }
818  return key;
819  }
820 
821 private:
822  bool accept_or_iterate() const {
824  if (gb_key) {
825  GB_TYPES ktype = GB_read_type(gb_key);
826  if (ktype == GB_DB) {
827  switch (get_type()) {
828  case QKEY_ALL:
829  case QKEY_ANY:
830  return iterate(); // = skip over containers
831 
832  case QKEY_ALL_REC:
833  case QKEY_ANY_REC:
834  parent.push(gb_key); // remember position ..
835  gb_key = GB_child(gb_key); // .. and descend into container
836  break;
837 
838  case QKEY_EXPLICIT:
839  dbq_assert(0);
840  }
841  return accept_or_iterate();
842  }
843  if (!GB_TYPE_readable_as_string(ktype)) {
844  return iterate();
845  }
846  return true;
847  }
848  if (!parent.empty()) {
849  gb_key = parent.top();
850  parent.pop();
851  return iterate();
852  }
853  return false;
854  }
855 public:
856 
857  bool iterate() const OVERRIDE { // iterate key to next item
859  if (gb_key) gb_key = GB_nextChild(gb_key);
860  return accept_or_iterate();
861  }
862  void reset() const OVERRIDE {
863  // restart multi-key iteration
864  gb_key = NULp;
865  parent = ParentStack();
866  }
867  // ----------
868 
869 
870  GBDATA *get_first_field(GBDATA *gb_item) const {
871  GBDATA *gb_field = NULp;
872 
873  if (hierarchical) {
874  gb_field = GB_search(gb_item, key, GB_FIND);
875  }
876  else if (get_type() != QKEY_EXPLICIT) {
877  gb_field = GB_child(gb_item);
878  // no need to use same method as normal search (we just need any key here)
879  while (gb_field && GB_read_type(gb_field) == GB_DB) {
880  gb_field = GB_nextChild(gb_field);
881  }
882  }
883  else {
884  gb_field = GB_find_sub_by_quark(gb_item, keyquark, NULp, 0);
885  }
886 
887  return gb_field;
888  }
889 };
890 
891 inline query_operator awarvalue2query_operator(const char *awarvalue) {
892  if (strcmp(awarvalue, "and") == 0) return AND;
893  if (strcmp(awarvalue, "or") == 0) return OR;
894  return ILLEGAL;
895 }
896 
898  AW_root *aw_root = aws->get_root();
899  QueryExpr *first_qe = NULp;
900 
901  for (int idx = 0; idx<QUERY_EXPRESSIONS; ++idx) {
902  query_operator aqo = idx
904  : OR; // initial value is false, (false OR QUERY1) == QUERY1
905 
906  if (aqo != ILLEGAL) {
907  bool not_equal = aw_root->awar(awar_not[idx])->read_int() != 0;
908  const char *expression = aw_root->awar(awar_queries[idx])->read_char_pntr();
909  const char *field_name = aw_root->awar(awar_keys[idx])->read_char_pntr();
910  QueryKeyPtr qkey = new ItemQueryKey(gb_main, field_name);
911 
912  QueryExpr *qe = new QueryExpr(aqo, qkey, not_equal, expression);
913 
914  if (!field_name[0] || strcmp(field_name, NO_FIELD_SELECTED) == 0) {
915  qe->setError("No field selected");
916  }
917 
918  if (!first_qe) first_qe = qe;
919  else first_qe->append(qe);
920  }
921  }
922 
923  return first_qe;
924 }
925 
926 static void perform_query_cb(AW_window*, DbQuery *query, EXT_QUERY_TYPES ext_query) {
927  ItemSelector& selector = query->selector;
928 
930 
931  AW_root *aw_root = query->aws->get_root();
932  SmartPtr<QueryExpr> qexpr = query->buildQueryExpr();
933 
934  QUERY_MODES mode = (QUERY_MODES)aw_root->awar(query->awar_ere)->read_int();
935  QUERY_RANGE range = (QUERY_RANGE)aw_root->awar(query->awar_where)->read_int();
936  QUERY_TYPES type = (QUERY_TYPES)aw_root->awar(query->awar_by)->read_int();
937 
938  if (query->gb_ref && type != QUERY_MARKED) { // special for merge tool!
939  char *first_query = aw_root->awar(query->awar_queries[0])->read_string();
940  if (strlen(first_query) == 0) {
941  if (!ext_query) ext_query = EXT_QUERY_COMPARE_LINES;
942  }
943  free(first_query);
944  }
945 
946  GB_ERROR error = qexpr->getError();
947 
948  if (!error) {
949  size_t item_count = query_count_items(query, range, mode);
950  if (item_count) {
951  arb_progress progress("Searching", item_count);
952 
953  if (query->gb_ref && // merge tool only
954  (ext_query == EXT_QUERY_COMPARE_LINES || ext_query == EXT_QUERY_COMPARE_WORDS))
955  {
956  if (qexpr->get_key_type() != QKEY_EXPLICIT) {
957  error = "Please select an explicit field or specify a search string (for first expression)";
958  }
959  else {
960  GB_push_transaction(query->gb_ref);
961 
962  char *first_keyname = aw_root->awar(query->awar_keys[0])->read_string();
963  GB_HASH *ref_hash = create_ref_hash(query, first_keyname, ext_query == EXT_QUERY_COMPARE_WORDS);
964 
965  if (GBS_hash_elements(ref_hash) == 0) {
966  error = GBS_global_string("No data found in field '%s'", first_keyname);
967  }
968 
969 #if defined(DEBUG)
970  printf("query: search identical %s in field %s%s\n",
971  (ext_query == EXT_QUERY_COMPARE_WORDS ? "words" : "values"),
972  first_keyname,
973  query->expect_hit_in_ref_list ? " of species listed in other hitlist" : "");
974 #endif // DEBUG
975 
976  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, aw_root, range);
977  gb_item_container && !error;
978  gb_item_container = selector.get_next_item_container(gb_item_container, range))
979  {
980  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
981  gb_item && !error;
982  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
983  {
984  switch (mode) {
985  case QUERY_GENERATE: CLEAR_QUERIED(gb_item, query); break;
986  case QUERY_ENLARGE: if (IS_QUERIED(gb_item, query)) continue; break;
987  case QUERY_REDUCE: if (!IS_QUERIED(gb_item, query)) continue; break;
988  }
989 
990  // Note: here only the first query is used (special case in merge tool only)
991 
992  ItemQueryKey& query_key = DOWNCAST_REFERENCE(ItemQueryKey, qexpr->get_key());
993  GBDATA *gb_key = query_key.get_first_field(gb_item);
994  if (gb_key) {
995  char *data = GB_read_as_string(gb_key);
996 
997  if (data && data[0]) {
998  string hit_reason;
999  bool this_hit = false;
1000 
1001  if (ext_query == EXT_QUERY_COMPARE_WORDS) {
1002  for (char *t = strtok(data, " "); t; t = strtok(NULp, " ")) {
1003  GBDATA *gb_ref_pntr = (GBDATA *)GBS_read_hash(ref_hash, t);
1004  if (gb_ref_pntr) { // found item in other DB, with 'first_keyname' containing word from 'gb_key'
1005  this_hit = true;
1006  hit_reason = GBS_global_string("%s%s has word '%s' in %s",
1007  query->expect_hit_in_ref_list ? "Hit " : "",
1008  selector.generate_item_id(query->gb_ref, gb_ref_pntr),
1009  t, first_keyname);
1010  }
1011  }
1012  }
1013  else {
1014  GBDATA *gb_ref_pntr = (GBDATA *)GBS_read_hash(ref_hash, data);
1015  if (gb_ref_pntr) { // found item in other DB, with identical 'first_keyname'
1016  this_hit = true;
1017  hit_reason = GBS_global_string("%s%s matches %s",
1018  query->expect_hit_in_ref_list ? "Hit " : "",
1019  selector.generate_item_id(query->gb_ref, gb_ref_pntr),
1020  first_keyname);
1021  }
1022  }
1023 
1024  if (type == QUERY_DONT_MATCH) {
1025  this_hit = !this_hit;
1026  if (this_hit) hit_reason = "<no matching entry>";
1027  }
1028 
1029  if (this_hit) {
1030  dbq_assert(!hit_reason.empty());
1031  SET_QUERIED(gb_item, query, hit_reason.c_str(), hit_reason.length());
1032  }
1033  else CLEAR_QUERIED(gb_item, query);
1034  }
1035  free(data);
1036  }
1037 
1038  progress.inc_and_check_user_abort(error);
1039  }
1040  }
1041 
1042  GBS_free_hash(ref_hash);
1043  GB_pop_transaction(query->gb_ref);
1044  }
1045  }
1046  else { // "normal" query
1047  if (type == QUERY_DONT_MATCH) {
1048 #if defined(DEBUG)
1049  fputs("query: !(", stdout); qexpr->dump();
1050 #endif // DEBUG
1051 
1052  qexpr->negate();
1053  type = QUERY_MATCH;
1054 
1055 #if defined(DEBUG)
1056  fputs(") => query: ", stdout); qexpr->dump(); fputc('\n', stdout);
1057 #endif // DEBUG
1058  }
1059 #if defined(DEBUG)
1060  else { fputs("query: ", stdout); qexpr->dump(); fputc('\n', stdout); }
1061 #endif // DEBUG
1062 
1063  TargetItem target_item(*query);
1064 
1065  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, aw_root, range);
1066  gb_item_container && !error;
1067  gb_item_container = selector.get_next_item_container(gb_item_container, range))
1068  {
1069  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
1070  gb_item && !error;
1071  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
1072  {
1073  switch (mode) {
1074  case QUERY_GENERATE: CLEAR_QUERIED(gb_item, query); break;
1075  case QUERY_ENLARGE: if (IS_QUERIED(gb_item, query)) continue; break;
1076  case QUERY_REDUCE: if (!IS_QUERIED(gb_item, query)) continue; break;
1077  }
1078 
1079  bool hit = false;
1080  string hit_reason;
1081 
1082  switch (type) {
1083  case QUERY_MARKED:
1084  hit = GB_read_flag(gb_item);
1085  hit_reason = "<marked>";
1086  break;
1087 
1088  case QUERY_MATCH:
1089  dbq_assert(ext_query == EXT_QUERY_NONE);
1090  target_item.aimTo(gb_item);
1091  hit = qexpr->matches(target_item, hit_reason);
1092  break;
1093 
1094  default: dbq_assert(0); break;
1095  }
1096 
1097  if (hit) {
1098  dbq_assert(!hit_reason.empty());
1099 
1100  if (mode == QUERY_REDUCE) hit_reason = keptHitReason(hit_reason, gb_item, query);
1101  SET_QUERIED(gb_item, query, hit_reason.c_str(), hit_reason.length());
1102  }
1103  else CLEAR_QUERIED(gb_item, query);
1104 
1105  if (error) {
1106  error = GB_failedTo_error("query", GBT_get_name_or_description(gb_item), error);
1107  }
1108  else {
1109  progress.inc_and_check_user_abort(error);
1110  }
1111  }
1112  }
1113  }
1114 
1115  if (error) progress.done();
1116  }
1117  }
1118 
1119  if (!error) error = qexpr->getError(); // check for query error
1120 
1121  if (error) aw_message(error);
1122  else DbQuery_update_list(query);
1123 
1124  GB_pop_transaction(query->gb_main);
1125 }
1126 
1127 void QUERY::copy_selection_list_2_query_box(DbQuery *query, AW_selection_list *srclist, const char *hit_description) {
1128  GB_transaction ta(query->gb_main);
1129 
1130  dbq_assert(strstr(hit_description, "%s")); // hit_description needs '%s' (which is replaced by visible content of 'id')
1131 
1132  GB_ERROR error = NULp;
1133  AW_window *aww = query->aws;
1134  AW_root *aw_root = aww->get_root();
1135  GB_HASH *list_hash = srclist->to_hash(false);
1136  QUERY_MODES mode = (QUERY_MODES)aw_root->awar(query->awar_ere)->read_int();
1137  QUERY_TYPES type = (QUERY_TYPES)aw_root->awar(query->awar_by)->read_int();
1138 
1139  if (type == QUERY_MARKED) {
1140  error = "Query mode 'that are marked' does not apply here.\nEither select 'that match the query' or 'that don't match the q.'";
1141  }
1142 
1143  if (type != QUERY_MATCH || mode != QUERY_GENERATE) { // different behavior as in the past -> advice
1144  AW_advice("'Move to hitlist' now depends on the values selected for\n"
1145  " * 'Search/Add/Keep species' and\n"
1146  " * 'that match/don't match the query'\n"
1147  "in the search tool.",
1149  "Behavior changed",
1150  "next_neighbours.hlp");
1151  }
1152 
1153  long inHitlist = GBS_hash_elements(list_hash);
1154  long seenInDB = 0;
1155 
1156  for (GBDATA *gb_species = GBT_first_species(query->gb_main);
1157  gb_species && !error;
1158  gb_species = GBT_next_species(gb_species))
1159  {
1160  switch (mode) {
1161  case QUERY_GENERATE: CLEAR_QUERIED(gb_species, query); break;
1162  case QUERY_ENLARGE: if (IS_QUERIED(gb_species, query)) continue; break;
1163  case QUERY_REDUCE: if (!IS_QUERIED(gb_species, query)) continue; break;
1164  }
1165 
1166  const char *displayed = reinterpret_cast<const char*>(GBS_read_hash(list_hash, GBT_get_name_or_description(gb_species)));
1167 
1168  if (displayed) seenInDB++;
1169 
1170  if (contradicted(displayed, type == QUERY_DONT_MATCH)) {
1171  string hit_reason = GBS_global_string(hit_description, displayed ? displayed : "<no near neighbour>");
1172 
1173  if (mode == QUERY_REDUCE) hit_reason = keptHitReason(hit_reason, gb_species, query);
1174  SET_QUERIED(gb_species, query, hit_reason.c_str(), hit_reason.length());
1175  }
1176  else {
1177  CLEAR_QUERIED(gb_species, query);
1178  }
1179  }
1180 
1181  if (seenInDB < inHitlist) {
1182  aw_message(GBS_global_string("%li of %li hits were found in database", seenInDB, inHitlist));
1183  }
1184 
1185  GBS_free_hash(list_hash);
1186  if (error) aw_message(error);
1187  DbQuery_update_list(query);
1188 }
1189 
1190 
1192  AW_root *aw_root = query->aws->get_root();
1193  char *key = aw_root->awar(query->awar_keys[0])->read_string();
1194  GB_ERROR error = NULp;
1195 
1196  if (strlen(key) == 0) {
1197  error = "Please select a key (in the first query expression)";
1198  }
1199  else if (is_pseudo_key(key)) {
1200  error = "You have to select an explicit key (in the first query expression)";
1201  }
1202  else {
1203  GB_transaction dumy(query->gb_main);
1204  ItemSelector& selector = query->selector;
1205 
1207  long hashsize;
1208  QUERY_RANGE range = QUERY_ALL_ITEMS;
1209  QUERY_TYPES type = (QUERY_TYPES)aw_root->awar(query->awar_by)->read_int();
1210 
1211  switch (selector.type) {
1212  case QUERY_ITEM_SPECIES:
1213  case QUERY_ITEM_ORGANISM: {
1214  hashsize = GB_number_of_subentries(gb_species_data);
1215  break;
1216  }
1218  case QUERY_ITEM_GENES: {
1219  // handle species sub-items
1220  hashsize = 0;
1221 
1222  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, aw_root, range);
1223  gb_item_container;
1224  gb_item_container = selector.get_next_item_container(gb_item_container, range))
1225  {
1226  hashsize += GB_number_of_subentries(gb_item_container);
1227  }
1228 
1229  break;
1230  }
1231  default: {
1232  dbq_assert(0);
1233  hashsize = 0;
1234  break;
1235  }
1236  }
1237 
1238  if (!hashsize) {
1239  error = "No items exist";
1240  }
1241  else if (type == QUERY_MARKED) {
1242  error = "'that are marked' is not applicable here";
1243  }
1244 
1245  if (!error) {
1247 
1248  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, aw_root, range);
1249  gb_item_container;
1250  gb_item_container = selector.get_next_item_container(gb_item_container, range))
1251  {
1252  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
1253  gb_item;
1254  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
1255  {
1256  CLEAR_QUERIED(gb_item, query);
1257  GB_write_flag(gb_item, 0);
1258 
1259  GBDATA *gb_key = GB_search(gb_item, key, GB_FIND); if (!gb_key) continue;
1260  char *data = GB_read_as_string(gb_key); if (!data) continue;
1261 
1262  if (tokenize) {
1263  char *s;
1264  for (s=strtok(data, ",; \t."); s; s = strtok(NULp, ",; \t.")) {
1265  GBDATA *gb_old = (GBDATA *)GBS_read_hash(hash, s);
1266  if (gb_old) {
1267  const char *oldInfo = NULp;
1268  char *firstInfo = GBS_global_string_copy("1st=%s", s);
1269 
1270  if (IS_QUERIED(gb_old, query)) {
1271  const char *prevInfo = getHitInfo(gb_old, query);
1272  if (!prevInfo) {
1273  oldInfo = firstInfo;
1274  }
1275  else if (!strstr(prevInfo, firstInfo)) { // not already have 1st-entry here
1276  oldInfo = GBS_global_string("%s %s", prevInfo, firstInfo);
1277  }
1278  }
1279  else {
1280  oldInfo = firstInfo;
1281  }
1282 
1283  if (oldInfo) SET_QUERIED(gb_old, query, oldInfo);
1284  SET_QUERIED(gb_item, query, GBS_global_string("dup=%s", s));
1285  GB_write_flag(gb_item, 1);
1286 
1287  free(firstInfo);
1288  }
1289  else {
1290  GBS_write_hash(hash, s, (long)gb_item);
1291  }
1292  }
1293  }
1294  else {
1295  GBDATA *gb_old = (GBDATA *)GBS_read_hash(hash, data);
1296  if (gb_old) {
1297  if (!IS_QUERIED(gb_old, query)) {
1298  SET_QUERIED(gb_old, query, GBS_global_string("%s (1st)", data));
1299  }
1300  SET_QUERIED(gb_item, query, GBS_global_string("%s (duplicate)", data));
1301  GB_write_flag(gb_item, 1);
1302  }
1303  else {
1304  GBS_write_hash(hash, data, (long)gb_item);
1305  }
1306  }
1307 
1308  free(data);
1309  }
1310 
1311  if (type == QUERY_DONT_MATCH) {
1312  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
1313  gb_item;
1314  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
1315  {
1316  if (IS_QUERIED(gb_item, query)) {
1317  CLEAR_QUERIED(gb_item, query);
1318  GB_write_flag(gb_item, 0); // unmark
1319  }
1320  else {
1321  SET_QUERIED(gb_item, query, tokenize ? "<entry with unique words>" : "<unique entry>");
1322  }
1323  }
1324  }
1325  }
1326 
1327  GBS_free_hash(hash);
1328  }
1329 
1330  if (type != QUERY_MATCH) {
1331  AW_advice("'Find equal entries' now depends on the values selected for\n"
1332  " * 'that match/don't match the query'\n"
1333  "in the search tool.",
1335  "Behavior changed",
1336  "search_duplicates.hlp");
1337  }
1338  }
1339 
1340  free(key);
1341 
1342  if (error) aw_message(error);
1343  DbQuery_update_list(query);
1344 }
1345 
1347  ItemSelector& selector = query->selector;
1348  AW_root *aw_root = query->aws->get_root();
1350 
1351  const char *key;
1352  if (!error) {
1353  bool acceptIdMod = aw_root->awar(query->awar_acceptIdMod)->read_int();
1354  FailIfField failMode = acceptIdMod ? FIF_ALLOW_ID_CHANGE : FIF_STANDARD;
1355  key = prepare_and_get_selected_itemfield(aw_root, query->awar_parskey, query->gb_main, selector, failMode);
1356  if (!key) error = GB_await_error();
1357  }
1358 
1359  if (!error) {
1360  GB_TYPES key_type = GBT_get_type_of_changekey(query->gb_main, key, selector.change_key_path);
1361  bool safe_conversion = (key_type != GB_STRING) && !aw_root->awar(query->awar_acceptConvError)->read_int();
1362  char *command = aw_root->awar(query->awar_parsvalue)->read_string();
1363 
1364  if (!strlen(command)) error = "Please enter a command";
1365 
1366  if (!error) {
1367  long ncount = aw_root->awar(query->awar_count)->read_int();
1368  char *deftag = aw_root->awar(query->awar_deftag)->read_string();
1369  char *tag = aw_root->awar(query->awar_tag)->read_string();
1370 
1371  {
1372  long use_tag = aw_root->awar(query->awar_use_tag)->read_int();
1373  if (!use_tag || !strlen(tag)) {
1374  freenull(tag);
1375  }
1376  }
1377  int double_pars = aw_root->awar(query->awar_double_pars)->read_int();
1378 
1379  arb_progress progress("Parse fields", ncount);
1380  QUERY_RANGE range = (QUERY_RANGE)aw_root->awar(query->awar_where)->read_int();
1381  GBL_env env(query->gb_main, query->get_tree_name());
1382 
1383  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, aw_root, range);
1384  !error && gb_item_container;
1385  gb_item_container = selector.get_next_item_container(gb_item_container, range))
1386  {
1387  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
1388  !error && gb_item;
1389  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
1390  {
1391  if (IS_QUERIED(gb_item, query)) {
1392  GBDATA *gb_new = GB_search(gb_item, key, GB_FIND);
1393  error = GB_incur_error_if(!gb_new);
1394 
1395  if (!error) {
1396  GBL_call_env callEnv(gb_item, env);
1397 
1398  char *str = gb_new ? GB_read_as_string(gb_new) : strdup("");
1399  char *parsed = NULp;
1400 
1401  if (double_pars) {
1402  char *com2 = GB_command_interpreter_in_env(str, command, callEnv);
1403  if (com2) {
1404  if (tag) parsed = GBS_modify_tagged_string_with_ACI("", deftag, tag, com2, callEnv);
1405  else parsed = GB_command_interpreter_in_env ("", com2, callEnv);
1406 
1407  free(com2);
1408  }
1409  }
1410  else {
1411  if (tag) parsed = GBS_modify_tagged_string_with_ACI(str, deftag, tag, command, callEnv);
1412  else parsed = GB_command_interpreter_in_env (str, command, callEnv);
1413  }
1414 
1415  if (!parsed) error = GB_await_error();
1416  else {
1417  if (strcmp(parsed, str) != 0) { // any change?
1418  if (gb_new && parsed[0] == 0) { // empty result -> delete field
1419  error = GB_delete(gb_new);
1420  }
1421  else {
1422  if (!gb_new) {
1423  gb_new = GB_search(gb_item, key, key_type);
1424  if (!gb_new) error = GB_await_error();
1425  }
1426  if (!error) {
1427  error = GB_write_autoconv_string(gb_new, parsed); // <- field is actually written HERE
1428  if (!error && safe_conversion) {
1429  dbq_assert(key_type != GB_STRING);
1430  char *resulting = GB_read_as_string(gb_new);
1431  if (!resulting) {
1432  error = GB_await_error();
1433  }
1434  else {
1435  if (strcmp(resulting, parsed) != 0) {
1436  error = GBS_global_string("Conversion error: writing '%s'\n"
1437  "resulted in '%s'\n"
1438  "(mark checkbox to accept conversion errors)",
1439  parsed, resulting);
1440  }
1441  }
1442  }
1443  }
1444  }
1445  }
1446  free(parsed);
1447  }
1448  free(str);
1449  }
1450 
1451  if (error) {
1452  char *errCopy = strdup(error);
1453  char *itemId = selector.generate_item_id(query->gb_main, gb_item);
1454 
1455  error = GBS_global_string("While modifying field of %s '%s':\n%s",
1456  selector.item_name, itemId, errCopy);
1457 
1458  free(itemId);
1459  free(errCopy);
1460  }
1461 
1462  progress.inc_and_check_user_abort(error);
1463  }
1464  }
1465  }
1466 
1467  delete tag;
1468  free(deftag);
1469 
1470  if (error) progress.done();
1471  }
1472 
1473  free(command);
1474  }
1475 
1476  error = GB_end_transaction(query->gb_main, error);
1477  aw_message_if(error);
1478 }
1479 
1480 static void predef_prg(AW_root *aw_root, DbQuery *query) {
1481  char *str = aw_root->awar(query->awar_parspredefined)->read_string();
1482  char *brk = strchr(str, '#');
1483  if (brk) {
1484  *(brk++) = 0;
1485  char *kv = str;
1486  if (!strcmp(str, "ali_*/data")) { // when the target field contains this string -> replace it with current alignment
1487  GB_transaction ta(query->gb_main);
1488  char *use = GBT_get_default_alignment(query->gb_main);
1489  if (!use) {
1491  }
1492  else {
1493  kv = GBS_global_string_copy("%s/data", use);
1494  free(use);
1495  }
1496  }
1497  aw_root->awar(query->awar_parskey)->write_string(kv);
1498  if (kv != str) free(kv);
1499  aw_root->awar(query->awar_parsvalue)->write_string(brk);
1500  }
1501  else {
1502  aw_root->awar(query->awar_parsvalue)->write_string(str);
1503  }
1504  free(str);
1505 }
1506 
1507 static void colorize_queried_cb(AW_window *, DbQuery *query) {
1508  ItemSelector& selector = query->selector;
1509  GB_transaction ta(query->gb_main);
1510  GB_ERROR error = NULp;
1511  AW_root *aw_root = query->aws->get_root();
1512  int color_group = aw_root->awar(AWAR_COLORIZE)->read_int();
1513  QUERY_RANGE range = (QUERY_RANGE)aw_root->awar(query->awar_where)->read_int();
1514  bool changed = false;
1515 
1516  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, aw_root, range);
1517  !error && gb_item_container;
1518  gb_item_container = selector.get_next_item_container(gb_item_container, range))
1519  {
1520  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
1521  !error && gb_item;
1522  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
1523  {
1524  if (IS_QUERIED(gb_item, query)) {
1525  error = GBT_set_color_group(gb_item, color_group);
1526  if (!error) changed = true;
1527  }
1528  }
1529  }
1530 
1531  if (error) GB_export_error(error);
1532  else if (changed) selector.trigger_display_refresh();
1533 }
1534 
1535 static void colorize_marked_cb(AW_window *aww, BoundItemSel *cmd) {
1536  ItemSelector& sel = cmd->selector;
1537  GB_transaction ta(cmd->gb_main);
1538  GB_ERROR error = NULp;
1539  AW_root *aw_root = aww->get_root();
1540  int color_group = aw_root->awar(AWAR_COLORIZE)->read_int();
1541  QUERY_RANGE range = QUERY_ALL_ITEMS; // @@@ FIXME: make customizable
1542 
1543  for (GBDATA *gb_item_container = sel.get_first_item_container(cmd->gb_main, aw_root, range);
1544  !error && gb_item_container;
1545  gb_item_container = sel.get_next_item_container(gb_item_container, range))
1546  {
1547  for (GBDATA *gb_item = sel.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
1548  !error && gb_item;
1549  gb_item = sel.get_next_item(gb_item, QUERY_ALL_ITEMS))
1550  {
1551  if (GB_read_flag(gb_item)) {
1552  error = GBT_set_color_group(gb_item, color_group);
1553  }
1554  }
1555  }
1556 
1557  if (error) GB_export_error(error);
1558 }
1559 
1564 };
1565 
1566 static void mark_colored_cb(AW_window *aww, BoundItemSel *cmd, mark_mode mode) {
1567  // @@@ mark_colored_cb is obsolete! (will be replaced by dynamic coloring in the future)
1568  ItemSelector& sel = cmd->selector;
1569  AW_root *aw_root = aww->get_root();
1570  int color_group = aw_root->awar(AWAR_COLORIZE)->read_int();
1571  QUERY_RANGE range = QUERY_ALL_ITEMS; // @@@ FIXME: make customizable
1572 
1573  GB_transaction ta(cmd->gb_main);
1574 
1575  for (GBDATA *gb_item_container = sel.get_first_item_container(cmd->gb_main, aw_root, range);
1576  gb_item_container;
1577  gb_item_container = sel.get_next_item_container(gb_item_container, range))
1578  {
1579  for (GBDATA *gb_item = sel.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
1580  gb_item;
1581  gb_item = sel.get_next_item(gb_item, QUERY_ALL_ITEMS))
1582  {
1583  int my_color = GBT_get_color_group(gb_item);
1584  if (my_color == color_group) {
1585  bool marked = GB_read_flag(gb_item);
1586 
1587  switch (mode) {
1588  case UNMARK: marked = 0; break;
1589  case MARK: marked = 1; break;
1590  case INVERT: marked = !marked; break;
1591 
1592  default: dbq_assert(0); break;
1593  }
1594 
1595  GB_write_flag(gb_item, marked);
1596  }
1597  }
1598  }
1599 
1600 }
1601 
1602 // --------------------------------------------------------------------------------
1603 // color sets
1604 
1608 
1609  const char *get_items_name() const {
1610  return bsel->selector.items_name;
1611  }
1612 };
1613 
1614 #define AWAR_COLOR_LOADSAVE_NAME "tmp/colorset/name"
1615 
1617  return GBT_colorset_root(bsel->gb_main, bsel->selector.items_name);
1618 }
1619 
1621  ConstStrArray foundSets;
1622  {
1623  GB_transaction ta(csd->bsel->gb_main);
1624  GBT_get_colorset_names(foundSets, get_colorset_root(csd->bsel));
1625  }
1626 
1627  AW_selection_list *sel = csd->colorsets;
1628  sel->clear();
1629  sel->insert_default("<new colorset>", "");
1630  for (size_t i = 0; i<foundSets.size(); ++i) {
1631  sel->insert(foundSets[i], foundSets[i]);
1632  }
1633  sel->update();
1634 }
1635 
1636 static void colorset_changed_cb(GBDATA*, const color_save_data *csd, GB_CB_TYPE cbt) {
1637  if (cbt&GB_CB_CHANGED) {
1639  }
1640 }
1641 
1642 static void create_colorset_representation(BoundItemSel *bsel, AW_root *aw_root, StrArray& colordefs, GB_ERROR& error) {
1643  ItemSelector& sel = bsel->selector;
1644  GBDATA *gb_main = bsel->gb_main;
1645 
1646  dbq_assert(!error);
1647 
1648  for (GBDATA *gb_item_container = sel.get_first_item_container(gb_main, aw_root, QUERY_ALL_ITEMS);
1649  gb_item_container;
1650  gb_item_container = sel.get_next_item_container(gb_item_container, QUERY_ALL_ITEMS))
1651  {
1652  for (GBDATA *gb_item = sel.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
1653  gb_item;
1654  gb_item = sel.get_next_item(gb_item, QUERY_ALL_ITEMS))
1655  {
1656  int color = GBT_get_color_group(gb_item);
1657  if (color>0) {
1658  char *id = sel.generate_item_id(gb_main, gb_item);
1659  char *color_def = GBS_global_string_copy("%s=%i", id, color);
1660 
1661  colordefs.put(color_def);
1662  free(id);
1663  }
1664  }
1665  }
1666 
1667  if (colordefs.empty()) {
1668  error = GBS_global_string("Could not find any colored %s", sel.items_name);
1669  }
1670 }
1671 
1673  ItemSelector& sel = bsel->selector;
1674  GB_ERROR error = NULp;
1675  bool changed = false;
1676 
1677  for (GBDATA *gb_item_container = sel.get_first_item_container(bsel->gb_main, aw_root, QUERY_ALL_ITEMS);
1678  !error && gb_item_container;
1679  gb_item_container = sel.get_next_item_container(gb_item_container, QUERY_ALL_ITEMS))
1680  {
1681  for (GBDATA *gb_item = sel.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
1682  !error && gb_item;
1683  gb_item = sel.get_next_item(gb_item, QUERY_ALL_ITEMS))
1684  {
1685  error = GBT_set_color_group(gb_item, 0); // clear colors
1686  if (!error) changed = true;
1687  }
1688  }
1689 
1690  if (changed && !error) sel.trigger_display_refresh();
1691  return error;
1692 }
1693 
1694 static void clear_all_colors_cb(AW_window *aww, BoundItemSel *bsel) {
1695  GB_transaction ta(bsel->gb_main);
1696  GB_ERROR error = clear_all_colors(bsel, aww->get_root());
1697 
1698  if (error) {
1699  error = ta.close(error);
1700  aw_message(error);
1701  }
1702 }
1703 
1705  ItemSelector& sel = bsel->selector;
1706  GBDATA *gb_main = bsel->gb_main;
1707  bool changed = false;
1708  GB_ERROR error = NULp;
1709  int ignores = 0;
1710 
1711  for (size_t d = 0; d<colordefs.size() && !error; ++d) {
1712  const char *def = colordefs[d];
1713  const char *equal = strchr(def, '=');
1714 
1715  if (equal) {
1716  LocallyModify<char> tempSplit(const_cast<char*>(equal)[0], 0);
1717 
1718  const char *id = def;
1719  GBDATA *gb_item = sel.find_item_by_id(gb_main, id);
1720  if (!gb_item) {
1721  aw_message(GBS_global_string("No such %s: '%s' (ignored)", sel.item_name, id)); // only warn
1722  ++ignores;
1723  }
1724  else {
1725  int color_group = atoi(equal+1);
1726  if (color_group>0) { // bugfix: saved color groups contained zero (which means "no color") by mistake; ignore
1727  error = GBT_set_color_group(gb_item, color_group);
1728  if (!error) changed = true;
1729  }
1730  }
1731  }
1732  else {
1733  aw_message(GBS_global_string("Invalid colordef '%s' (ignored)", def));
1734  ++ignores;
1735  }
1736  }
1737  if (changed && !error) sel.trigger_display_refresh();
1738  if (ignores>0 && !error) {
1739  aw_message(GBS_global_string("Warning: failed to restore color assignment for %i %s", ignores, sel.items_name));
1740  }
1741 
1742  return error;
1743 }
1744 
1750 };
1751 
1753  AW_root *aw_root = aws->get_root();
1754  char *name = aw_root->awar(AWAR_COLOR_LOADSAVE_NAME)->read_string();
1755  GB_ERROR error = NULp;
1756 
1757  if (name[0] == 0) error = "Please enter a name for the colorset.";
1758  else {
1759  GB_transaction ta(bsel->gb_main);
1760 
1761  GBDATA *gb_colorset_root = get_colorset_root(bsel);
1762  GBDATA *gb_colorset = gb_colorset_root ? GBT_find_colorset(gb_colorset_root, name) : NULp;
1763 
1764  error = GB_incur_error();
1765  if (!error) {
1766  if (mode == SAVE) {
1767  if (!gb_colorset) { // create new colorset
1768  gb_colorset = GBT_find_or_create_colorset(gb_colorset_root, name);
1769  if (!gb_colorset) error = GB_await_error();
1770  }
1771  dbq_assert(gb_colorset || error);
1772 
1773  if (!error) {
1774  StrArray colordefs;
1775  create_colorset_representation(bsel, aw_root, colordefs, error);
1776  if (!error) error = GBT_save_colorset(gb_colorset, colordefs);
1777  }
1778  }
1779  else {
1780  if (!gb_colorset) error = GBS_global_string("Colorset '%s' not found", name);
1781  else {
1782  if (mode == LOAD || mode == OVERLAY) {
1783  ConstStrArray colordefs;
1784  error = GBT_load_colorset(gb_colorset, colordefs);
1785 
1786  if (!error && colordefs.empty()) error = "oops.. empty colorset";
1787  if (!error && mode == LOAD) error = clear_all_colors(bsel, aw_root);
1788  if (!error) error = restore_colorset_representation(bsel, colordefs);
1789  }
1790  else {
1791  dbq_assert(mode == DELETE);
1792  error = GB_delete(gb_colorset);
1793  }
1794  }
1795  }
1796  }
1797  error = ta.close(error);
1798  }
1799  free(name);
1800 
1801  if (error) aw_message(error);
1802 }
1803 
1805  static AW_window **aw_loadsave = NULp;
1806  if (!aw_loadsave) {
1807  // init data
1809  ARB_calloc(aw_loadsave, QUERY_ITEM_TYPES); // contains loadsave windows for each item type
1810  }
1811 
1813 
1815 
1816  if (!aw_loadsave[type]) {
1817  // init window
1818  AW_window_simple *aws = new AW_window_simple;
1819  {
1820  char *window_id = GBS_global_string_copy("colorset_loadsave_%s", csd->get_items_name());
1821  aws->init(aw_root, window_id, GBS_global_string("Load/Save %s colorset", csd->get_items_name()));
1822  free(window_id);
1823  }
1824 
1825  aws->load_xfig("query/color_loadsave.fig");
1826 
1827  aws->at("close");
1828  aws->callback(AW_POPDOWN);
1829  aws->create_button("CLOSE", "CLOSE", "C");
1830 
1831  aws->at("help");
1832  aws->callback(makeHelpCallback("color_loadsave.hlp"));
1833  aws->create_button("HELP", "HELP", "H");
1834 
1835  dbq_assert(!csd->colorsets);
1837 
1839 
1840  aws->at("save"); aws->callback(makeWindowCallback(loadsave_colorset_cb, csd->bsel, SAVE)); aws->create_button("save", "Save", "S");
1841  aws->at("load"); aws->callback(makeWindowCallback(loadsave_colorset_cb, csd->bsel, LOAD)); aws->create_button("load", "Load", "L");
1842  aws->at("overlay"); aws->callback(makeWindowCallback(loadsave_colorset_cb, csd->bsel, OVERLAY)); aws->create_button("overlay", "Overlay", "O");
1843  aws->at("delete"); aws->callback(makeWindowCallback(loadsave_colorset_cb, csd->bsel, DELETE)); aws->create_button("delete", "Delete", "D");
1844 
1845  aws->at("reset");
1846  aws->callback(makeWindowCallback(clear_all_colors_cb, csd->bsel));
1847  aws->create_button("reset", "Reset", "R");
1848 
1849  // callbacks
1850  {
1851  GB_transaction ta(csd->bsel->gb_main);
1852  GBDATA *gb_colorset = get_colorset_root(csd->bsel);
1853  GB_add_callback(gb_colorset, GB_CB_CHANGED, makeDatabaseCallback(colorset_changed_cb, csd));
1854  }
1855 
1856  aw_loadsave[type] = aws;
1857  }
1858 
1859  return aw_loadsave[type];
1860 }
1861 
1863  // invoked by 'colorize listed' (sel != 0)
1864  // and 'colorize marked/mark colored' (query != 0)
1865 
1866  enum { COLORIZE_INVALID, COLORIZE_LISTED, COLORIZE_MARKED } mode = COLORIZE_INVALID;
1867 
1869 
1870  AW_window_simple *aws = new AW_window_simple;
1871 
1872  dbq_assert(contradicted(query, sel));
1873 
1874  if (query) {
1875  dbq_assert(mode == COLORIZE_INVALID);
1876  mode = COLORIZE_LISTED;
1877  }
1878  if (sel) {
1879  dbq_assert(mode == COLORIZE_INVALID);
1880  mode = COLORIZE_MARKED;
1881  }
1882  dbq_assert(!(mode == COLORIZE_INVALID));
1883 
1884  ItemSelector& Sel = mode == COLORIZE_LISTED ? query->selector : *sel;
1885  const char *what = mode == COLORIZE_LISTED ? "listed" : "marked";
1886 
1887  {
1888  char *macro_name = GBS_global_string_copy("COLORIZE_%s_%s", what, Sel.items_name);
1889  char *window_name = GBS_global_string_copy("Colorize %s %s", what, Sel.items_name);
1890 
1891  aws->init(aw_root, macro_name, window_name);
1892 
1893  free(window_name);
1894  free(macro_name);
1895  }
1896 
1897  aws->load_xfig("query/colorize.fig");
1898 
1899  aws->auto_space(10, 10);
1900 
1901  aws->at("close");
1902  aws->callback(AW_POPDOWN);
1903  aws->create_button("CLOSE", "CLOSE", "C");
1904 
1905  aws->at("help");
1906  aws->callback(makeHelpCallback(mode == COLORIZE_LISTED ? "set_color_of_listed.hlp" : "colorize.hlp"));
1907  aws->create_button("HELP", "HELP", "H");
1908 
1909  aws->at("colorize");
1910 
1911  BoundItemSel *bsel = new BoundItemSel(gb_main, ((mode == COLORIZE_MARKED) ? *sel : query->selector)); // do not free, bound to CB
1912 
1913  if (mode == COLORIZE_LISTED) aws->callback(makeWindowCallback(colorize_queried_cb, query));
1914  else aws->callback(makeWindowCallback(colorize_marked_cb, bsel));
1915 
1916  aws->create_autosize_button("COLORIZE", GBS_global_string_copy("Set color of %s %s to ...", what, Sel.items_name), "S", 2);
1917 
1918  {
1919  int color_group;
1920 
1921  aws->create_option_menu(AWAR_COLORIZE);
1922  aws->insert_default_option("No color group", "none", 0);
1923  for (color_group = 1; color_group <= AW_COLOR_GROUPS; ++color_group) {
1924  char *name = AW_get_color_group_name(aw_root, color_group);
1925  aws->insert_option(name, "", color_group);
1926  free(name);
1927  }
1928  aws->update_option_menu();
1929  }
1930 
1931  color_save_data *csd = new color_save_data; // do not free, bound to CB
1932  csd->bsel = bsel;
1933  csd->colorsets = NULp;
1934 
1935  aws->at("loadsave");
1936  aws->callback(makeCreateWindowCallback(create_loadsave_colored_window, csd));
1937  aws->create_autosize_button("LOADSAVE_COLORED", "Load/Save", "L");
1938 
1939  if (mode == COLORIZE_MARKED) {
1940  aws->at("mark");
1941  aws->callback(makeWindowCallback(mark_colored_cb, bsel, MARK));
1942  aws->create_autosize_button("MARK_COLORED", GBS_global_string_copy("Mark all %s of ...", Sel.items_name), "M", 2);
1943 
1944  aws->at("unmark");
1945  aws->callback(makeWindowCallback(mark_colored_cb, bsel, UNMARK));
1946  aws->create_autosize_button("UNMARK_COLORED", GBS_global_string_copy("Unmark all %s of ...", Sel.items_name), "U", 2);
1947 
1948  aws->at("invert");
1949  aws->callback(makeWindowCallback(mark_colored_cb, bsel, INVERT));
1950  aws->create_autosize_button("INVERT_COLORED", GBS_global_string_copy("Invert all %s of ...", Sel.items_name), "I", 2);
1951  }
1952 
1953  aws->at_newline();
1954  aws->window_fit();
1955 
1956  return aws;
1957 }
1958 
1960  return create_colorize_window(aw_root, query->gb_main, query, NULp);
1961 }
1962 
1964  return create_colorize_window(aw_root, gb_main, NULp, &sel);
1965 }
1966 
1968  const char *typeawar = get_itemfield_type_awarname(query->awar_parskey);
1969  dbq_assert(typeawar);
1970 
1971  cdef.add(query->awar_parskey, "key");
1972  cdef.add(typeawar, "type");
1973  cdef.add(query->awar_use_tag, "usetag");
1974  cdef.add(query->awar_deftag, "deftag");
1975  cdef.add(query->awar_tag, "modtag");
1976  cdef.add(query->awar_double_pars, "doubleparse");
1977  cdef.add(query->awar_acceptConvError, "acceptconv");
1978  cdef.add(query->awar_acceptIdMod, "acceptidmod");
1979  cdef.add(query->awar_parsvalue, "aci");
1980 }
1981 
1983  AW_window_simple *aws = new AW_window_simple;
1984 
1985  {
1986  char *macro_name = GBS_global_string_copy("MODIFY_DATABASE_FIELD_%s", query->selector.items_name);
1987  char *window_name = GBS_global_string_copy("MODIFY DATABASE FIELD of listed %s", query->selector.items_name);
1988 
1989  aws->init(aw_root, macro_name, window_name);
1990 
1991  free(window_name);
1992  free(macro_name);
1993  }
1994 
1995  aws->load_xfig("query/modify_fields.fig");
1996 
1997  aws->at("close");
1998  aws->callback(AW_POPDOWN);
1999  aws->create_button("CLOSE", "CLOSE", "C");
2000 
2001  aws->at("help");
2002  aws->callback(makeHelpCallback("mod_field_list.hlp"));
2003  aws->create_button("HELP", "HELP", "H");
2004 
2005  aws->at("helptags");
2006  aws->callback(makeHelpCallback("tags.hlp"));
2007  aws->create_button("HELP_TAGS", "Help tags", "H");
2008 
2010  aws->at("acceptErr"); aws->create_toggle(query->awar_acceptConvError);
2011 
2012  // ------------------------
2013  // expert section
2014  aws->at("usetag"); aws->create_toggle (query->awar_use_tag);
2015  aws->at("deftag"); aws->create_input_field(query->awar_deftag);
2016  aws->at("tag"); aws->create_input_field(query->awar_tag);
2017  aws->at("double"); aws->create_toggle (query->awar_double_pars);
2018  aws->at("acceptID"); aws->create_toggle (query->awar_acceptIdMod);
2019  // ------------------------
2020 
2021  aws->at("parser");
2022  aws->create_text_field(query->awar_parsvalue);
2023 
2024  aws->at("go");
2025  aws->callback(makeWindowCallback(modify_fields_of_queried_cb, query));
2026  aws->create_button("GO", "GO", "G");
2027 
2028  aws->at("pre");
2029  AW_selection_list *programs = aws->create_selection_list(query->awar_parspredefined);
2030 
2031  const char *sellst = NULp;
2032  switch (query->selector.type) {
2033  case QUERY_ITEM_SPECIES:
2034  case QUERY_ITEM_ORGANISM: sellst = "mod_fields*.sellst"; break;
2035  case QUERY_ITEM_GENES: sellst = "mod_gene_fields*.sellst"; break;
2036  case QUERY_ITEM_EXPERIMENTS: sellst = "mod_experiment_fields*.sellst"; break;
2037  default: dbq_assert(0); break;
2038  }
2039 
2040  GB_ERROR error;
2041  if (sellst) {
2042  StorableSelectionList storable_sellist(TypedSelectionList("sellst", programs, "field modification scripts", "mod_fields"));
2043  error = storable_sellist.load(GB_concat_path_in_ARBLIB("sellists", sellst), false);
2044  }
2045  else {
2046  error = "No default selection list for query-type";
2047  }
2048 
2049  if (error) {
2050  aw_message(error);
2051  }
2052  else {
2053  aws->get_root()->awar(query->awar_parspredefined)->add_callback(makeRootCallback(predef_prg, query));
2054  }
2055 
2056  aws->at("config");
2058  GBS_global_string("mod_%s_fields", query->selector.item_name),
2059  makeConfigSetupCallback(setup_modify_fields_config, query));
2060 
2061  return aws;
2062 }
2063 
2064 static void set_field_of_queried_cb(AW_window*, DbQuery *query, bool append) {
2065  // set fields of listed items
2066  ItemSelector& selector = query->selector;
2067  GB_ERROR error = NULp;
2068  AW_root *aw_root = query->aws->get_root();
2069  bool allow_loss = aw_root->awar(query->awar_writelossy)->read_int();
2070 
2071  char *value = aw_root->awar(query->awar_setvalue)->read_string();
2072  if (value[0] == 0) freenull(value);
2073 
2074  size_t value_len = value ? strlen(value) : 0;
2075 
2076  GB_begin_transaction(query->gb_main);
2077 
2078  const char *key = prepare_and_get_selected_itemfield(aw_root, query->awar_writekey, query->gb_main, selector);
2079  if (!key) error = GB_await_error();
2080 
2081  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, aw_root, QUERY_ALL_ITEMS);
2082  !error && gb_item_container;
2083  gb_item_container = selector.get_next_item_container(gb_item_container, QUERY_ALL_ITEMS))
2084  {
2085  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
2086  !error && gb_item;
2087  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
2088  {
2089  if (IS_QUERIED(gb_item, query)) {
2090  if (!value) { // empty value -> delete field
2091  if (!append) {
2092  GBDATA *gb_field = GB_search(gb_item, key, GB_FIND);
2093  if (gb_field) error = GB_delete(gb_field);
2094  }
2095  // otherwise "nothing" is appended (=noop)
2096  }
2097  else {
2099  if (!gb_field) error = GB_await_error();
2100  else {
2101  const char *new_content = value;
2102  SmartCharPtr content;
2103 
2104  if (append) {
2105  char *old = GB_read_as_string(gb_field);
2106  if (!old) error = "field has incompatible type";
2107  else {
2108  size_t old_len = strlen(old);
2109  GBS_strstruct buf(old_len+value_len+2);
2110 
2111  buf.ncat(old, old_len);
2112  buf.ncat(value, value_len);
2113 
2114  content = buf.release();
2115  new_content = &*content;
2116  }
2117  }
2118 
2119  error = GB_write_autoconv_string(gb_field, new_content);
2120 
2121  if (!allow_loss && !error) {
2122  char *result = GB_read_as_string(gb_field);
2123  dbq_assert(result);
2124 
2125  if (strcmp(new_content, result) != 0) {
2126  error = GBS_global_string("value modified by type conversion\n('%s' -> '%s')", new_content, result);
2127  }
2128  free(result);
2129  }
2130  }
2131  }
2132 
2133  if (error) { // add name of current item to error
2134  const char *name = GBT_read_char_pntr(gb_item, "name");
2135  error = GBS_global_string("Error while writing to %s '%s':\n%s", selector.item_name, name, error);
2136  }
2137  }
2138  }
2139  }
2140 
2142 
2143  free(value);
2144 }
2145 
2147  AW_window_simple *aws = new AW_window_simple;
2148  init_itemType_specific_window(aw_root, aws, query->selector, "WRITE_DB_FIELD_OF_LISTED", "Write field of listed %s", true);
2149  aws->load_xfig("query/write_fields.fig");
2150 
2151  aws->at("close");
2152  aws->callback(AW_POPDOWN);
2153  aws->create_button("CLOSE", "CLOSE", "C");
2154 
2155  aws->at("help");
2156  aws->callback(makeHelpCallback("write_field_list.hlp"));
2157  aws->create_button("HELP", "HELP", "H");
2158 
2160 
2161  aws->at("val");
2162  aws->create_text_field(query->awar_setvalue, 2, 2);
2163 
2164  aws->at("lossy");
2165  aws->label("Allow lossy conversion?");
2166  aws->create_toggle(query->awar_writelossy);
2167 
2168  aws->at("create");
2169  aws->callback(makeWindowCallback(set_field_of_queried_cb, query, false));
2170  aws->create_button("SET_SINGLE_FIELD_OF_LISTED", "WRITE");
2171 
2172  aws->at("do");
2173  aws->callback(makeWindowCallback(set_field_of_queried_cb, query, true));
2174  aws->create_button("APPEND_SINGLE_FIELD_OF_LISTED", "APPEND");
2175 
2176  return aws;
2177 }
2178 
2180  // set protection of listed items
2181  ItemSelector& selector = query->selector;
2182  AW_root *aw_root = query->aws->get_root();
2183  char *key = aw_root->awar(query->awar_protectkey)->read_string();
2184 
2185  if (strcmp(key, NO_FIELD_SELECTED) == 0) {
2186  aw_message("Please select a field for which you want to set the protection");
2187  }
2188  else {
2189  GB_begin_transaction(query->gb_main);
2190 
2191  GB_ERROR error = NULp;
2192  GBDATA *gb_key_data = GB_search(query->gb_main, selector.change_key_path, GB_CREATE_CONTAINER);
2193  GBDATA *gb_key_name = GB_find_string(gb_key_data, CHANGEKEY_NAME, key, GB_IGNORE_CASE, SEARCH_GRANDCHILD);
2194 
2195  if (!gb_key_name) {
2196  error = GBS_global_string("The destination field '%s' does not exists", key);
2197  }
2198  else {
2199  int level = aw_root->awar(query->awar_setprotection)->read_int();
2200  QUERY_RANGE range = (QUERY_RANGE)aw_root->awar(query->awar_where)->read_int();
2201 
2202  for (GBDATA *gb_item_container = selector.get_first_item_container(query->gb_main, aw_root, range);
2203  !error && gb_item_container;
2204  gb_item_container = selector.get_next_item_container(gb_item_container, range))
2205  {
2206  for (GBDATA *gb_item = selector.get_first_item(gb_item_container, QUERY_ALL_ITEMS);
2207  !error && gb_item;
2208  gb_item = selector.get_next_item(gb_item, QUERY_ALL_ITEMS))
2209  {
2210  if (IS_QUERIED(gb_item, query)) {
2211  GBDATA *gb_new = GB_search(gb_item, key, GB_FIND);
2212  if (gb_new) {
2213  error = GB_write_security_delete(gb_new, level);
2214  if (!error) error = GB_write_security_write(gb_new, level);
2215  }
2216  }
2217  }
2218  }
2219  }
2221  }
2222 
2223  free(key);
2224 }
2225 
2227  AW_window_simple *aws = new AW_window_simple;
2228  init_itemType_specific_window(aw_root, aws, query->selector, "SET_PROTECTION_OF_FIELD_OF_LISTED", "Protect field of listed %s", true);
2229  aws->load_xfig("query/set_protection.fig");
2230 
2231  aws->at("close");
2232  aws->callback(AW_POPDOWN);
2233  aws->create_button("CLOSE", "CLOSE", "C");
2234 
2235  aws->at("help");
2236  aws->callback(makeHelpCallback("set_protection.hlp"));
2237  aws->create_button("HELP", "HELP", "H");
2238 
2239 
2240  aws->at("prot");
2241  aws->create_toggle_field(query->awar_setprotection, AW_VERTICAL);
2242  aws->insert_toggle("0 temporary", "0", 0);
2243  aws->insert_toggle("1 checked", "1", 1);
2244  aws->insert_toggle("2", "2", 2);
2245  aws->insert_toggle("3", "3", 3);
2246  aws->insert_toggle("4 normal", "4", 4);
2247  aws->insert_toggle("5 ", "5", 5);
2248  aws->insert_toggle("6 the truth", "5", 6);
2249  aws->update_toggle_field();
2250 
2251  create_itemfield_selection_list(aws, FieldSelDef(query->awar_protectkey, query->gb_main, query->selector, FIELD_UNFILTERED, "field to protect"), "list");
2252 
2253  aws->at("go");
2254  aws->callback(makeWindowCallback(set_protection_of_queried_cb, query));
2255  aws->create_autosize_button("SET_PROTECTION_OF_FIELD_OF_LISTED", "Assign\nprotection\nto field\nof listed");
2256 
2257  return aws;
2258 }
2259 
2260 static void toggle_flag_cb(AW_window *aww, DbQuery *query) {
2261  GB_transaction ta(query->gb_main);
2262  GBDATA *gb_item = query->selector.get_selected_item(query->gb_main, aww->get_root());
2263  if (gb_item) {
2264  long flag = GB_read_flag(gb_item);
2265  GB_write_flag(gb_item, 1-flag);
2266  }
2267  DbQuery_update_list(query);
2268 }
2269 
2270 static void new_selection_made_cb(AW_root *aw_root, const char *awar_selection, DbQuery *query) {
2271  char *item_name = aw_root->awar(awar_selection)->read_as_string();
2272  query->selector.update_item_awars(query->gb_main, aw_root, item_name);
2273  free(item_name);
2274 }
2275 
2277  // this defines what is saved/restored to/from configs
2278  for (int key_id = 0; key_id<QUERY_EXPRESSIONS; ++key_id) {
2279  cdef.add(query->awar_keys[key_id], "key", key_id);
2280  cdef.add(query->awar_queries[key_id], "query", key_id);
2281  cdef.add(query->awar_not[key_id], "not", key_id);
2282  cdef.add(query->awar_operator[key_id], "operator", key_id);
2283  }
2284 }
2285 
2286 template<typename CB>
2287 static void query_rel_menu_entry(AW_window *aws, const char *id, const char *query_id, const char* label, const char *mnemonic, const char *helpText, AW_active Mask, const CB& cb) {
2288  char *rel_id = GBS_global_string_copy("%s_%s", query_id, id);
2289  aws->insert_menu_topic(rel_id, label, mnemonic, helpText, Mask, cb);
2290  free(rel_id);
2291 }
2292 
2293 const char *DbQuery::get_tree_name() const {
2294  if (!awar_tree_name)
2295  return NULp;
2296  else
2297  return aws->get_root()->awar(awar_tree_name)->read_char_pntr();
2298 }
2299 
2301  for (int s = 0; s<QUERY_EXPRESSIONS; ++s) {
2302  free(awar_keys[s]);
2303  free(awar_queries[s]);
2304  free(awar_not[s]);
2305  free(awar_operator[s]);
2306  }
2307 
2308  free(species_name);
2309 
2310  free(awar_writekey);
2311  free(awar_writelossy);
2312  free(awar_protectkey);
2313  free(awar_setprotection);
2314  free(awar_setvalue);
2315 
2316  free(awar_parskey);
2317  free(awar_parsvalue);
2318  free(awar_parspredefined);
2319  free(awar_acceptConvError);
2320  free(awar_acceptIdMod);
2321 
2322  free(awar_ere);
2323  free(awar_where);
2324  free(awar_by);
2325  free(awar_use_tag);
2326  free(awar_double_pars);
2327  free(awar_deftag);
2328  free(awar_tag);
2329  free(awar_count);
2330  free(awar_sort);
2331 
2333 }
2334 
2335 // ----------------------------------------
2336 // store query data until DB close
2337 
2339 template<> void Keeper<DbQuery*>::destroy(DbQuery *q) { delete q; }
2341 static void destroyKeptQueries() {
2342  queryKeeper.setNull();
2343 }
2344 static void keepQuery(GBDATA *gbmain, DbQuery *q) {
2345  if (queryKeeper.isNull()) {
2346  queryKeeper = new QueryKeeper;
2347  GB_atclose_callback(gbmain, makeDatabaseCallback(destroyKeptQueries));
2348  }
2349  queryKeeper->keep(q);
2350 }
2351 
2352 // ----------------------------------------
2353 
2354 DbQuery *QUERY::create_query_box(AW_window *aws, query_spec *awtqs, const char *query_id) {
2355  char buffer[256];
2356  AW_root *aw_root = aws->get_root();
2357  GBDATA *gb_main = awtqs->gb_main;
2358  DbQuery *query = new DbQuery(awtqs->get_queried_itemtype());
2359 
2360  keepQuery(gb_main, query); // transfers ownership of query
2361 
2362  // @@@ set all the things below via ctor!
2363  // @@@ create a copyable object containing everything query_spec and DbQuery have in common -> pass that object to DbQuery-ctor
2364 
2365  query->gb_main = awtqs->gb_main;
2366  query->aws = aws;
2367  query->gb_ref = awtqs->gb_ref;
2369  query->select_bit = awtqs->select_bit;
2370  query->species_name = strdup(awtqs->species_name);
2371 
2372  query->set_tree_awar_name(awtqs->tree_name);
2374 
2375  GB_push_transaction(gb_main);
2376 
2377  // Create query box AWARS
2379 
2380  {
2381  const char *default_key[QUERY_EXPRESSIONS+1] = { "name", "name", "name", NULp };
2382 
2383  for (int key_id = 0; key_id<QUERY_EXPRESSIONS; ++key_id) {
2384  sprintf(buffer, "tmp/dbquery_%s/key_%i", query_id, key_id);
2385  query->awar_keys[key_id] = strdup(buffer);
2386  dbq_assert(default_key[key_id]);
2387  aw_root->awar_string(query->awar_keys[key_id], default_key[key_id], AW_ROOT_DEFAULT);
2388 
2389  sprintf(buffer, "tmp/dbquery_%s/query_%i", query_id, key_id);
2390  query->awar_queries[key_id] = strdup(buffer);
2391  aw_root->awar_string(query->awar_queries[key_id], "*", AW_ROOT_DEFAULT);
2392 
2393  sprintf(buffer, "tmp/dbquery_%s/not_%i", query_id, key_id);
2394  query->awar_not[key_id] = strdup(buffer);
2395  aw_root->awar_int(query->awar_not[key_id], 0, AW_ROOT_DEFAULT);
2396 
2397  sprintf(buffer, "tmp/dbquery_%s/operator_%i", query_id, key_id);
2398  query->awar_operator[key_id] = strdup(buffer);
2399  aw_root->awar_string(query->awar_operator[key_id], "ign", AW_ROOT_DEFAULT);
2400  }
2401  aw_root->awar(query->awar_keys[0])->add_callback(makeRootCallback(first_searchkey_changed_cb, query));
2402  }
2403 
2404  sprintf(buffer, "tmp/dbquery_%s/ere", query_id);
2405  query->awar_ere = strdup(buffer);
2406  aw_root->awar_int(query->awar_ere, QUERY_GENERATE);
2407 
2408  sprintf(buffer, "tmp/dbquery_%s/where", query_id);
2409  query->awar_where = strdup(buffer);
2410  aw_root->awar_int(query->awar_where, QUERY_ALL_ITEMS);
2411 
2412  sprintf(buffer, "tmp/dbquery_%s/count", query_id);
2413  query->awar_count = strdup(buffer);
2414  aw_root->awar_int(query->awar_count, 0);
2415 
2416  sprintf(buffer, "tmp/dbquery_%s/sort", query_id);
2417  query->awar_sort = strdup(buffer);
2418  aw_root->awar_int(query->awar_sort, QUERY_SORT_NONE)->add_callback(makeRootCallback(result_sort_order_changed_cb, query));
2419  query->sort_mask = QUERY_SORT_NONE; // default to unsorted
2420 
2421  sprintf(buffer, "tmp/dbquery_%s/by", query_id);
2422  query->awar_by = strdup(buffer);
2423  aw_root->awar_int(query->awar_by, QUERY_MATCH);
2424 
2425  if (awtqs->ere_pos_fig) {
2426  aws->at(awtqs->ere_pos_fig);
2427  aws->create_toggle_field(query->awar_ere);
2428 
2429  aws->insert_toggle(GBS_global_string("Search %s", query->selector.items_name), "G", (int)QUERY_GENERATE);
2430  aws->insert_toggle(GBS_global_string("Add %s", query->selector.items_name), "E", (int)QUERY_ENLARGE);
2431  aws->insert_toggle(GBS_global_string("Keep %s", query->selector.items_name), "R", (int)QUERY_REDUCE);
2432 
2433  aws->update_toggle_field();
2434  }
2435  if (awtqs->where_pos_fig) {
2436  aws->at(awtqs->where_pos_fig);
2437  aws->create_toggle_field(query->awar_where);
2438  aws->insert_toggle("of current organism", "C", (int)QUERY_CURRENT_ITEM);
2439  aws->insert_toggle("of marked organisms", "M", (int)QUERY_MARKED_ITEMS);
2440  aws->insert_toggle("of all organisms", "A", (int)QUERY_ALL_ITEMS);
2441  aws->update_toggle_field();
2442 
2443  }
2444  if (awtqs->by_pos_fig) {
2445  aws->at(awtqs->by_pos_fig);
2446  aws->create_toggle_field(query->awar_by);
2447  aws->insert_toggle("that match the query", "M", (int)QUERY_MATCH);
2448  aws->insert_toggle("that don't match the q.", "D", (int)QUERY_DONT_MATCH);
2449  aws->insert_toggle("that are marked", "A", (int)QUERY_MARKED);
2450  aws->update_toggle_field();
2451  }
2452 
2453  // distances for multiple queries :
2454 
2455 #define KEY_Y_OFFSET 32
2456 
2457  int xpos_calc[3] = { -1, -1, -1 }; // X-positions for elements in search expressions
2458 
2459  if (awtqs->qbox_pos_fig) {
2460  aws->auto_space(1, 1);
2461  aws->at(awtqs->qbox_pos_fig);
2462 
2464 
2465  int xpos, ypos;
2466  aws->get_at_position(&xpos, &ypos);
2467 
2468  int ypos_dummy;
2469 
2470  for (int key = QUERY_EXPRESSIONS-1; key >= 0; --key) {
2471  if (key) {
2472  aws->at(xpos, ypos+key*KEY_Y_OFFSET);
2473  aws->create_option_menu(query->awar_operator[key]);
2474  aws->insert_option("and", "", "and");
2475  aws->insert_option("or", "", "or");
2476  aws->insert_option("ign", "", "ign");
2477  aws->update_option_menu();
2478 
2479  if (xpos_calc[0] == -1) aws->get_at_position(&xpos_calc[0], &ypos_dummy);
2480  }
2481 
2482  aws->at(xpos_calc[0], ypos+key*KEY_Y_OFFSET);
2483  aws->restore_at_from(*at_size);
2484 
2486 
2487  if (xpos_calc[1] == -1) aws->get_at_position(&xpos_calc[1], &ypos_dummy);
2488 
2489  aws->at(xpos_calc[1], ypos+key*KEY_Y_OFFSET);
2490  aws->create_toggle(query->awar_not[key], "#equal.xpm", "#notEqual.xpm");
2491 
2492  if (xpos_calc[2] == -1) aws->get_at_position(&xpos_calc[2], &ypos_dummy);
2493  }
2494  }
2495  if (awtqs->key_pos_fig) {
2496  aws->at(awtqs->key_pos_fig);
2497  aws->create_input_field(query->awar_keys[0], 12);
2498  }
2499 
2500  if (awtqs->query_pos_fig) {
2501  aws->at(awtqs->query_pos_fig);
2502 
2504 
2505  int xpos, ypos;
2506  aws->get_at_position(&xpos, &ypos);
2507 
2508  for (int key = 0; key<QUERY_EXPRESSIONS; ++key) {
2509  aws->at(xpos_calc[2], ypos+key*KEY_Y_OFFSET);
2510  aws->restore_at_from(*at_size);
2511  aws->d_callback(makeWindowCallback(perform_query_cb, query, EXT_QUERY_NONE)); // enable ENTER in searchfield to start search
2512  aws->create_input_field(query->awar_queries[key], 12);
2513  }
2514  }
2515 
2516  if (awtqs->result_pos_fig) {
2517  aws->at(awtqs->result_pos_fig);
2518  aws->d_callback(makeWindowCallback(toggle_flag_cb, query));
2519 
2520  {
2521  const char *this_awar_name = ARB_keep_string(GBS_global_string_copy("tmp/dbquery_%s/select", query_id)); // do not free this cause it's passed to new_selection_made_cb
2522  AW_awar *awar = aw_root->awar_string(this_awar_name, "", AW_ROOT_DEFAULT);
2523 
2524  query->hitlist = aws->create_selection_list(this_awar_name, 5, 5);
2525  awar->add_callback(makeRootCallback(new_selection_made_cb, this_awar_name, query));
2526  }
2527  query->hitlist->insert_default("end of list", "");
2528  query->hitlist->update();
2529  }
2530 
2531  if (awtqs->count_pos_fig) {
2532  aws->button_length(13);
2533  aws->at(awtqs->count_pos_fig);
2534  aws->label("Hits:");
2535  aws->create_button(NULp, query->awar_count, NULp, "+");
2536 
2537  if (awtqs->popup_info_window) {
2539  aws->create_button("popinfo", "Info");
2540  }
2541  }
2542  else {
2543  dbq_assert(!awtqs->popup_info_window); // dont know where to display
2544  }
2545 
2546  if (awtqs->config_pos_fig) {
2547  aws->button_length(0);
2548  aws->at(awtqs->config_pos_fig);
2549  char *macro_id = GBS_global_string_copy("SAVELOAD_CONFIG_%s", query_id);
2550  AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "query_box", makeConfigSetupCallback(query_box_setup_config, query), macro_id);
2551  free(macro_id);
2552  }
2553 
2554  aws->button_length(18);
2555 
2556  if (awtqs->do_query_pos_fig) {
2557  aws->at(awtqs->do_query_pos_fig);
2558  aws->callback(makeWindowCallback(perform_query_cb, query, EXT_QUERY_NONE));
2559  char *macro_id = GBS_global_string_copy("SEARCH_%s", query_id);
2560  aws->create_button(macro_id, "Search", "S", "+");
2561  free(macro_id);
2562  }
2563  if (awtqs->do_refresh_pos_fig) {
2564  aws->at(awtqs->do_refresh_pos_fig);
2565  aws->create_option_menu(query->awar_sort);
2566  aws->insert_default_option("unsorted", "u", QUERY_SORT_NONE);
2567  aws->insert_option ("by value", "v", QUERY_SORT_BY_1STFIELD_CONTENT);
2568  aws->insert_option ("by number", "n", QUERY_SORT_NUM_BY_1STFIELD_CONTENT);
2569  aws->insert_option ("by id", "i", QUERY_SORT_BY_ID);
2570  if (query->selector.parent_selector) {
2571  aws->insert_option ("by parent", "p", QUERY_SORT_BY_NESTED_PID);
2572  }
2573  aws->insert_option ("by marked", "m", QUERY_SORT_BY_MARKED);
2574  aws->insert_option ("by hit", "h", QUERY_SORT_BY_HIT_DESCRIPTION);
2575  aws->insert_option ("reverse", "r", QUERY_SORT_REVERSE);
2576  aws->update_option_menu();
2577  }
2578  else {
2579  dbq_assert(0); // hmm - no sort button here. -> tell ralf where this happens
2580  }
2581 
2582  if (awtqs->do_mark_pos_fig) {
2583  aws->at(awtqs->do_mark_pos_fig);
2584  aws->help_text("mark_list.hlp");
2585  aws->callback(makeWindowCallback(mark_queried_cb, query, 1));
2586  aws->create_button("MARK_LISTED_UNMARK_REST", "Mark Listed\nUnmark Rest", "M");
2587  }
2588  if (awtqs->do_unmark_pos_fig) {
2589  aws->at(awtqs->do_unmark_pos_fig);
2590  aws->help_text("unmark_list.hlp");
2591  aws->callback(makeWindowCallback(mark_queried_cb, query, 0));
2592  aws->create_button("UNMARK_LISTED_MARK_REST", "Unmark Listed\nMark Rest", "U");
2593  }
2594  if (awtqs->do_delete_pos_fig) {
2595  aws->at(awtqs->do_delete_pos_fig);
2596  aws->help_text("del_list.hlp");
2597  aws->callback(makeWindowCallback(delete_queried_species_cb, query));
2598  char *macro_id = GBS_global_string_copy("DELETE_LISTED_%s", query_id);
2599  aws->create_button(macro_id, "Delete Listed", "D");
2600  free(macro_id);
2601  }
2602  if (awtqs->do_set_pos_fig) {
2603  query->awar_writekey = GBS_global_string_copy("tmp/dbquery_%s/write_key", query_id); aw_root->awar_string(query->awar_writekey);
2604  query->awar_writelossy = GBS_global_string_copy("tmp/dbquery_%s/write_lossy", query_id); aw_root->awar_int (query->awar_writelossy);
2605  query->awar_protectkey = GBS_global_string_copy("tmp/dbquery_%s/protect_key", query_id); aw_root->awar_string(query->awar_protectkey);
2606  query->awar_setprotection = GBS_global_string_copy("tmp/dbquery_%s/set_protection", query_id); aw_root->awar_int (query->awar_setprotection, 4);
2607  query->awar_setvalue = GBS_global_string_copy("tmp/dbquery_%s/set_value", query_id); aw_root->awar_string(query->awar_setvalue);
2608 
2609  aws->at(awtqs->do_set_pos_fig);
2610  aws->help_text("mod_field_list.hlp");
2611  aws->callback(makeCreateWindowCallback(create_writeFieldOfListed_window, query));
2612  char *macro_id = GBS_global_string_copy("WRITE_TO_FIELDS_OF_LISTED_%s", query_id);
2613  aws->create_button(macro_id, "Write to Fields\nof Listed", "S");
2614  free(macro_id);
2615  }
2616 
2617  char *Items = strdup(query->selector.items_name);
2618  Items[0] = toupper(Items[0]);
2619 
2620  if ((awtqs->use_menu || awtqs->open_parser_pos_fig)) {
2621  sprintf(buffer, "tmp/dbquery_%s/tag", query_id); query->awar_tag = strdup(buffer); aw_root->awar_string(query->awar_tag);
2622  sprintf(buffer, "tmp/dbquery_%s/use_tag", query_id); query->awar_use_tag = strdup(buffer); aw_root->awar_int (query->awar_use_tag);
2623  sprintf(buffer, "tmp/dbquery_%s/deftag", query_id); query->awar_deftag = strdup(buffer); aw_root->awar_string(query->awar_deftag);
2624  sprintf(buffer, "tmp/dbquery_%s/double_pars", query_id); query->awar_double_pars = strdup(buffer); aw_root->awar_int (query->awar_double_pars);
2625  sprintf(buffer, "tmp/dbquery_%s/parskey", query_id); query->awar_parskey = strdup(buffer); aw_root->awar_string(query->awar_parskey);
2626  sprintf(buffer, "tmp/dbquery_%s/parsvalue", query_id); query->awar_parsvalue = strdup(buffer); aw_root->awar_string(query->awar_parsvalue);
2627  sprintf(buffer, "tmp/dbquery_%s/awar_parspredefined", query_id); query->awar_parspredefined = strdup(buffer); aw_root->awar_string(query->awar_parspredefined);
2628  sprintf(buffer, "tmp/dbquery_%s/acceptConvError", query_id); query->awar_acceptConvError = strdup(buffer); aw_root->awar_int (query->awar_acceptConvError);
2629  sprintf(buffer, "tmp/dbquery_%s/acceptNameMod", query_id); query->awar_acceptIdMod = strdup(buffer); aw_root->awar_int (query->awar_acceptIdMod);
2630 
2631  if (awtqs->use_menu) {
2632  sprintf(buffer, "Modify Fields of Listed %s", Items); query_rel_menu_entry(aws, "mod_fields_of_listed", query_id, buffer, "F", "mod_field_list.hlp", AWM_ALL, makeCreateWindowCallback(create_modify_fields_window, query));
2633  }
2634  else {
2635  aws->at(awtqs->open_parser_pos_fig);
2636  aws->callback(makeCreateWindowCallback(create_modify_fields_window, query));
2637  aws->create_button("MODIFY_FIELDS_OF_LISTED", "MODIFY FIELDS\nOF LISTED", "F");
2638  }
2639  }
2640  if (awtqs->use_menu) {
2641  sprintf(buffer, "Set Protection of Fields of Listed %s", Items); query_rel_menu_entry(aws, "s_prot_of_listed", query_id, buffer, "P", "set_protection.hlp", AWM_ALL, makeCreateWindowCallback(create_set_protection_window, query));
2642  aws->sep______________();
2643  sprintf(buffer, "Mark Listed %s, don't Change Rest", Items); query_rel_menu_entry(aws, "mark_listed", query_id, buffer, "M", "mark.hlp", AWM_ALL, makeWindowCallback(mark_queried_cb, query, 1|8));
2644  sprintf(buffer, "Mark Listed %s, Unmark Rest", Items); query_rel_menu_entry(aws, "mark_listed_unmark_rest", query_id, buffer, "L", "mark.hlp", AWM_ALL, makeWindowCallback(mark_queried_cb, query, 1 ));
2645  sprintf(buffer, "Unmark Listed %s, don't Change Rest", Items); query_rel_menu_entry(aws, "unmark_listed", query_id, buffer, "U", "mark.hlp", AWM_ALL, makeWindowCallback(mark_queried_cb, query, 0|8));
2646  sprintf(buffer, "Unmark Listed %s, Mark Rest", Items); query_rel_menu_entry(aws, "unmark_listed_mark_rest", query_id, buffer, "R", "mark.hlp", AWM_ALL, makeWindowCallback(mark_queried_cb, query, 0 ));
2647  aws->sep______________();
2648 
2649 
2650  sprintf(buffer, "Set Color of Listed %s", Items); query_rel_menu_entry(aws, "set_color_of_listed", query_id, buffer, "C", "set_color_of_listed.hlp", AWM_ALL, makeCreateWindowCallback(create_colorize_queried_window, query));
2651 
2652  if (query->gb_ref) {
2653  dbq_assert(speciesOrOrganism(query->selector.type)); // stuff below works only for species/organisms
2654  aws->sep______________();
2655  if (query->expect_hit_in_ref_list) {
2656  aws->insert_menu_topic("search_equal_fields_and_listed_in_I", "Search entries existing in both DBs and listed in the source DB hitlist", "S",
2657  "search_equal_fields.hlp", AWM_ALL, makeWindowCallback(perform_query_cb, query, EXT_QUERY_COMPARE_LINES));
2658  aws->insert_menu_topic("search_equal_words_and_listed_in_I", "Search words existing in entries of both DBs and listed in the source DB hitlist", "w",
2659  "search_equal_fields.hlp", AWM_ALL, makeWindowCallback(perform_query_cb, query, EXT_QUERY_COMPARE_WORDS));
2660  }
2661  else {
2662  aws->insert_menu_topic("search_equal_field_in_both_db", "Search entries existing in both DBs", "S",
2663  "search_equal_fields.hlp", AWM_ALL, makeWindowCallback(perform_query_cb, query, EXT_QUERY_COMPARE_LINES));
2664  aws->insert_menu_topic("search_equal_word_in_both_db", "Search words existing in entries of both DBs", "w",
2665  "search_equal_fields.hlp", AWM_ALL, makeWindowCallback(perform_query_cb, query, EXT_QUERY_COMPARE_WORDS));
2666  }
2667  }
2668  }
2669 
2670  free(Items);
2671 
2672  GB_pop_transaction(gb_main);
2673  return query;
2674 }
2675 
2676 // --------------------------------------------------------------------------------
2677 
2678 #ifdef UNIT_TESTS
2679 #ifndef TEST_UNIT_H
2680 #include <test_unit.h>
2681 #endif
2682 
2683 void TEST_nullcmp() {
2684  const char *whatever = "bla";
2686  TEST_EXPECT_EQUAL(ARB_strNULLcmp(whatever, whatever), 0);
2687  TEST_EXPECT_EQUAL(ARB_strNULLcmp("a", "b"), -1);
2688 
2689  // document uncommon behavior: NULp is bigger than any other text!
2690  TEST_EXPECT_EQUAL(ARB_strNULLcmp(whatever, NULp), -1);
2691  TEST_EXPECT_EQUAL(ARB_strNULLcmp(NULp, whatever), 1);
2692 }
2693 
2694 #endif // UNIT_TESTS
2695 
2696 // --------------------------------------------------------------------------------
2697 
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
void keep(T elem)
Definition: Keeper.h:32
static void mark_colored_cb(AW_window *aww, BoundItemSel *cmd, mark_mode mode)
Definition: db_query.cxx:1566
void insert_option(AW_label choice_label, const char *mnemonic, const char *var_value, const char *name_of_color=NULp)
static GB_ERROR clear_all_colors(BoundItemSel *bsel, AW_root *aw_root)
Definition: db_query.cxx:1672
#define MAX_QUERY_LIST_LEN
Definition: db_query.cxx:43
const char * GB_ERROR
Definition: arb_core.h:25
const char * get_items_name() const
Definition: db_query.cxx:1609
void get_at_position(int *x, int *y) const
Definition: AW_at.cxx:296
AW_bitset AW_active
Definition: aw_base.hxx:45
const char * item_name
Definition: items.h:66
#define PSEUDO_FIELD_ALL_FIELDS_REC
Definition: item_sel_list.h:30
string result
GB_TYPES type
static void toggle_flag_cb(AW_window *aww, DbQuery *query)
Definition: db_query.cxx:2260
void insert_toggle(AW_label toggle_label, const char *mnemonic, const char *var_value)
GB_ERROR GB_commit_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2551
void set_tree_awar_name(const char *tree_awar_name)
bool GB_TYPE_readable_as_string(GB_TYPES type)
Definition: arbdb.h:90
void button_length(int length)
Definition: AW_at.cxx:288
void add(const char *awar_name, const char *config_name)
const char * getHitInfo(const char *item_id, DbQuery *query)
Definition: db_query.cxx:85
size_t size() const
Definition: arb_strarray.h:85
mark_mode
Definition: db_query.cxx:1560
ItemSelector * parent_selector
Definition: items.h:79
GBDATA * GBT_colorset_root(GBDATA *gb_main, const char *itemsname)
Definition: ad_colorset.cxx:52
void d_callback(const WindowCallback &cb)
Definition: AW_window.cxx:141
static QUERY_RESULT_ORDER find_display_determining_sort_order(QUERY_RESULT_ORDER *order)
Definition: db_query.cxx:217
char * awar_writekey
GBDATA * GB_child(GBDATA *father)
Definition: adquery.cxx:322
char * awar_writelossy
GB_ERROR GB_incur_error()
Definition: arb_msg.h:49
char * awar_parsvalue
static void destroyKeptQueries()
Definition: db_query.cxx:2341
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
Definition: adhash.cxx:454
return string(buffer, length)
const char * config_pos_fig
Definition: db_query.h:61
AwarName species_name
Definition: db_query.h:42
void insert_menu_topic(const char *id, const char *name, const char *mnemonic, const char *help_text_, AW_active mask, const WindowCallback &wcb)
Definition: AW_window.cxx:595
void GB_atclose_callback(GBDATA *gbd, const DatabaseCallback &atClose)
Definition: ad_cb.cxx:458
static GB_ERROR restore_colorset_representation(BoundItemSel *bsel, CharPtrArray &colordefs)
Definition: db_query.cxx:1704
static void keepQuery(GBDATA *gbmain, DbQuery *q)
Definition: db_query.cxx:2344
void DbQuery_update_list(DbQuery *query)
Definition: db_query.cxx:482
Definition: AP_filter.hxx:36
void insert_default(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:385
GB_ERROR GB_add_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
Definition: ad_cb.cxx:356
#define DOWNCAST_REFERENCE(totype, expr)
Definition: downcast.h:152
static void iterate(GBDATA *gbd)
const char * key_pos_fig
Definition: db_query.h:53
const char * ARB_keep_string(char *str)
Definition: arb_string.cxx:72
void GB_sort(void **array, size_t first, size_t behind_last, gb_compare_function compare, void *client_data)
Definition: arb_sort.cxx:27
bool GB_readable_as_string(GBDATA *gbd)
Definition: arbdb.cxx:1080
#define PSEUDO_FIELD_ALL_FIELDS
Definition: item_sel_list.h:28
GBDATA * query_get_gb_main(DbQuery *query)
Definition: db_query.cxx:106
loadsave_mode
Definition: db_query.cxx:1745
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2561
void at(int x, int y)
Definition: AW_at.cxx:93
static void set_protection_of_queried_cb(AW_window *, DbQuery *query)
Definition: db_query.cxx:2179
static void detectMaxNameLength(const char *key, long, void *cl_len)
Definition: db_query.cxx:459
const char * ere_pos_fig
Definition: db_query.h:48
static void create_colorset_representation(BoundItemSel *bsel, AW_root *aw_root, StrArray &colordefs, GB_ERROR &error)
Definition: db_query.cxx:1642
#define AW_COLOR_GROUPS
void copy_selection_list_2_query_box(DbQuery *query, AW_selection_list *srclist, const char *hit_description)
Definition: db_query.cxx:1127
const char * where_pos_fig
Definition: db_query.h:49
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)
void GB_end_transaction_show_error(GBDATA *gbd, GB_ERROR error, void(*error_handler)(GB_ERROR))
Definition: arbdb.cxx:2584
char * GB_read_as_string(GBDATA *gbd)
Definition: arbdb.cxx:1060
void CLEAR_QUERIED(GBDATA *gb_species, DbQuery *query)
Definition: db_query.cxx:77
static GB_HASH * create_ref_hash(const DbQuery *query, const char *key, bool split_words)
Definition: db_query.cxx:677
long read_int() const
Definition: AW_awar.cxx:184
GBDATA *(* get_parent)(GBDATA *gb_item)
Definition: items.h:80
bool iterate() const OVERRIDE
Definition: db_query.cxx:857
GBDATA * get_first_field(GBDATA *gb_item) const
Definition: db_query.cxx:870
size_t GBS_shorten_repeated_data(char *data)
Definition: adstring.cxx:357
#define QUERY_EXPRESSIONS
DbQuery * create_query_box(AW_window *aws, query_spec *awtqs, const char *query_id)
Definition: db_query.cxx:2354
GBDATA * GBT_find_or_create_colorset(GBDATA *gb_colorset_root, const char *name)
Definition: ad_colorset.cxx:85
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
static int query_count_items(DbQuery *query, QUERY_RANGE range, QUERY_MODES mode)
Definition: db_query.cxx:180
const char * result_pos_fig
Definition: db_query.h:57
void AW_advice(const char *message, AW_Advice_Type type, const char *title, const char *corresponding_help)
Show a message box with an advice for the user.
Definition: AW_advice.cxx:160
GB_HASH * GBS_create_dynaval_hash(long estimated_elements, GB_CASE case_sens, void(*freefun)(long))
Definition: adhash.cxx:271
GBDATA * get_colorset_root(BoundItemSel *bsel)
Definition: db_query.cxx:1616
bool GB_have_error()
Definition: arb_msg.cxx:338
STL namespace.
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
void unquery_all(void *dummy, DbQuery *query)
Definition: db_query.cxx:617
char * release()
Definition: arb_strbuf.h:129
void GBS_free_hash(GB_HASH *hs)
Definition: adhash.cxx:538
static void result_sort_order_changed_cb(AW_root *aw_root, DbQuery *query)
Definition: db_query.cxx:265
#define KEY_Y_OFFSET
bool isNull() const
test if SmartPtr is NULp
Definition: smartptr.h:248
static SmartPtr< QueryKeeper > queryKeeper
Definition: db_query.cxx:2340
char * awar_acceptConvError
char * awar_keys[QUERY_EXPRESSIONS]
GB_TYPES first_type
Definition: db_query.cxx:300
static void modify_fields_of_queried_cb(AW_window *, DbQuery *query)
Definition: db_query.cxx:1346
query_operator awarvalue2query_operator(const char *awarvalue)
Definition: db_query.cxx:891
long count_queried_items(DbQuery *query, QUERY_RANGE range)
Definition: db_query.cxx:159
const char * open_parser_pos_fig
Definition: db_query.h:66
const int MAX_CRITERIA
Definition: db_query.cxx:204
ItemQueryKey(GBDATA *gb_main, const char *field_name)
Definition: db_query.cxx:751
void setNull()
set SmartPtr to NULp
Definition: smartptr.h:251
const char * get_tree_name() const
Definition: db_query.cxx:2293
char buffer[MESSAGE_BUFFERSIZE]
Definition: seq_search.cxx:34
GBDATA * GB_get_father(GBDATA *gbd)
Definition: arbdb.cxx:1722
void update_option_menu()
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2494
bool SLOW_is_pseudo_key(const char *key)
Definition: db_query.cxx:467
int ARB_strNULLcmp(const char *s1, const char *s2)
Definition: arb_str.h:52
EXT_QUERY_TYPES
Definition: db_query.cxx:114
bool empty() const
Definition: arb_strarray.h:86
#define cb(action)
bool speciesOrOrganism(QUERY_ITEM_TYPE type)
Definition: items.h:37
#define NO_FIELD_SELECTED
void update_toggle_field()
GB_ERROR GB_incur_error_if(bool error_may_occur)
Definition: arb_msg.h:56
static void loadsave_colorset_cb(AW_window *aws, BoundItemSel *bsel, loadsave_mode mode)
Definition: db_query.cxx:1752
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:231
GB_ERROR GB_delete(GBDATA *&source)
Definition: arbdb.cxx:1916
void insert(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:380
char * GBS_modify_tagged_string_with_ACI(const char *s, const char *dt, const char *tag, const char *aci, GBL_call_env &env)
Definition: adstring.cxx:747
void create_itemfield_selection_button(AW_window *aws, const FieldSelDef &selDef, const char *at)
TargetItem(const DbQuery &query)
Definition: db_query.cxx:711
NOT4PERL float * GBT_read_float(GBDATA *gb_container, const char *fieldpath)
Definition: adtools.cxx:349
void GB_raise_user_flag(GBDATA *gbd, unsigned char user_bit)
Definition: arbdb.cxx:2755
static AW_window * create_writeFieldOfListed_window(AW_root *aw_root, DbQuery *query)
Definition: db_query.cxx:2146
static void colorset_changed_cb(GBDATA *, const color_save_data *csd, GB_CB_TYPE cbt)
Definition: db_query.cxx:1636
const char * read_char_pntr() const
Definition: AW_awar.cxx:168
char * get_target_data(const QueryTarget &target, GB_ERROR &error) const OVERRIDE
Definition: db_query.cxx:772
bool GB_user_flag(GBDATA *gbd, unsigned char user_bit)
Definition: arbdb.cxx:2750
QUERY_RESULT_ORDER order[MAX_CRITERIA]
Definition: db_query.cxx:301
GB_ERROR GB_export_error(const char *error)
Definition: arb_msg.cxx:257
char * awar_setprotection
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:342
static void first_searchkey_changed_cb(AW_root *, DbQuery *query)
Definition: db_query.cxx:248
NOT4PERL long * GBT_read_int(GBDATA *gb_container, const char *fieldpath)
Definition: adtools.cxx:327
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
Definition: arbdb.h:67
Definition: arbdb.h:78
GB_TYPES GB_read_type(GBDATA *gbd)
Definition: arbdb.cxx:1643
void create_toggle_field(const char *awar_name, AW_label label, AW_orientation orientation=AW_VERTICAL)
static AW_window * create_colorize_queried_window(AW_root *aw_root, DbQuery *query)
Definition: db_query.cxx:1959
GB_HASH * hit_description
GB_CSTR GB_read_key_pntr(GBDATA *gbd)
Definition: arbdb.cxx:1656
bool expect_hit_in_ref_list
QUERY_RESULT_ORDER
GB_HASH * to_hash(bool case_sens)
Definition: AW_select.cxx:532
#define PSEUDO_FIELD_ANY_FIELD
Definition: item_sel_list.h:27
GBDATA * get_item() const
Definition: db_query.cxx:720
char * awar_setvalue
GBDATA * gb_species_data
Definition: adname.cxx:33
long GB_number_of_subentries(GBDATA *gbd)
Definition: arbdb.cxx:2892
bool is_pseudo_key(const char *key)
Definition: db_query.cxx:475
const char * GB_first_non_key_char(const char *str)
Definition: adquery.cxx:416
ItemSelector & get_queried_itemtype(DbQuery *query)
Definition: db_query.cxx:110
void GBS_hash_do_const_loop(const GB_HASH *hs, gb_hash_const_loop_type func, void *client_data)
Definition: adhash.cxx:559
GBDATA * gb_ref
Definition: db_query.h:40
int GBT_get_color_group(GBDATA *gb_item)
Definition: ad_colorset.cxx:16
const char * change_key_path
Definition: items.h:65
void init_itemType_specific_window(AW_root *aw_root, class AW_window_simple *aws, const ItemSelector &itemType, const char *id, const char *title_format, bool plural=false)
Definition: itemtools.cxx:33
GBDATA *(* get_selected_item)(GBDATA *gb_main, AW_root *aw_root)
Definition: items.h:76
void aimTo(GBDATA *gb_next_item)
Definition: db_query.cxx:716
string keptHitReason(const string &currentHitReason, GBDATA *gb_item, DbQuery *query)
Definition: db_query.cxx:95
ItemSelector & selector
Definition: items.h:87
int numeric_string_cmp(const char *str1, const char *str2)
Definition: db_query.cxx:315
AW_selection_list * hitlist
static AW_window * create_set_protection_window(AW_root *aw_root, DbQuery *query)
Definition: db_query.cxx:2226
FailIfField
#define false
Definition: ureadseq.h:13
BoundItemSel * bsel
Definition: db_query.cxx:1606
GBDATA * gb_main
GBDATA * get_ACI_item() const OVERRIDE
Definition: db_query.cxx:726
AW_window * aws
CONSTEXPR_INLINE int float_cmp(const float f1, const float f2)
Definition: arbtools.h:192
const char * qbox_pos_fig
Definition: db_query.h:52
void help_text(const char *id)
Definition: AW_window.cxx:116
static char const * macro_name
Definition: mkptypes.cxx:81
DbQuery * query
Definition: db_query.cxx:298
GBDATA *(* get_first_item_container)(GBDATA *, AW_root *, QUERY_RANGE)
Definition: items.h:70
static void error(const char *msg)
Definition: mkptypes.cxx:96
GBDATA *(* get_next_item_container)(GBDATA *, QUERY_RANGE)
Definition: items.h:71
GB_ERROR GB_abort_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2539
void reset() const OVERRIDE
Definition: db_query.cxx:862
void(* trigger_display_refresh)()
Definition: items.h:82
const char * mnemonic
void restore_at_from(const AW_at_storage &stored)
Definition: aw_window.hxx:555
fputc('\n', stderr)
query_key_type
Definition: query_expr.h:81
static void new_selection_made_cb(AW_root *aw_root, const char *awar_selection, DbQuery *query)
Definition: db_query.cxx:2270
ItemSelector & selector
static void colorize_marked_cb(AW_window *aww, BoundItemSel *cmd)
Definition: db_query.cxx:1535
char * awar_operator[QUERY_EXPRESSIONS]
GBQUARK GB_find_or_create_quark(GBDATA *gbd, const char *key)
Definition: arbdb.cxx:1695
#define CHANGEKEY_NAME
Definition: arbdbt.h:91
static void delete_queried_species_cb(AW_window *, DbQuery *query)
Definition: db_query.cxx:629
void label(const char *label)
Definition: AW_window.cxx:102
char * str
Definition: defines.h:20
size_t GBS_hash_elements(const GB_HASH *hs)
Definition: adhash.cxx:570
char * read_as_string() const
GB_ERROR GBT_save_colorset(GBDATA *gb_colorset, CharPtrArray &colorsetDefs)
const char * items_name
Definition: items.h:67
#define MAX_SHOWN_DATA_SIZE
Definition: query_expr.h:62
static void colorize_queried_cb(AW_window *, DbQuery *query)
Definition: db_query.cxx:1507
GB_ERROR GBT_load_colorset(GBDATA *gb_colorset, ConstStrArray &colorsetDefs)
Definition: ad_colorset.cxx:94
const char * count_pos_fig
Definition: db_query.h:58
GBDATA * GB_find_sub_by_quark(GBDATA *father, GBQUARK key_quark, GBDATA *after, size_t skip_over)
Definition: adquery.cxx:174
static AW_window * create_colorize_window(AW_root *aw_root, GBDATA *gb_main, DbQuery *query, ItemSelector *sel)
Definition: db_query.cxx:1862
int item_name_length
Definition: items.h:63
#define cmp(h1, h2)
Definition: admap.cxx:50
static void free_hit_description(long info)
Definition: db_query.cxx:47
#define AWAR_COLOR_LOADSAVE_NAME
Definition: db_query.cxx:1614
const char * by_pos_fig
Definition: db_query.h:50
const char * prepare_and_get_selected_itemfield(AW_root *awr, const char *awar_name, GBDATA *gb_main, const ItemSelector &itemtype, FailIfField failIf)
int GB_read_flag(GBDATA *gbd)
Definition: arbdb.cxx:2796
char *(* generate_item_id)(GBDATA *gb_main, GBDATA *gb_item)
Definition: items.h:59
char * read_string() const
Definition: AW_awar.cxx:198
static void create_query_independent_awars(AW_root *aw_root, AW_default aw_def)
Definition: db_query.cxx:102
GB_ERROR GB_write_security_write(GBDATA *gbd, unsigned long level)
Definition: arbdb.cxx:1584
static WindowCallback simple(void(*root_cb)(AW_root *, T), T t)
Definition: rootAsWin.h:47
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
GB_ERROR GB_pop_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2524
GB_TYPES GBT_get_type_of_changekey(GBDATA *gb_main, const char *field_name, const char *change_key_path)
Definition: adChangeKey.cxx:33
AW_selection_list * colorsets
Definition: db_query.cxx:1607
bool expect_hit_in_ref_list
Definition: db_query.h:41
Definition: arbdb.h:86
#define AWAR_COLORIZE
Definition: db_query.cxx:45
GBDATA *(* get_first_item)(GBDATA *, QUERY_RANGE)
Definition: items.h:73
void search_duplicated_field_content(AW_window *dummy, DbQuery *query, bool tokenize)
Definition: db_query.cxx:1191
char * awar_parspredefined
static void clear_all_colors_cb(AW_window *aww, BoundItemSel *bsel)
Definition: db_query.cxx:1694
void append(QueryExpr *&tail)
Definition: query_expr.cxx:46
Definition: db_query.h:24
static AW_at_storage * make(AW_window *aww, AW_at_storage_type type)
Definition: AW_at.cxx:449
AW_selection_list * awt_create_selection_list_with_input_field(AW_window *aww, const char *awar_name, const char *at_box, const char *at_field)
void insert_default_option(AW_label choice_label, const char *mnemonic, const char *var_value, const char *name_of_color=NULp)
QUERY_RANGE
Definition: items.h:41
char * awar_not[QUERY_EXPRESSIONS]
static void query_rel_menu_entry(AW_window *aws, const char *id, const char *query_id, const char *label, const char *mnemonic, const char *helpText, AW_active Mask, const CB &cb)
Definition: db_query.cxx:2287
TYPE get_type() const
Definition: probe_tree.h:64
QUERY_ITEM_TYPE
Definition: items.h:27
long int flag
Definition: f2c.h:39
GBDATA * GBT_searchOrCreate_itemfield_according_to_changekey(GBDATA *gb_item, const char *field_name, const char *change_key_path)
Definition: adChangeKey.cxx:61
GBDATA *(* get_next_item)(GBDATA *, QUERY_RANGE)
Definition: items.h:74
SmartPtr< QueryExpr > buildQueryExpr()
Definition: db_query.cxx:897
static void remove_keydependent_sort_criteria(QUERY_RESULT_ORDER *order)
Definition: db_query.cxx:234
bool aw_ask_sure(const char *unique_id, const char *msg)
void(* update_item_awars)(GBDATA *gb_main, AW_root *aw_root, const char *item_name)
Definition: items.h:58
static void split_sort_mask(unsigned long sort_mask, QUERY_RESULT_ORDER *order)
Definition: db_query.cxx:206
TokLPtr tokenize(const std::string &description, TokLPtr tokenLP)
void create_input_field(const char *awar_name, int columns=0)
Definition: AW_button.cxx:857
const char * get_name() const OVERRIDE
Definition: db_query.cxx:798
fputs(TRACE_PREFIX, stderr)
static void setup_modify_fields_config(AWT_config_definition &cdef, const DbQuery *query)
Definition: db_query.cxx:1967
AW_window * create_colorize_items_window(AW_root *aw_root, GBDATA *gb_main, ItemSelector &sel)
Definition: db_query.cxx:1963
void ncat(const char *from, size_t count)
Definition: arb_strbuf.h:173
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
TYPE * ARB_calloc(size_t nelem)
Definition: arb_mem.h:81
void auto_space(int xspace, int yspace)
Definition: AW_at.cxx:259
static void query_box_setup_config(AWT_config_definition &cdef, DbQuery *query)
Definition: db_query.cxx:2276
popup_info_window_cb popup_info_window
Definition: db_query.h:69
#define gb_assert(cond)
Definition: arbdbt.h:11
xml element
GB_ERROR close(GB_ERROR error)
Definition: arbdbpp.cxx:35
void GB_write_flag(GBDATA *gbd, long flag)
Definition: arbdb.cxx:2773
void SET_QUERIED(GBDATA *gb_species, DbQuery *query, const char *hitInfo, size_t hitInfoLen=0)
Definition: db_query.cxx:51
#define QUERY_SORT_CRITERIA_MASK
#define OVERRIDE
Definition: cxxforward.h:110
const char * do_mark_pos_fig
Definition: db_query.h:62
bool IS_QUERIED(GBDATA *gb_item, const query_spec *aqs)
Definition: db_query.h:84
Itemfield_Selection * create_itemfield_selection_list(AW_window *aws, const FieldSelDef &selDef, const char *at)
GB_ERROR GB_failedTo_error(const char *do_something, const char *special, GB_ERROR error)
Definition: arb_msg.cxx:375
bool matches(const QueryTarget &target, std::string &hit_reason) const
Definition: query_expr.cxx:277
unsigned long sort_mask
AW_selection_list * create_selection_list(const char *awar_name, int columns, int rows)
Definition: AW_button.cxx:1215
char * AW_get_color_group_name(AW_root *awr, int color_group)
Definition: AW_preset.cxx:1173
#define QUERY_SORT_CRITERIA_BITS
GBDATA * GBT_first_species(GBDATA *gb_main)
Definition: aditem.cxx:124
char * GBT_read_as_string(GBDATA *gb_container, const char *fieldpath)
Definition: adtools.cxx:290
GBDATA * gb_main
Definition: items.h:86
query_operator
Definition: query_expr.h:64
GB_ERROR GB_write_security_delete(GBDATA *gbd, unsigned long level)
Definition: arbdb.cxx:1605
GB_CSTR GB_concat_path_in_ARBLIB(const char *relative_path_left, const char *anypath_right)
Definition: adsocket.cxx:1159
static void update_colorset_selection_list(const color_save_data *csd)
Definition: db_query.cxx:1620
void negate()
Definition: query_expr.cxx:56
const char * query_pos_fig
Definition: db_query.h:54
const char * GB_get_db_path(GBDATA *gbd)
Definition: adTest.cxx:14
#define dbq_assert(cond)
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
const char * do_query_pos_fig
Definition: db_query.h:60
AW_option_menu_struct * create_option_menu(const char *awar_name)
GBDATA * GBT_find_colorset(GBDATA *gb_colorset_root, const char *name)
Definition: ad_colorset.cxx:76
void GB_clear_user_flag(GBDATA *gbd, unsigned char user_bit)
Definition: arbdb.cxx:2760
Definition: Keeper.h:19
GBDATA * GB_find_string(GBDATA *gbd, const char *key, const char *str, GB_CASE case_sens, GB_SEARCH_TYPE gbs)
Definition: adquery.cxx:302
query_key_type get_key_type() const
Definition: query_expr.h:200
AW_root * get_root()
Definition: aw_window.hxx:354
Keeper< DbQuery * > QueryKeeper
Definition: db_query.cxx:2338
static int compare_hits(const void *cl_item1, const void *cl_item2, void *cl_param)
Definition: db_query.cxx:346
static int line
Definition: arb_a2ps.c:296
GBDATA * GBT_next_species(GBDATA *gb_species)
Definition: aditem.cxx:128
#define NULp
Definition: cxxforward.h:114
GBDATA *(* find_item_by_id)(GBDATA *gb_main, const char *id)
Definition: items.h:60
GB_ERROR getError(int count=0) const
Definition: query_expr.cxx:77
GB_ERROR write_string(const char *aw_string)
static char * command
Definition: arb_a2ps.c:319
char * awar_acceptIdMod
char * GBT_get_default_alignment(GBDATA *gb_main)
Definition: adali.cxx:747
void sep______________()
Definition: AW_window.cxx:753
#define GB_USERFLAG_QUERY
Definition: arbdb.h:55
static void predef_prg(AW_root *aw_root, DbQuery *query)
Definition: db_query.cxx:1480
NOT4PERL char * GB_command_interpreter_in_env(const char *str, const char *commands, const GBL_call_env &callEnv)
Definition: gb_aci.cxx:361
GB_TYPES
Definition: arbdb.h:62
GBDATA * GB_nextChild(GBDATA *child)
Definition: adquery.cxx:326
bool keep_criteria(QUERY_RESULT_ORDER old_criteria, QUERY_RESULT_ORDER new_criteria)
Definition: db_query.cxx:258
void GBT_get_colorset_names(ConstStrArray &colorsetNames, GBDATA *gb_colorset_root)
Definition: ad_colorset.cxx:62
long GBT_get_species_count(GBDATA *gb_main)
Definition: aditem.cxx:207
static void perform_query_cb(AW_window *, DbQuery *query, EXT_QUERY_TYPES ext_query)
Definition: db_query.cxx:926
GB_ERROR load(const char *filemask, bool append) const
char * awar_protectkey
GB_transaction ta(gb_var)
void callback(const WindowCallback &cb)
Definition: AW_window.cxx:133
void setError(GB_ERROR error_) const
Definition: query_expr.h:210
GBDATA * gb_main
Definition: db_query.h:39
GBDATA * gb_main
Definition: adname.cxx:32
hits_sort_params(DbQuery *q, const char *fk)
Definition: db_query.cxx:303
ItemSelector & get_queried_itemtype() const
Definition: db_query.h:37
bool is_queried(GBDATA *gb_item) const
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
GB_ERROR GBT_set_color_group(GBDATA *gb_item, int color_group)
Definition: ad_colorset.cxx:31
QueryKey & get_key()
Definition: query_expr.h:202
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
Definition: aditem.cxx:459
static AW_window * create_modify_fields_window(AW_root *aw_root, DbQuery *query)
Definition: db_query.cxx:1982
const char * do_set_pos_fig
Definition: db_query.h:65
GB_CB_TYPE
Definition: arbdb_base.h:46
static int info[maxsites+1]
CONSTEXPR_INLINE int double_cmp(const double d1, const double d2)
Definition: arbtools.h:185
const char * GBT_read_char_pntr(GBDATA *gb_container, const char *fieldpath)
Definition: adtools.cxx:307
bool is_queried(GBDATA *gb_item) const
Definition: db_query.cxx:151
char * awar_double_pars
AwarName tree_name
Definition: db_query.h:43
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
static void set_field_of_queried_cb(AW_window *, DbQuery *query, bool append)
Definition: db_query.cxx:2064
char * awar_queries[QUERY_EXPRESSIONS]
#define TEST_EXPECT_EQUAL(expr, want)
Definition: test_unit.h:1294
GB_ERROR write_int(long aw_int)
const MutableBoundItemSel BoundItemSel
Definition: items.h:106
static AW_window * create_loadsave_colored_window(AW_root *aw_root, color_save_data *csd)
Definition: db_query.cxx:1804
long GBS_read_hash(const GB_HASH *hs, const char *key)
Definition: adhash.cxx:392
void inc_and_check_user_abort(GB_ERROR &error)
Definition: arb_progress.h:332
static void mark_queried_cb(AW_window *, DbQuery *query, int mark)
Definition: db_query.cxx:588
#define PSEUDO_FIELD_ANY_FIELD_REC
Definition: item_sel_list.h:29
const char * do_delete_pos_fig
Definition: db_query.h:64
void aw_message_if(GB_ERROR error)
Definition: aw_msg.hxx:21
CONSTEXPR long FIELD_FILTER_STRING_READABLE
Definition: item_sel_list.h:47
const char * do_unmark_pos_fig
Definition: db_query.h:63
char * GBS_global_string_copy(const char *templat,...)
Definition: arb_msg.cxx:194
const char * do_refresh_pos_fig
Definition: db_query.h:67
const char * id_field
Definition: items.h:68
QUERY_ITEM_TYPE type
Definition: items.h:51
CONSTEXPR long FIELD_UNFILTERED
Definition: item_sel_list.h:49
const char * label
GB_HASH * GBS_create_hash(long estimated_elements, GB_CASE case_sens)
Definition: adhash.cxx:253
void create_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, const char *color=NULp)
Definition: AW_button.cxx:448
Definition: arbdb.h:66
CONSTEXPR_INLINE int long_cmp(const long L1, const long L2)
Definition: arbtools.h:199
const char * get_itemfield_type_awarname(const char *itemfield_awarname)
GBDATA * GBT_get_species_data(GBDATA *gb_main)
Definition: aditem.cxx:105
GB_ERROR GB_write_autoconv_string(GBDATA *gbd, const char *val)
Definition: arbdb.cxx:1479
GB_write_int const char s
Definition: AW_awar.cxx:154